xref: /webtrees/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php (revision 62ff2f188c699b1144fb2ca2d6da1358d5e1a745)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\SurnameTradition;
21
22use Fisharebest\Webtrees\Fact;
23use Fisharebest\Webtrees\Individual;
24use Fisharebest\Webtrees\TestCase;
25use Illuminate\Support\Collection;
26use PHPUnit\Framework\Attributes\CoversClass;
27
28
29#[CoversClass(DefaultSurnameTradition::class)]
30class DefaultSurnameTraditionTest extends TestCase
31{
32    private SurnameTraditionInterface $surname_tradition;
33
34    /**
35     * Test whether surnames are used
36     */
37    public function testSurnames(): void
38    {
39        self::assertSame('//', $this->surname_tradition->defaultName());
40    }
41
42    /**
43     * Test new child names
44     */
45    public function testNewChildNames(): void
46    {
47        $father_fact = $this->createMock(Fact::class);
48        $father_fact->method('value')->willReturn('Chris /White/');
49
50        $father = $this->createMock(Individual::class);
51        $father->method('facts')->willReturn(new Collection([$father]));
52
53        $mother_fact = $this->createMock(Fact::class);
54        $mother_fact->method('value')->willReturn('Chris /White/');
55
56        $mother = $this->createMock(Individual::class);
57        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
58
59        self::assertSame(
60            ["1 NAME //\n2 TYPE BIRTH"],
61            $this->surname_tradition->newChildNames($father, $mother, 'M')
62        );
63
64        self::assertSame(
65            ["1 NAME //\n2 TYPE BIRTH"],
66            $this->surname_tradition->newChildNames($father, $mother, 'F')
67        );
68
69        self::assertSame(
70            ["1 NAME //\n2 TYPE BIRTH"],
71            $this->surname_tradition->newChildNames($father, $mother, 'U')
72        );
73    }
74
75    /**
76     * Test new parent names
77     */
78    public function testNewParentNames(): void
79    {
80        $fact = $this->createMock(Fact::class);
81        $fact->method('value')->willReturn('Chris /White/');
82
83        $individual = $this->createMock(Individual::class);
84        $individual->method('facts')->willReturn(new Collection([$fact]));
85
86        self::assertSame(
87            ["1 NAME //\n2 TYPE BIRTH"],
88            $this->surname_tradition->newParentNames($individual, 'M')
89        );
90
91        self::assertSame(
92            ["1 NAME //\n2 TYPE BIRTH"],
93            $this->surname_tradition->newParentNames($individual, 'F')
94        );
95
96        self::assertSame(
97            ["1 NAME //\n2 TYPE BIRTH"],
98            $this->surname_tradition->newParentNames($individual, 'U')
99        );
100    }
101
102    /**
103     * Test new spouse names
104     */
105    public function testNewSpouseNames(): void
106    {
107        $fact = $this->createMock(Fact::class);
108        $fact->method('value')->willReturn('Chris /White/');
109
110        $individual = $this->createMock(Individual::class);
111        $individual->method('facts')->willReturn(new Collection([$fact]));
112
113        self::assertSame(
114            ["1 NAME //\n2 TYPE BIRTH"],
115            $this->surname_tradition->newSpouseNames($individual, 'M')
116        );
117
118        self::assertSame(
119            ["1 NAME //\n2 TYPE BIRTH"],
120            $this->surname_tradition->newSpouseNames($individual, 'F')
121        );
122
123        self::assertSame(
124            ["1 NAME //\n2 TYPE BIRTH"],
125            $this->surname_tradition->newSpouseNames($individual, 'U')
126        );
127    }
128
129    /**
130     * Prepare the environment for these tests
131     */
132    protected function setUp(): void
133    {
134        parent::setUp();
135
136        $this->surname_tradition = new DefaultSurnameTradition();
137    }
138}
139