xref: /webtrees/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.php (revision 8939e2c24ff4346b8c6b9f3f822a733db666d588)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\SurnameTradition;
21
22use Fisharebest\Webtrees\Fact;
23use Fisharebest\Webtrees\Individual;
24use Fisharebest\Webtrees\TestCase;
25use Illuminate\Support\Collection;
26
27/**
28 * Test harness for the class MatrilinenalSurnameTradition
29 */
30class MatrilinealSurnameTraditionTest extends TestCase
31{
32    private SurnameTraditionInterface $surname_tradition;
33
34    /**
35     * Prepare the environment for these tests
36     *
37     * @return void
38     */
39    protected function setUp(): void
40    {
41        parent::setUp();
42
43        $this->surname_tradition = new MatrilinealSurnameTradition();
44    }
45
46    /**
47     * Test whether surnames are used
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
50     *
51     * @return void
52     */
53    public function testSurnames(): void
54    {
55        self::assertSame('//', $this->surname_tradition->defaultName());
56    }
57
58    /**
59     * Test new child names
60     *
61     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
62     *
63     * @return void
64     */
65    public function testNewChildNames(): void
66    {
67        $father_fact = $this->createStub(Fact::class);
68        $father_fact->method('value')->willReturn('John /White/');
69
70        $father = $this->createStub(Individual::class);
71        $father->method('facts')->willReturn(new Collection([$father_fact]));
72
73        $mother_fact = $this->createStub(Fact::class);
74        $mother_fact->method('value')->willReturn('Mary /Black/');
75
76        $mother = $this->createStub(Individual::class);
77        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
78
79        self::assertSame(
80            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
81            $this->surname_tradition->newChildNames($father, $mother, 'M')
82        );
83
84        self::assertSame(
85            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
86            $this->surname_tradition->newChildNames($father, $mother, 'F')
87        );
88
89        self::assertSame(
90            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
91            $this->surname_tradition->newChildNames($father, $mother, 'U')
92        );
93    }
94
95    /**
96     * Test new child names
97     *
98     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
99     *
100     * @return void
101     */
102    public function testNewChildNamesWithSpfx(): void
103    {
104        $father_fact = $this->createStub(Fact::class);
105        $father_fact->method('value')->willReturn('John /de White/');
106
107        $father = $this->createStub(Individual::class);
108        $father->method('facts')->willReturn(new Collection([$father_fact]));
109
110        $mother_fact = $this->createStub(Fact::class);
111        $mother_fact->method('value')->willReturn('Mary /van Black/');
112
113        $mother = $this->createStub(Individual::class);
114        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
115
116        self::assertSame(
117            ["1 NAME /van Black/\n2 TYPE BIRTH\n2 SPFX van\n2 SURN Black"],
118            $this->surname_tradition->newChildNames($father, $mother, 'U')
119        );
120    }
121
122    /**
123     * Test new child names
124     *
125     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
126     *
127     * @return void
128     */
129    public function testNewChildNamesWithNoParentsNames(): void
130    {
131        self::assertSame(
132            ["1 NAME //\n2 TYPE BIRTH"],
133            $this->surname_tradition->newChildNames(null, null, 'U')
134        );
135    }
136
137    /**
138     * Test new parent names
139     *
140     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
141     *
142     * @return void
143     */
144    public function testNewParentNames(): void
145    {
146        $fact = $this->createStub(Fact::class);
147        $fact->method('value')->willReturn('Chris /White/');
148
149        $individual = $this->createStub(Individual::class);
150        $individual->method('facts')->willReturn(new Collection([$fact]));
151
152
153        self::assertSame(
154            ["1 NAME //\n2 TYPE BIRTH"],
155            $this->surname_tradition->newParentNames($individual, 'M')
156        );
157
158        self::assertSame(
159            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
160            $this->surname_tradition->newParentNames($individual, 'F')
161        );
162
163        self::assertSame(
164            ["1 NAME //\n2 TYPE BIRTH"],
165            $this->surname_tradition->newParentNames($individual, 'U')
166        );
167    }
168
169    /**
170     * Test new spouse names
171     *
172     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
173     *
174     * @return void
175     */
176    public function testNewSpouseNames(): void
177    {
178        $fact = $this->createStub(Fact::class);
179        $fact->method('value')->willReturn('Chris /White/');
180
181        $individual = $this->createStub(Individual::class);
182        $individual->method('facts')->willReturn(new Collection([$fact]));
183
184        self::assertSame(
185            ["1 NAME //\n2 TYPE BIRTH"],
186            $this->surname_tradition->newSpouseNames($individual, 'M')
187        );
188
189        self::assertSame(
190            ["1 NAME //\n2 TYPE BIRTH"],
191            $this->surname_tradition->newSpouseNames($individual, 'F')
192        );
193
194        self::assertSame(
195            ["1 NAME //\n2 TYPE BIRTH"],
196            $this->surname_tradition->newSpouseNames($individual, 'U')
197        );
198    }
199}
200