xref: /webtrees/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php (revision 9d74ed0ab3ae61aa8ae07578e026f14020844ce9)
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#[CoversClass(PatrilinealSurnameTradition::class)]
29class PatrilinealSurnameTraditionTest extends TestCase
30{
31    private SurnameTraditionInterface $surname_tradition;
32
33    /**
34     * Prepare the environment for these tests
35     */
36    protected function setUp(): void
37    {
38        parent::setUp();
39
40        $this->surname_tradition = new PatrilinealSurnameTradition();
41    }
42
43    /**
44     * Test whether surnames are used
45     */
46    public function testSurnames(): void
47    {
48        self::assertSame('//', $this->surname_tradition->defaultName());
49    }
50
51    /**
52     * Test new child names
53     */
54    public function testNewChildNames(): void
55    {
56        $father_fact = $this->createMock(Fact::class);
57        $father_fact->method('value')->willReturn('John /White/');
58
59        $father = $this->createMock(Individual::class);
60        $father->method('facts')->willReturn(new Collection([$father_fact]));
61
62        $mother_fact = $this->createMock(Fact::class);
63        $mother_fact->method('value')->willReturn('Mary /Black/');
64
65        $mother = $this->createMock(Individual::class);
66        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
67
68        self::assertSame(
69            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
70            $this->surname_tradition->newChildNames($father, $mother, 'M')
71        );
72
73        self::assertSame(
74            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
75            $this->surname_tradition->newChildNames($father, $mother, 'F')
76        );
77
78        self::assertSame(
79            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
80            $this->surname_tradition->newChildNames($father, $mother, 'U')
81        );
82    }
83
84    /**
85     * Test new child names
86     */
87    public function testNewChildNamesWithSpfx(): void
88    {
89        $father_fact = $this->createMock(Fact::class);
90        $father_fact->method('value')->willReturn('John /de White/');
91
92        $father = $this->createMock(Individual::class);
93        $father->method('facts')->willReturn(new Collection([$father_fact]));
94
95        $mother_fact = $this->createMock(Fact::class);
96        $mother_fact->method('value')->willReturn('Mary /van Black/');
97
98        $mother = $this->createMock(Individual::class);
99        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
100
101        self::assertSame(
102            ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"],
103            $this->surname_tradition->newChildNames($father, $mother, 'U')
104        );
105    }
106
107    /**
108     * Test new child names
109     */
110    public function testNewChildNamesWithNoParentsNames(): void
111    {
112        self::assertSame(
113            ["1 NAME //\n2 TYPE BIRTH"],
114            $this->surname_tradition->newChildNames(null, null, 'U')
115        );
116    }
117
118    /**
119     * Test new parent names
120     */
121    public function testNewParentNames(): void
122    {
123        $fact = $this->createMock(Fact::class);
124        $fact->method('value')->willReturn('Chris /White/');
125
126        $individual = $this->createMock(Individual::class);
127        $individual->method('facts')->willReturn(new Collection([$fact]));
128
129        self::assertSame(
130            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
131            $this->surname_tradition->newParentNames($individual, 'M')
132        );
133
134        self::assertSame(
135            ["1 NAME //\n2 TYPE BIRTH"],
136            $this->surname_tradition->newParentNames($individual, 'F')
137        );
138
139        self::assertSame(
140            ["1 NAME //\n2 TYPE BIRTH"],
141            $this->surname_tradition->newParentNames($individual, 'U')
142        );
143    }
144
145    /**
146     * Test new spouse names
147     */
148    public function testNewSpouseNames(): void
149    {
150        $fact = $this->createMock(Fact::class);
151        $fact->method('value')->willReturn('Chris /White/');
152
153        $individual = $this->createMock(Individual::class);
154        $individual->method('facts')->willReturn(new Collection([$fact]));
155
156        self::assertSame(
157            ["1 NAME //\n2 TYPE BIRTH"],
158            $this->surname_tradition->newSpouseNames($individual, 'M')
159        );
160
161        self::assertSame(
162            ["1 NAME //\n2 TYPE BIRTH"],
163            $this->surname_tradition->newSpouseNames($individual, 'F')
164        );
165
166        self::assertSame(
167            ["1 NAME //\n2 TYPE BIRTH"],
168            $this->surname_tradition->newSpouseNames($individual, 'U')
169        );
170    }
171}
172