xref: /webtrees/tests/app/SurnameTradition/PaternalSurnameTraditionTest.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(PaternalSurnameTradition::class)]
293cfcc809SGreg Roachclass PaternalSurnameTraditionTest extends TestCase
30c1010edaSGreg Roach{
31c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
32323788f4SGreg Roach
33323788f4SGreg Roach    /**
34c1ec7145SGreg Roach     * Test whether surnames are used
35c1ec7145SGreg Roach     */
369b802b22SGreg Roach    public function testSurnames(): void
37c1010edaSGreg Roach    {
38a171b6a5SGreg Roach        self::assertSame('//', $this->surname_tradition->defaultName());
39c1ec7145SGreg Roach    }
40c1ec7145SGreg Roach
41c1ec7145SGreg Roach    /**
42323788f4SGreg Roach     * Test new child names
43323788f4SGreg Roach     */
449b802b22SGreg Roach    public function testNewChildNames(): void
45c1010edaSGreg Roach    {
46*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
4783c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /White/');
48cb7a42eaSGreg Roach
49*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
5083c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
51cb7a42eaSGreg Roach
52*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
5383c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
54cb7a42eaSGreg Roach
55*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
5683c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
57cb7a42eaSGreg Roach
585e933c21SGreg Roach        self::assertSame(
598939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
60cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
61cb7a42eaSGreg Roach        );
62cb7a42eaSGreg Roach
63cb7a42eaSGreg Roach        self::assertSame(
648939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
65cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
66cb7a42eaSGreg Roach        );
67cb7a42eaSGreg Roach
68cb7a42eaSGreg Roach        self::assertSame(
698939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
70cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
71323788f4SGreg Roach        );
72323788f4SGreg Roach    }
73323788f4SGreg Roach
74323788f4SGreg Roach    /**
75323788f4SGreg Roach     * Test new child names
76323788f4SGreg Roach     */
779b802b22SGreg Roach    public function testNewChildNamesWithSpfx(): void
78c1010edaSGreg Roach    {
79*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
8083c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /de White/');
81cb7a42eaSGreg Roach
82*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
8383c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
84cb7a42eaSGreg Roach
85*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
8683c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /van Black/');
87cb7a42eaSGreg Roach
88*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
8983c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
90cb7a42eaSGreg Roach
915e933c21SGreg Roach        self::assertSame(
928939e2c2SGreg Roach            ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"],
93cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
94323788f4SGreg Roach        );
95323788f4SGreg Roach    }
96323788f4SGreg Roach
97323788f4SGreg Roach    /**
988caf8226SGreg Roach     * Test new child names
998caf8226SGreg Roach     */
1009b802b22SGreg Roach    public function testNewChildNamesWithMultipleSpfx(): void
101c1010edaSGreg Roach    {
102*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
10383c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /van der White/');
104cb7a42eaSGreg Roach
105*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
10683c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
107cb7a42eaSGreg Roach
108*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
10983c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /van Black/');
110cb7a42eaSGreg Roach
111*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
11283c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
113cb7a42eaSGreg Roach
1145e933c21SGreg Roach        self::assertSame(
1158939e2c2SGreg Roach            ["1 NAME /van der White/\n2 TYPE BIRTH\n2 SPFX van der\n2 SURN White"],
116cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
1178caf8226SGreg Roach        );
1188caf8226SGreg Roach    }
1198caf8226SGreg Roach
1208caf8226SGreg Roach    /**
1219797fe2eSGreg Roach     * Test new child names
1229797fe2eSGreg Roach     */
1239b802b22SGreg Roach    public function testNewChildNamesWithDutchSpfx(): void
124c1010edaSGreg Roach    {
125*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
12683c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /\'t White/');
127cb7a42eaSGreg Roach
128*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
12983c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
130cb7a42eaSGreg Roach
131*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
13283c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /van Black/');
133cb7a42eaSGreg Roach
134*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
13583c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
136cb7a42eaSGreg Roach
1375e933c21SGreg Roach        self::assertSame(
1388939e2c2SGreg Roach            ["1 NAME /'t White/\n2 TYPE BIRTH\n2 SPFX 't\n2 SURN White"],
139cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
1409797fe2eSGreg Roach        );
1419797fe2eSGreg Roach    }
1429797fe2eSGreg Roach
1439797fe2eSGreg Roach    /**
1449797fe2eSGreg Roach     * Test new child names
1459797fe2eSGreg Roach     */
1469b802b22SGreg Roach    public function testNewChildNamesWithMultipleDutchSpfx(): void
147c1010edaSGreg Roach    {
148*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
14983c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /van \'t White/');
150cb7a42eaSGreg Roach
151*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
15283c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
153cb7a42eaSGreg Roach
154*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
15583c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /van Black/');
156cb7a42eaSGreg Roach
157*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
15883c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
159cb7a42eaSGreg Roach
1605e933c21SGreg Roach        self::assertSame(
1618939e2c2SGreg Roach            ["1 NAME /van 't White/\n2 TYPE BIRTH\n2 SPFX van 't\n2 SURN White"],
162cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
1639797fe2eSGreg Roach        );
1649797fe2eSGreg Roach    }
1659797fe2eSGreg Roach
1669797fe2eSGreg Roach    /**
167323788f4SGreg Roach     * Test new father names
168323788f4SGreg Roach     */
1699b802b22SGreg Roach    public function testNewFatherNames(): void
170c1010edaSGreg Roach    {
171*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
17283c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
173cb7a42eaSGreg Roach
174*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
17583c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
176cb7a42eaSGreg Roach
1775e933c21SGreg Roach        self::assertSame(
1788939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
179cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
180323788f4SGreg Roach        );
181323788f4SGreg Roach    }
182323788f4SGreg Roach
183323788f4SGreg Roach    /**
184323788f4SGreg Roach     * Test new mother names
185323788f4SGreg Roach     */
1869b802b22SGreg Roach    public function testNewMotherNames(): void
187c1010edaSGreg Roach    {
188*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
18983c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
190cb7a42eaSGreg Roach
191*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
19283c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
193cb7a42eaSGreg Roach
1945e933c21SGreg Roach        self::assertSame(
1958939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"],
196cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
197323788f4SGreg Roach        );
198323788f4SGreg Roach    }
199323788f4SGreg Roach
200323788f4SGreg Roach    /**
201323788f4SGreg Roach     * Test new parent names
202323788f4SGreg Roach     */
2039b802b22SGreg Roach    public function testNewParentNames(): void
204c1010edaSGreg Roach    {
205*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
20683c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
207cb7a42eaSGreg Roach
208*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
20983c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
210cb7a42eaSGreg Roach
2115e933c21SGreg Roach        self::assertSame(
2128939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
213cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
214323788f4SGreg Roach        );
215323788f4SGreg Roach    }
216323788f4SGreg Roach
217323788f4SGreg Roach    /**
218323788f4SGreg Roach     * Test new husband names
219323788f4SGreg Roach     */
2209b802b22SGreg Roach    public function testNewHusbandNames(): void
221c1010edaSGreg Roach    {
222*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
22383c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
224cb7a42eaSGreg Roach
225*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
22683c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
227cb7a42eaSGreg Roach
2285e933c21SGreg Roach        self::assertSame(
2298939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
230cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
231323788f4SGreg Roach        );
232323788f4SGreg Roach    }
233323788f4SGreg Roach
234323788f4SGreg Roach    /**
235323788f4SGreg Roach     * Test new wife names
236323788f4SGreg Roach     */
2379b802b22SGreg Roach    public function testNewWifeNames(): void
238c1010edaSGreg Roach    {
239*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
24083c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
241cb7a42eaSGreg Roach
242*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
24383c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
244cb7a42eaSGreg Roach
2455e933c21SGreg Roach        self::assertSame(
2468939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"],
247cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
248323788f4SGreg Roach        );
249323788f4SGreg Roach    }
250323788f4SGreg Roach
251323788f4SGreg Roach    /**
2525b2de99fSGreg Roach     * Test new wife names
2535b2de99fSGreg Roach     */
2549b802b22SGreg Roach    public function testNewWifeNamesWithSpfx(): void
255c1010edaSGreg Roach    {
256*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
25783c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /van der White/');
258cb7a42eaSGreg Roach
259*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
26083c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
261cb7a42eaSGreg Roach
2625e933c21SGreg Roach        self::assertSame(
2638939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH", "1 NAME /van der White/\n2 TYPE MARRIED\n2 SPFX van der\n2 SURN White"],
264cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
2655b2de99fSGreg Roach        );
2665b2de99fSGreg Roach    }
2675b2de99fSGreg Roach
2685b2de99fSGreg Roach    /**
269323788f4SGreg Roach     * Test new spouse names
270323788f4SGreg Roach     */
2719b802b22SGreg Roach    public function testNewSpouseNames(): void
272c1010edaSGreg Roach    {
273*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
27483c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
275cb7a42eaSGreg Roach
276*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
27783c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
278cb7a42eaSGreg Roach
2795e933c21SGreg Roach        self::assertSame(
2808939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
281cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
282323788f4SGreg Roach        );
283323788f4SGreg Roach    }
284cb7a42eaSGreg Roach
285cb7a42eaSGreg Roach    /**
286cb7a42eaSGreg Roach     * Prepare the environment for these tests
287cb7a42eaSGreg Roach     */
288cb7a42eaSGreg Roach    protected function setUp(): void
289cb7a42eaSGreg Roach    {
290cb7a42eaSGreg Roach        parent::setUp();
291cb7a42eaSGreg Roach
292cb7a42eaSGreg Roach        $this->surname_tradition = new PaternalSurnameTradition();
293cb7a42eaSGreg Roach    }
294323788f4SGreg Roach}
295