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