xref: /webtrees/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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;
26*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
273cfcc809SGreg Roach
28*202c018bSGreg Roach
29*202c018bSGreg Roach#[CoversClass(PatrilinealSurnameTradition::class)]
303cfcc809SGreg Roachclass PatrilinealSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35323788f4SGreg Roach     * Prepare the environment for these tests
36323788f4SGreg Roach     */
375c48bcd6SGreg Roach    protected function setUp(): void
38c1010edaSGreg Roach    {
390115bc16SGreg Roach        parent::setUp();
400115bc16SGreg Roach
4174d6dc0eSGreg Roach        $this->surname_tradition = new PatrilinealSurnameTradition();
42323788f4SGreg Roach    }
43323788f4SGreg Roach
44323788f4SGreg Roach    /**
45c1ec7145SGreg Roach     * Test whether surnames are used
46c1ec7145SGreg Roach     */
479b802b22SGreg Roach    public function testSurnames(): void
48c1010edaSGreg Roach    {
49a171b6a5SGreg Roach        self::assertSame('//', $this->surname_tradition->defaultName());
50c1ec7145SGreg Roach    }
51c1ec7145SGreg Roach
52c1ec7145SGreg Roach    /**
53323788f4SGreg Roach     * Test new child names
54323788f4SGreg Roach     */
559b802b22SGreg Roach    public function testNewChildNames(): void
56c1010edaSGreg Roach    {
57cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
5883c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /White/');
59cb7a42eaSGreg Roach
60cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
6183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
62cb7a42eaSGreg Roach
63cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
6483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
65cb7a42eaSGreg Roach
66cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
6783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
68cb7a42eaSGreg Roach
695e933c21SGreg Roach        self::assertSame(
708939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
71cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
72cb7a42eaSGreg Roach        );
73cb7a42eaSGreg Roach
74cb7a42eaSGreg Roach        self::assertSame(
758939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
76cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
77cb7a42eaSGreg Roach        );
78cb7a42eaSGreg Roach
79cb7a42eaSGreg Roach        self::assertSame(
808939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
81cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
82323788f4SGreg Roach        );
83323788f4SGreg Roach    }
84323788f4SGreg Roach
85323788f4SGreg Roach    /**
86323788f4SGreg Roach     * Test new child names
87323788f4SGreg Roach     */
889b802b22SGreg Roach    public function testNewChildNamesWithSpfx(): void
89c1010edaSGreg Roach    {
90cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
9183c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /de White/');
92cb7a42eaSGreg Roach
93cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
9483c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
95cb7a42eaSGreg Roach
96cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
9783c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /van Black/');
98cb7a42eaSGreg Roach
99cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
10083c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
101cb7a42eaSGreg Roach
1025e933c21SGreg Roach        self::assertSame(
1038939e2c2SGreg Roach            ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"],
104cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
105323788f4SGreg Roach        );
106323788f4SGreg Roach    }
107323788f4SGreg Roach
108323788f4SGreg Roach    /**
1091677a03aSGreg Roach     * Test new child names
1101677a03aSGreg Roach     */
1119b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
112c1010edaSGreg Roach    {
1135e933c21SGreg Roach        self::assertSame(
1148939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
115cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
116323788f4SGreg Roach        );
117323788f4SGreg Roach    }
118323788f4SGreg Roach
119323788f4SGreg Roach    /**
120323788f4SGreg Roach     * Test new parent names
121323788f4SGreg Roach     */
1229b802b22SGreg Roach    public function testNewParentNames(): void
123c1010edaSGreg Roach    {
124cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
12583c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
126323788f4SGreg Roach
127cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
12883c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
129323788f4SGreg Roach
1305e933c21SGreg Roach        self::assertSame(
1318939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
132cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
133cb7a42eaSGreg Roach        );
134cb7a42eaSGreg Roach
135cb7a42eaSGreg Roach        self::assertSame(
1368939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
137cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
138cb7a42eaSGreg Roach        );
139cb7a42eaSGreg Roach
140cb7a42eaSGreg Roach        self::assertSame(
1418939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
142cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
143323788f4SGreg Roach        );
144323788f4SGreg Roach    }
145323788f4SGreg Roach
146323788f4SGreg Roach    /**
147323788f4SGreg Roach     * Test new spouse names
148323788f4SGreg Roach     */
1499b802b22SGreg Roach    public function testNewSpouseNames(): void
150c1010edaSGreg Roach    {
151cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
15283c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
153cb7a42eaSGreg Roach
154cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
15583c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
156cb7a42eaSGreg Roach
1575e933c21SGreg Roach        self::assertSame(
1588939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
159cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
160cb7a42eaSGreg Roach        );
161cb7a42eaSGreg Roach
162cb7a42eaSGreg Roach        self::assertSame(
1638939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
164cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
165cb7a42eaSGreg Roach        );
166cb7a42eaSGreg Roach
167cb7a42eaSGreg Roach        self::assertSame(
1688939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
169cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
170323788f4SGreg Roach        );
171323788f4SGreg Roach    }
172323788f4SGreg Roach}
173