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