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