xref: /webtrees/tests/app/SurnameTradition/PolishSurnameTraditionTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9323788f4SGreg Roach * (at your option) any later version.
10323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13323788f4SGreg Roach * GNU General Public License for more details.
14323788f4SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16323788f4SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
21c1010edaSGreg Roach
22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact;
23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
25cb7a42eaSGreg Roachuse Illuminate\Support\Collection;
26202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
273cfcc809SGreg Roach
28202c018bSGreg Roach#[CoversClass(PolishSurnameTradition::class)]
29202c018bSGreg Roach#[CoversClass(PatrilinealSurnameTradition::class)]
303cfcc809SGreg Roachclass PolishSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35c1ec7145SGreg Roach     * Test whether surnames are used
36c1ec7145SGreg Roach     */
379b802b22SGreg Roach    public function testSurnames(): void
38c1010edaSGreg Roach    {
39a171b6a5SGreg Roach        self::assertSame('//', $this->surname_tradition->defaultName());
40c1ec7145SGreg Roach    }
41c1ec7145SGreg Roach
42c1ec7145SGreg Roach    /**
43323788f4SGreg Roach     * Test new son names
44323788f4SGreg Roach     */
459b802b22SGreg Roach    public function testNewSonNames(): void
46c1010edaSGreg Roach    {
47*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
4883c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /White/');
49cb7a42eaSGreg Roach
50*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
5183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
52cb7a42eaSGreg Roach
53*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
5483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
55cb7a42eaSGreg Roach
56*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
5783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
58cb7a42eaSGreg Roach
595e933c21SGreg Roach        self::assertSame(
608939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
61cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
62323788f4SGreg Roach        );
63323788f4SGreg Roach    }
64323788f4SGreg Roach
65323788f4SGreg Roach    /**
66323788f4SGreg Roach     * Test new daughter names
67323788f4SGreg Roach     */
689b802b22SGreg Roach    public function testNewDaughterNames(): void
69c1010edaSGreg Roach    {
70*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
7183c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /White/');
72cb7a42eaSGreg Roach
73*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
7483c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
75cb7a42eaSGreg Roach
76*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
7783c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
78cb7a42eaSGreg Roach
79*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
8083c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
81cb7a42eaSGreg Roach
825e933c21SGreg Roach        self::assertSame(
838939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
84cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
85323788f4SGreg Roach        );
86323788f4SGreg Roach    }
87323788f4SGreg Roach
88323788f4SGreg Roach    /**
89323788f4SGreg Roach     * Test new daughter names
90323788f4SGreg Roach     */
919b802b22SGreg Roach    public function testNewDaughterNamesInflected(): void
92c1010edaSGreg Roach    {
93*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
9483c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /Whitecki/');
95cb7a42eaSGreg Roach
96*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
9783c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
98cb7a42eaSGreg Roach
99*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
10083c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
101cb7a42eaSGreg Roach
102*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
10383c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
104cb7a42eaSGreg Roach
1055e933c21SGreg Roach        self::assertSame(
1068939e2c2SGreg Roach            ["1 NAME /Whitecka/\n2 TYPE BIRTH\n2 SURN Whitecki"],
107cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
108323788f4SGreg Roach        );
109cb7a42eaSGreg Roach
110*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
11183c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /Whitedzki/');
112cb7a42eaSGreg Roach
113*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
11483c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
115cb7a42eaSGreg Roach
116*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
11783c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
118cb7a42eaSGreg Roach
119*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
12083c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
121cb7a42eaSGreg Roach
1225e933c21SGreg Roach        self::assertSame(
1238939e2c2SGreg Roach            ["1 NAME /Whitedzka/\n2 TYPE BIRTH\n2 SURN Whitedzki"],
124cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
125323788f4SGreg Roach        );
126cb7a42eaSGreg Roach
127*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
12883c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /Whiteski/');
129cb7a42eaSGreg Roach
130*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
13183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
132cb7a42eaSGreg Roach
133*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
13483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
135cb7a42eaSGreg Roach
136*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
13783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
138cb7a42eaSGreg Roach
1395e933c21SGreg Roach        self::assertSame(
1408939e2c2SGreg Roach            ["1 NAME /Whiteska/\n2 TYPE BIRTH\n2 SURN Whiteski"],
141cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
142323788f4SGreg Roach        );
143cb7a42eaSGreg Roach
144*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
14583c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /Whiteżki/');
146cb7a42eaSGreg Roach
147*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
14883c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
149cb7a42eaSGreg Roach
150*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
15183c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
152cb7a42eaSGreg Roach
153*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
15483c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
155cb7a42eaSGreg Roach
1565e933c21SGreg Roach        self::assertSame(
1578939e2c2SGreg Roach            ["1 NAME /Whiteżka/\n2 TYPE BIRTH\n2 SURN Whiteżki"],
158cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
159323788f4SGreg Roach        );
160323788f4SGreg Roach    }
161323788f4SGreg Roach
162323788f4SGreg Roach    /**
163323788f4SGreg Roach     * Test new child names
164323788f4SGreg Roach     */
1659b802b22SGreg Roach    public function testNewChildNames(): void
166c1010edaSGreg Roach    {
167*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
16883c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /White/');
169cb7a42eaSGreg Roach
170*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
17183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
172cb7a42eaSGreg Roach
173*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
17483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
175cb7a42eaSGreg Roach
176*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
17783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
178cb7a42eaSGreg Roach
1795e933c21SGreg Roach        self::assertSame(
1808939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
181cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
182323788f4SGreg Roach        );
183323788f4SGreg Roach    }
184323788f4SGreg Roach
185323788f4SGreg Roach    /**
1861677a03aSGreg Roach     * Test new child names
1871677a03aSGreg Roach     */
1889b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
189c1010edaSGreg Roach    {
1905e933c21SGreg Roach        self::assertSame(
1918939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
192cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
1931677a03aSGreg Roach        );
1941677a03aSGreg Roach    }
1951677a03aSGreg Roach
1961677a03aSGreg Roach    /**
197323788f4SGreg Roach     * Test new father names
198323788f4SGreg Roach     */
1999b802b22SGreg Roach    public function testNewFatherNames(): void
200c1010edaSGreg Roach    {
201*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
20283c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
203cb7a42eaSGreg Roach
204*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
20583c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
206cb7a42eaSGreg Roach
2075e933c21SGreg Roach        self::assertSame(
2088939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
209cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
210323788f4SGreg Roach        );
211323788f4SGreg Roach    }
212323788f4SGreg Roach
213323788f4SGreg Roach    /**
214323788f4SGreg Roach     * Test new father names
215323788f4SGreg Roach     */
2169b802b22SGreg Roach    public function testNewFatherNamesInflected(): void
217c1010edaSGreg Roach    {
218*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
21983c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /Whitecka/');
220cb7a42eaSGreg Roach
221*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
22283c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
223cb7a42eaSGreg Roach
2245e933c21SGreg Roach        self::assertSame(
2258939e2c2SGreg Roach            ["1 NAME /Whitecki/\n2 TYPE BIRTH\n2 SURN Whitecki"],
226cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
227323788f4SGreg Roach        );
228cb7a42eaSGreg Roach
229*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
23083c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /Whitedzka/');
231cb7a42eaSGreg Roach
232*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
23383c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
234cb7a42eaSGreg Roach
2355e933c21SGreg Roach        self::assertSame(
2368939e2c2SGreg Roach            ["1 NAME /Whitedzki/\n2 TYPE BIRTH\n2 SURN Whitedzki"],
237cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
238323788f4SGreg Roach        );
239cb7a42eaSGreg Roach
240*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
24183c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /Whiteska/');
242cb7a42eaSGreg Roach
243*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
24483c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
245cb7a42eaSGreg Roach
2465e933c21SGreg Roach        self::assertSame(
2478939e2c2SGreg Roach            ["1 NAME /Whiteski/\n2 TYPE BIRTH\n2 SURN Whiteski"],
248cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
249323788f4SGreg Roach        );
250cb7a42eaSGreg Roach
251*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
25283c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /Whiteżka/');
253cb7a42eaSGreg Roach
254*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
25583c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
256cb7a42eaSGreg Roach
2575e933c21SGreg Roach        self::assertSame(
2588939e2c2SGreg Roach            ["1 NAME /Whiteżki/\n2 TYPE BIRTH\n2 SURN Whiteżki"],
259cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
260323788f4SGreg Roach        );
261323788f4SGreg Roach    }
262323788f4SGreg Roach
263323788f4SGreg Roach    /**
264323788f4SGreg Roach     * Test new mother names
265323788f4SGreg Roach     */
2669b802b22SGreg Roach    public function testNewMotherNames(): void
267c1010edaSGreg Roach    {
268*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
26983c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
270cb7a42eaSGreg Roach
271*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
27283c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
273cb7a42eaSGreg Roach
2745e933c21SGreg Roach        self::assertSame(
2758939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
276cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
277323788f4SGreg Roach        );
278323788f4SGreg Roach    }
279323788f4SGreg Roach
280323788f4SGreg Roach    /**
281323788f4SGreg Roach     * Test new parent names
282323788f4SGreg Roach     */
2839b802b22SGreg Roach    public function testNewParentNames(): void
284c1010edaSGreg Roach    {
285*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
28683c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
287323788f4SGreg Roach
288*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
28983c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
290323788f4SGreg Roach
2915e933c21SGreg Roach        self::assertSame(
2928939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
293cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
294323788f4SGreg Roach        );
295323788f4SGreg Roach    }
296323788f4SGreg Roach
297323788f4SGreg Roach    /**
298323788f4SGreg Roach     * Test new spouse names
299323788f4SGreg Roach     */
3009b802b22SGreg Roach    public function testNewSpouseNames(): void
301c1010edaSGreg Roach    {
302*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
30383c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
304cb7a42eaSGreg Roach
305*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
30683c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
307cb7a42eaSGreg Roach
3085e933c21SGreg Roach        self::assertSame(
3098939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
310cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
311323788f4SGreg Roach        );
312cb7a42eaSGreg Roach
313cb7a42eaSGreg Roach        self::assertSame(
3148939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"],
315cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
316cb7a42eaSGreg Roach        );
317cb7a42eaSGreg Roach
318cb7a42eaSGreg Roach        self::assertSame(
3198939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
320cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
321cb7a42eaSGreg Roach        );
322cb7a42eaSGreg Roach    }
323cb7a42eaSGreg Roach
324cb7a42eaSGreg Roach    /**
325cb7a42eaSGreg Roach     * Prepare the environment for these tests
326cb7a42eaSGreg Roach     */
327cb7a42eaSGreg Roach    protected function setUp(): void
328cb7a42eaSGreg Roach    {
329cb7a42eaSGreg Roach        parent::setUp();
330cb7a42eaSGreg Roach
331cb7a42eaSGreg Roach        $this->surname_tradition = new PolishSurnameTradition();
332323788f4SGreg Roach    }
333323788f4SGreg Roach}
334