xref: /webtrees/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.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(MatrilinealSurnameTradition::class)]
293cfcc809SGreg Roachclass MatrilinealSurnameTraditionTest extends TestCase
30c1010edaSGreg Roach{
31c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
32323788f4SGreg Roach
33323788f4SGreg Roach    /**
34323788f4SGreg Roach     * Prepare the environment for these tests
35323788f4SGreg Roach     */
365c48bcd6SGreg Roach    protected function setUp(): void
37c1010edaSGreg Roach    {
380115bc16SGreg Roach        parent::setUp();
390115bc16SGreg Roach
4074d6dc0eSGreg Roach        $this->surname_tradition = new MatrilinealSurnameTradition();
41323788f4SGreg Roach    }
42323788f4SGreg Roach
43323788f4SGreg Roach    /**
44c1ec7145SGreg Roach     * Test whether surnames are used
45c1ec7145SGreg Roach     */
469b802b22SGreg Roach    public function testSurnames(): void
47c1010edaSGreg Roach    {
48a171b6a5SGreg Roach        self::assertSame('//', $this->surname_tradition->defaultName());
49c1ec7145SGreg Roach    }
50c1ec7145SGreg Roach
51c1ec7145SGreg Roach    /**
52323788f4SGreg Roach     * Test new child names
53323788f4SGreg Roach     */
549b802b22SGreg Roach    public function testNewChildNames(): void
55c1010edaSGreg Roach    {
56*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
5783c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /White/');
58cb7a42eaSGreg Roach
59*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
6083c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
61cb7a42eaSGreg Roach
62*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
6383c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /Black/');
64cb7a42eaSGreg Roach
65*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
6683c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
67cb7a42eaSGreg Roach
685e933c21SGreg Roach        self::assertSame(
698939e2c2SGreg Roach            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
70cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
71cb7a42eaSGreg Roach        );
72cb7a42eaSGreg Roach
73cb7a42eaSGreg Roach        self::assertSame(
748939e2c2SGreg Roach            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
75cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
76cb7a42eaSGreg Roach        );
77cb7a42eaSGreg Roach
78cb7a42eaSGreg Roach        self::assertSame(
798939e2c2SGreg Roach            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
80cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
81323788f4SGreg Roach        );
82323788f4SGreg Roach    }
83323788f4SGreg Roach
84323788f4SGreg Roach    /**
85323788f4SGreg Roach     * Test new child names
86323788f4SGreg Roach     */
879b802b22SGreg Roach    public function testNewChildNamesWithSpfx(): void
88c1010edaSGreg Roach    {
89*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
9083c91e47SGreg Roach        $father_fact->method('value')->willReturn('John /de White/');
91cb7a42eaSGreg Roach
92*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
9383c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
94cb7a42eaSGreg Roach
95*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
9683c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Mary /van Black/');
97cb7a42eaSGreg Roach
98*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
9983c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
100cb7a42eaSGreg Roach
1015e933c21SGreg Roach        self::assertSame(
1028939e2c2SGreg Roach            ["1 NAME /van Black/\n2 TYPE BIRTH\n2 SPFX van\n2 SURN Black"],
103cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
104323788f4SGreg Roach        );
105323788f4SGreg Roach    }
106323788f4SGreg Roach
107323788f4SGreg Roach    /**
1081677a03aSGreg Roach     * Test new child names
1091677a03aSGreg Roach     */
1109b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
111c1010edaSGreg Roach    {
1125e933c21SGreg Roach        self::assertSame(
1138939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
114cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
115323788f4SGreg Roach        );
116323788f4SGreg Roach    }
117323788f4SGreg Roach
118323788f4SGreg Roach    /**
119323788f4SGreg Roach     * Test new parent names
120323788f4SGreg Roach     */
1219b802b22SGreg Roach    public function testNewParentNames(): void
122c1010edaSGreg Roach    {
123*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
12483c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
125323788f4SGreg Roach
126*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
12783c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
128323788f4SGreg Roach
1295e933c21SGreg Roach        self::assertSame(
1308939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
131cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
132cb7a42eaSGreg Roach        );
133cb7a42eaSGreg Roach
134cb7a42eaSGreg Roach        self::assertSame(
1358939e2c2SGreg Roach            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
136cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
137cb7a42eaSGreg Roach        );
138cb7a42eaSGreg Roach
139cb7a42eaSGreg Roach        self::assertSame(
1408939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
141cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
142323788f4SGreg Roach        );
143323788f4SGreg Roach    }
144323788f4SGreg Roach
145323788f4SGreg Roach    /**
146323788f4SGreg Roach     * Test new spouse names
147323788f4SGreg Roach     */
1489b802b22SGreg Roach    public function testNewSpouseNames(): void
149c1010edaSGreg Roach    {
150*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
15183c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
152cb7a42eaSGreg Roach
153*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
15483c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
155cb7a42eaSGreg Roach
1565e933c21SGreg Roach        self::assertSame(
1578939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
158cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
159cb7a42eaSGreg Roach        );
160cb7a42eaSGreg Roach
161cb7a42eaSGreg Roach        self::assertSame(
1628939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
163cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
164cb7a42eaSGreg Roach        );
165cb7a42eaSGreg Roach
166cb7a42eaSGreg Roach        self::assertSame(
1678939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
168cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
169323788f4SGreg Roach        );
170323788f4SGreg Roach    }
171323788f4SGreg Roach}
172