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