xref: /webtrees/tests/app/SurnameTradition/PaternalSurnameTraditionTest.php (revision 8d018ab2fe3b6881cab8124d97e1a69e0be79d32)
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;
26
27/**
28 * Test harness for the class PaternalSurnameTradition
29 */
30class PaternalSurnameTraditionTest extends TestCase
31{
32    private SurnameTraditionInterface $surname_tradition;
33
34    /**
35     * Test whether surnames are used
36     *
37     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
38     *
39     * @return void
40     */
41    public function testSurnames(): void
42    {
43        self::assertSame('//', $this->surname_tradition->defaultName());
44    }
45
46    /**
47     * Test new child names
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
50     *
51     * @return void
52     */
53    public function testNewChildNames(): void
54    {
55        $father_fact = $this->createStub(Fact::class);
56        $father_fact->method('value')->willReturn('John /White/');
57
58        $father = $this->createStub(Individual::class);
59        $father->method('facts')->willReturn(new Collection([$father_fact]));
60
61        $mother_fact = $this->createStub(Fact::class);
62        $mother_fact->method('value')->willReturn('Mary /Black/');
63
64        $mother = $this->createStub(Individual::class);
65        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
66
67        self::assertSame(
68            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
69            $this->surname_tradition->newChildNames($father, $mother, 'M')
70        );
71
72        self::assertSame(
73            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
74            $this->surname_tradition->newChildNames($father, $mother, 'F')
75        );
76
77        self::assertSame(
78            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
79            $this->surname_tradition->newChildNames($father, $mother, 'U')
80        );
81    }
82
83    /**
84     * Test new child names
85     *
86     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
87     *
88     * @return void
89     */
90    public function testNewChildNamesWithSpfx(): void
91    {
92        $father_fact = $this->createStub(Fact::class);
93        $father_fact->method('value')->willReturn('John /de White/');
94
95        $father = $this->createStub(Individual::class);
96        $father->method('facts')->willReturn(new Collection([$father_fact]));
97
98        $mother_fact = $this->createStub(Fact::class);
99        $mother_fact->method('value')->willReturn('Mary /van Black/');
100
101        $mother = $this->createStub(Individual::class);
102        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
103
104        self::assertSame(
105            ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"],
106            $this->surname_tradition->newChildNames($father, $mother, 'U')
107        );
108    }
109
110    /**
111     * Test new child names
112     *
113     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
114     *
115     * @return void
116     */
117    public function testNewChildNamesWithMultipleSpfx(): void
118    {
119        $father_fact = $this->createStub(Fact::class);
120        $father_fact->method('value')->willReturn('John /van der White/');
121
122        $father = $this->createStub(Individual::class);
123        $father->method('facts')->willReturn(new Collection([$father_fact]));
124
125        $mother_fact = $this->createStub(Fact::class);
126        $mother_fact->method('value')->willReturn('Mary /van Black/');
127
128        $mother = $this->createStub(Individual::class);
129        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
130
131        self::assertSame(
132            ["1 NAME /van der White/\n2 TYPE BIRTH\n2 SPFX van der\n2 SURN White"],
133            $this->surname_tradition->newChildNames($father, $mother, 'U')
134        );
135    }
136
137    /**
138     * Test new child names
139     *
140     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
141     *
142     * @return void
143     */
144    public function testNewChildNamesWithDutchSpfx(): void
145    {
146        $father_fact = $this->createStub(Fact::class);
147        $father_fact->method('value')->willReturn('John /\'t White/');
148
149        $father = $this->createStub(Individual::class);
150        $father->method('facts')->willReturn(new Collection([$father_fact]));
151
152        $mother_fact = $this->createStub(Fact::class);
153        $mother_fact->method('value')->willReturn('Mary /van Black/');
154
155        $mother = $this->createStub(Individual::class);
156        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
157
158        self::assertSame(
159            ["1 NAME /'t White/\n2 TYPE BIRTH\n2 SPFX 't\n2 SURN White"],
160            $this->surname_tradition->newChildNames($father, $mother, 'U')
161        );
162    }
163
164    /**
165     * Test new child names
166     *
167     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
168     *
169     * @return void
170     */
171    public function testNewChildNamesWithMultipleDutchSpfx(): void
172    {
173        $father_fact = $this->createStub(Fact::class);
174        $father_fact->method('value')->willReturn('John /van \'t White/');
175
176        $father = $this->createStub(Individual::class);
177        $father->method('facts')->willReturn(new Collection([$father_fact]));
178
179        $mother_fact = $this->createStub(Fact::class);
180        $mother_fact->method('value')->willReturn('Mary /van Black/');
181
182        $mother = $this->createStub(Individual::class);
183        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
184
185        self::assertSame(
186            ["1 NAME /van 't White/\n2 TYPE BIRTH\n2 SPFX van 't\n2 SURN White"],
187            $this->surname_tradition->newChildNames($father, $mother, 'U')
188        );
189    }
190
191    /**
192     * Test new father names
193     *
194     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
195     *
196     * @return void
197     */
198    public function testNewFatherNames(): void
199    {
200        $fact = $this->createStub(Fact::class);
201        $fact->method('value')->willReturn('Chris /White/');
202
203        $individual = $this->createStub(Individual::class);
204        $individual->method('facts')->willReturn(new Collection([$fact]));
205
206        self::assertSame(
207            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
208            $this->surname_tradition->newParentNames($individual, 'M')
209        );
210    }
211
212    /**
213     * Test new mother names
214     *
215     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
216     *
217     * @return void
218     */
219    public function testNewMotherNames(): void
220    {
221        $fact = $this->createStub(Fact::class);
222        $fact->method('value')->willReturn('Chris /White/');
223
224        $individual = $this->createStub(Individual::class);
225        $individual->method('facts')->willReturn(new Collection([$fact]));
226
227        self::assertSame(
228            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"],
229            $this->surname_tradition->newParentNames($individual, 'F')
230        );
231    }
232
233    /**
234     * Test new parent names
235     *
236     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
237     *
238     * @return void
239     */
240    public function testNewParentNames(): void
241    {
242        $fact = $this->createStub(Fact::class);
243        $fact->method('value')->willReturn('Chris /White/');
244
245        $individual = $this->createStub(Individual::class);
246        $individual->method('facts')->willReturn(new Collection([$fact]));
247
248        self::assertSame(
249            ["1 NAME //\n2 TYPE BIRTH"],
250            $this->surname_tradition->newParentNames($individual, 'U')
251        );
252    }
253
254    /**
255     * Test new husband names
256     *
257     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
258     *
259     * @return void
260     */
261    public function testNewHusbandNames(): void
262    {
263        $fact = $this->createStub(Fact::class);
264        $fact->method('value')->willReturn('Chris /White/');
265
266        $individual = $this->createStub(Individual::class);
267        $individual->method('facts')->willReturn(new Collection([$fact]));
268
269        self::assertSame(
270            ["1 NAME //\n2 TYPE BIRTH"],
271            $this->surname_tradition->newSpouseNames($individual, 'M')
272        );
273    }
274
275    /**
276     * Test new wife names
277     *
278     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
279     *
280     * @return void
281     */
282    public function testNewWifeNames(): void
283    {
284        $fact = $this->createStub(Fact::class);
285        $fact->method('value')->willReturn('Chris /White/');
286
287        $individual = $this->createStub(Individual::class);
288        $individual->method('facts')->willReturn(new Collection([$fact]));
289
290        self::assertSame(
291            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"],
292            $this->surname_tradition->newSpouseNames($individual, 'F')
293        );
294    }
295
296    /**
297     * Test new wife names
298     *
299     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
300     *
301     * @return void
302     */
303    public function testNewWifeNamesWithSpfx(): void
304    {
305        $fact = $this->createStub(Fact::class);
306        $fact->method('value')->willReturn('Chris /van der White/');
307
308        $individual = $this->createStub(Individual::class);
309        $individual->method('facts')->willReturn(new Collection([$fact]));
310
311        self::assertSame(
312            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /van der White/\n2 TYPE MARRIED\n2 SPFX van der\n2 SURN White"],
313            $this->surname_tradition->newSpouseNames($individual, 'F')
314        );
315    }
316
317    /**
318     * Test new spouse names
319     *
320     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
321     *
322     * @return void
323     */
324    public function testNewSpouseNames(): void
325    {
326        $fact = $this->createStub(Fact::class);
327        $fact->method('value')->willReturn('Chris /White/');
328
329        $individual = $this->createStub(Individual::class);
330        $individual->method('facts')->willReturn(new Collection([$fact]));
331
332        self::assertSame(
333            ["1 NAME //\n2 TYPE BIRTH"],
334            $this->surname_tradition->newSpouseNames($individual, 'U')
335        );
336    }
337
338    /**
339     * Prepare the environment for these tests
340     *
341     * @return void
342     */
343    protected function setUp(): void
344    {
345        parent::setUp();
346
347        $this->surname_tradition = new PaternalSurnameTradition();
348    }
349}
350