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