xref: /webtrees/tests/app/SurnameTradition/PaternalSurnameTraditionTest.php (revision cb7a42eae1efabac96d9d7693151fe0421b6717b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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
22*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact;
23*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
25*cb7a42eaSGreg Roachuse Illuminate\Support\Collection;
263cfcc809SGreg Roach
27323788f4SGreg Roach/**
28323788f4SGreg Roach * Test harness for the class PaternalSurnameTradition
29323788f4SGreg Roach */
303cfcc809SGreg Roachclass PaternalSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35323788f4SGreg Roach     * Test whether married surnames are used
3617d74f3aSGreg Roach     *
3715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
3852348eb8SGreg Roach     *
3952348eb8SGreg Roach     * @return void
40323788f4SGreg Roach     */
419b802b22SGreg Roach    public function testMarriedSurnames(): void
42c1010edaSGreg Roach    {
435e933c21SGreg Roach        self::assertTrue($this->surname_tradition->hasMarriedNames());
44323788f4SGreg Roach    }
45323788f4SGreg Roach
46323788f4SGreg Roach    /**
47c1ec7145SGreg Roach     * Test whether surnames are used
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52c1ec7145SGreg Roach     */
539b802b22SGreg Roach    public function testSurnames(): void
54c1010edaSGreg Roach    {
555e933c21SGreg Roach        self::assertTrue($this->surname_tradition->hasSurnames());
56c1ec7145SGreg Roach    }
57c1ec7145SGreg Roach
58c1ec7145SGreg Roach    /**
59323788f4SGreg Roach     * Test new child names
6017d74f3aSGreg Roach     *
6115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
6252348eb8SGreg Roach     *
6352348eb8SGreg Roach     * @return void
64323788f4SGreg Roach     */
659b802b22SGreg Roach    public function testNewChildNames(): void
66c1010edaSGreg Roach    {
67*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
68*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('John /White/');
69*cb7a42eaSGreg Roach
70*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
71*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
72*cb7a42eaSGreg Roach
73*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
74*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/');
75*cb7a42eaSGreg Roach
76*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
77*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
78*cb7a42eaSGreg Roach
795e933c21SGreg Roach        self::assertSame(
80*cb7a42eaSGreg Roach            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
81*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
82*cb7a42eaSGreg Roach        );
83*cb7a42eaSGreg Roach
84*cb7a42eaSGreg Roach        self::assertSame(
85*cb7a42eaSGreg Roach            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
86*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
87*cb7a42eaSGreg Roach        );
88*cb7a42eaSGreg Roach
89*cb7a42eaSGreg Roach        self::assertSame(
90*cb7a42eaSGreg Roach            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
91*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
92323788f4SGreg Roach        );
93323788f4SGreg Roach    }
94323788f4SGreg Roach
95323788f4SGreg Roach    /**
96323788f4SGreg Roach     * Test new child names
9717d74f3aSGreg Roach     *
9815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
9952348eb8SGreg Roach     *
10052348eb8SGreg Roach     * @return void
101323788f4SGreg Roach     */
1029b802b22SGreg Roach    public function testNewChildNamesWithSpfx(): void
103c1010edaSGreg Roach    {
104*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
105*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('John /de White/');
106*cb7a42eaSGreg Roach
107*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
108*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
109*cb7a42eaSGreg Roach
110*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
111*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/');
112*cb7a42eaSGreg Roach
113*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
114*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
115*cb7a42eaSGreg Roach
1165e933c21SGreg Roach        self::assertSame(
117*cb7a42eaSGreg Roach            ["1 NAME /de White/\n2 TYPE birth\n2 SPFX de\n2 SURN White"],
118*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
119323788f4SGreg Roach        );
120323788f4SGreg Roach    }
121323788f4SGreg Roach
122323788f4SGreg Roach    /**
1238caf8226SGreg Roach     * Test new child names
1248caf8226SGreg Roach     *
12515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
12652348eb8SGreg Roach     *
12752348eb8SGreg Roach     * @return void
1288caf8226SGreg Roach     */
1299b802b22SGreg Roach    public function testNewChildNamesWithMultipleSpfx(): void
130c1010edaSGreg Roach    {
131*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
132*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('John /van der White/');
133*cb7a42eaSGreg Roach
134*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
135*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
136*cb7a42eaSGreg Roach
137*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
138*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/');
139*cb7a42eaSGreg Roach
140*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
141*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
142*cb7a42eaSGreg Roach
1435e933c21SGreg Roach        self::assertSame(
144*cb7a42eaSGreg Roach            ["1 NAME /van der White/\n2 TYPE birth\n2 SPFX van der\n2 SURN White"],
145*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
1468caf8226SGreg Roach        );
1478caf8226SGreg Roach    }
1488caf8226SGreg Roach
1498caf8226SGreg Roach    /**
1509797fe2eSGreg Roach     * Test new child names
1519797fe2eSGreg Roach     *
15215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
15352348eb8SGreg Roach     *
15452348eb8SGreg Roach     * @return void
1559797fe2eSGreg Roach     */
1569b802b22SGreg Roach    public function testNewChildNamesWithDutchSpfx(): void
157c1010edaSGreg Roach    {
158*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
159*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('John /\'t White/');
160*cb7a42eaSGreg Roach
161*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
162*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
163*cb7a42eaSGreg Roach
164*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
165*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/');
166*cb7a42eaSGreg Roach
167*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
168*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
169*cb7a42eaSGreg Roach
1705e933c21SGreg Roach        self::assertSame(
171*cb7a42eaSGreg Roach            ["1 NAME /'t White/\n2 TYPE birth\n2 SPFX 't\n2 SURN White"],
172*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
1739797fe2eSGreg Roach        );
1749797fe2eSGreg Roach    }
1759797fe2eSGreg Roach
1769797fe2eSGreg Roach    /**
1779797fe2eSGreg Roach     * Test new child names
1789797fe2eSGreg Roach     *
17915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
18052348eb8SGreg Roach     *
18152348eb8SGreg Roach     * @return void
1829797fe2eSGreg Roach     */
1839b802b22SGreg Roach    public function testNewChildNamesWithMultipleDutchSpfx(): void
184c1010edaSGreg Roach    {
185*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
186*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('John /van \'t White/');
187*cb7a42eaSGreg Roach
188*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
189*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
190*cb7a42eaSGreg Roach
191*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
192*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Mary /van Black/');
193*cb7a42eaSGreg Roach
194*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
195*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
196*cb7a42eaSGreg Roach
1975e933c21SGreg Roach        self::assertSame(
198*cb7a42eaSGreg Roach            ["1 NAME /van 't White/\n2 TYPE birth\n2 SPFX van 't\n2 SURN White"],
199*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
2009797fe2eSGreg Roach        );
2019797fe2eSGreg Roach    }
2029797fe2eSGreg Roach
2039797fe2eSGreg Roach    /**
204323788f4SGreg Roach     * Test new father names
20517d74f3aSGreg Roach     *
20615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
20752348eb8SGreg Roach     *
20852348eb8SGreg Roach     * @return void
209323788f4SGreg Roach     */
2109b802b22SGreg Roach    public function testNewFatherNames(): void
211c1010edaSGreg Roach    {
212*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
213*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /White/');
214*cb7a42eaSGreg Roach
215*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
216*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
217*cb7a42eaSGreg Roach
2185e933c21SGreg Roach        self::assertSame(
219*cb7a42eaSGreg Roach            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
220*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
221323788f4SGreg Roach        );
222323788f4SGreg Roach    }
223323788f4SGreg Roach
224323788f4SGreg Roach    /**
225323788f4SGreg Roach     * Test new mother names
22617d74f3aSGreg Roach     *
22715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
22852348eb8SGreg Roach     *
22952348eb8SGreg Roach     * @return void
230323788f4SGreg Roach     */
2319b802b22SGreg Roach    public function testNewMotherNames(): void
232c1010edaSGreg Roach    {
233*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
234*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /White/');
235*cb7a42eaSGreg Roach
236*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
237*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
238*cb7a42eaSGreg Roach
2395e933c21SGreg Roach        self::assertSame(
240*cb7a42eaSGreg Roach            ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"],
241*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
242323788f4SGreg Roach        );
243323788f4SGreg Roach    }
244323788f4SGreg Roach
245323788f4SGreg Roach    /**
246323788f4SGreg Roach     * Test new parent names
24717d74f3aSGreg Roach     *
24815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
24952348eb8SGreg Roach     *
25052348eb8SGreg Roach     * @return void
251323788f4SGreg Roach     */
2529b802b22SGreg Roach    public function testNewParentNames(): void
253c1010edaSGreg Roach    {
254*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
255*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /White/');
256*cb7a42eaSGreg Roach
257*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
258*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
259*cb7a42eaSGreg Roach
2605e933c21SGreg Roach        self::assertSame(
261*cb7a42eaSGreg Roach            ["1 NAME //\n2 TYPE birth"],
262*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
263323788f4SGreg Roach        );
264323788f4SGreg Roach    }
265323788f4SGreg Roach
266323788f4SGreg Roach    /**
267323788f4SGreg Roach     * Test new husband names
26817d74f3aSGreg Roach     *
26915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
27052348eb8SGreg Roach     *
27152348eb8SGreg Roach     * @return void
272323788f4SGreg Roach     */
2739b802b22SGreg Roach    public function testNewHusbandNames(): void
274c1010edaSGreg Roach    {
275*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
276*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /White/');
277*cb7a42eaSGreg Roach
278*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
279*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
280*cb7a42eaSGreg Roach
2815e933c21SGreg Roach        self::assertSame(
282*cb7a42eaSGreg Roach            ["1 NAME //\n2 TYPE birth"],
283*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
284323788f4SGreg Roach        );
285323788f4SGreg Roach    }
286323788f4SGreg Roach
287323788f4SGreg Roach    /**
288323788f4SGreg Roach     * Test new wife names
28917d74f3aSGreg Roach     *
29015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
29152348eb8SGreg Roach     *
29252348eb8SGreg Roach     * @return void
293323788f4SGreg Roach     */
2949b802b22SGreg Roach    public function testNewWifeNames(): void
295c1010edaSGreg Roach    {
296*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
297*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /White/');
298*cb7a42eaSGreg Roach
299*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
300*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
301*cb7a42eaSGreg Roach
3025e933c21SGreg Roach        self::assertSame(
303*cb7a42eaSGreg Roach            ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"],
304*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
305323788f4SGreg Roach        );
306323788f4SGreg Roach    }
307323788f4SGreg Roach
308323788f4SGreg Roach    /**
3095b2de99fSGreg Roach     * Test new wife names
3105b2de99fSGreg Roach     *
31115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
31252348eb8SGreg Roach     *
31352348eb8SGreg Roach     * @return void
3145b2de99fSGreg Roach     */
3159b802b22SGreg Roach    public function testNewWifeNamesWithSpfx(): void
316c1010edaSGreg Roach    {
317*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
318*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /van der White/');
319*cb7a42eaSGreg Roach
320*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
321*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
322*cb7a42eaSGreg Roach
3235e933c21SGreg Roach        self::assertSame(
324*cb7a42eaSGreg Roach            ["1 NAME //\n2 TYPE birth", "1 NAME /van der White/\n2 TYPE married\n2 SPFX van der\n2 SURN White"],
325*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
3265b2de99fSGreg Roach        );
3275b2de99fSGreg Roach    }
3285b2de99fSGreg Roach
3295b2de99fSGreg Roach    /**
330323788f4SGreg Roach     * Test new spouse names
33117d74f3aSGreg Roach     *
33215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition
33352348eb8SGreg Roach     *
33452348eb8SGreg Roach     * @return void
335323788f4SGreg Roach     */
3369b802b22SGreg Roach    public function testNewSpouseNames(): void
337c1010edaSGreg Roach    {
338*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
339*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Chris /White/');
340*cb7a42eaSGreg Roach
341*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
342*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
343*cb7a42eaSGreg Roach
3445e933c21SGreg Roach        self::assertSame(
345*cb7a42eaSGreg Roach            ["1 NAME //\n2 TYPE birth"],
346*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
347323788f4SGreg Roach        );
348323788f4SGreg Roach    }
349*cb7a42eaSGreg Roach
350*cb7a42eaSGreg Roach    /**
351*cb7a42eaSGreg Roach     * Prepare the environment for these tests
352*cb7a42eaSGreg Roach     *
353*cb7a42eaSGreg Roach     * @return void
354*cb7a42eaSGreg Roach     */
355*cb7a42eaSGreg Roach    protected function setUp(): void
356*cb7a42eaSGreg Roach    {
357*cb7a42eaSGreg Roach        parent::setUp();
358*cb7a42eaSGreg Roach
359*cb7a42eaSGreg Roach        $this->surname_tradition = new PaternalSurnameTradition();
360*cb7a42eaSGreg Roach    }
361323788f4SGreg Roach}
362