xref: /webtrees/tests/app/SurnameTradition/MatrilinealSurnameTraditionTest.php (revision 09523927627d8824ee0799f8137d6de75b8b7921)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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    protected function setUp(): void
38    {
39        parent::setUp();
40
41        $this->surname_tradition = new MatrilinealSurnameTradition();
42    }
43
44    /**
45     * Test whether surnames are used
46     *
47     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
48     */
49    public function testSurnames(): void
50    {
51        self::assertSame('//', $this->surname_tradition->defaultName());
52    }
53
54    /**
55     * Test new child names
56     *
57     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
58     */
59    public function testNewChildNames(): void
60    {
61        $father_fact = $this->createStub(Fact::class);
62        $father_fact->method('value')->willReturn('John /White/');
63
64        $father = $this->createStub(Individual::class);
65        $father->method('facts')->willReturn(new Collection([$father_fact]));
66
67        $mother_fact = $this->createStub(Fact::class);
68        $mother_fact->method('value')->willReturn('Mary /Black/');
69
70        $mother = $this->createStub(Individual::class);
71        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
72
73        self::assertSame(
74            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
75            $this->surname_tradition->newChildNames($father, $mother, 'M')
76        );
77
78        self::assertSame(
79            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
80            $this->surname_tradition->newChildNames($father, $mother, 'F')
81        );
82
83        self::assertSame(
84            ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"],
85            $this->surname_tradition->newChildNames($father, $mother, 'U')
86        );
87    }
88
89    /**
90     * Test new child names
91     *
92     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
93     */
94    public function testNewChildNamesWithSpfx(): void
95    {
96        $father_fact = $this->createStub(Fact::class);
97        $father_fact->method('value')->willReturn('John /de White/');
98
99        $father = $this->createStub(Individual::class);
100        $father->method('facts')->willReturn(new Collection([$father_fact]));
101
102        $mother_fact = $this->createStub(Fact::class);
103        $mother_fact->method('value')->willReturn('Mary /van Black/');
104
105        $mother = $this->createStub(Individual::class);
106        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
107
108        self::assertSame(
109            ["1 NAME /van Black/\n2 TYPE BIRTH\n2 SPFX van\n2 SURN Black"],
110            $this->surname_tradition->newChildNames($father, $mother, 'U')
111        );
112    }
113
114    /**
115     * Test new child names
116     *
117     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
118     */
119    public function testNewChildNamesWithNoParentsNames(): void
120    {
121        self::assertSame(
122            ["1 NAME //\n2 TYPE BIRTH"],
123            $this->surname_tradition->newChildNames(null, null, 'U')
124        );
125    }
126
127    /**
128     * Test new parent names
129     *
130     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
131     */
132    public function testNewParentNames(): void
133    {
134        $fact = $this->createStub(Fact::class);
135        $fact->method('value')->willReturn('Chris /White/');
136
137        $individual = $this->createStub(Individual::class);
138        $individual->method('facts')->willReturn(new Collection([$fact]));
139
140
141        self::assertSame(
142            ["1 NAME //\n2 TYPE BIRTH"],
143            $this->surname_tradition->newParentNames($individual, 'M')
144        );
145
146        self::assertSame(
147            ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"],
148            $this->surname_tradition->newParentNames($individual, 'F')
149        );
150
151        self::assertSame(
152            ["1 NAME //\n2 TYPE BIRTH"],
153            $this->surname_tradition->newParentNames($individual, 'U')
154        );
155    }
156
157    /**
158     * Test new spouse names
159     *
160     * @covers \Fisharebest\Webtrees\SurnameTradition\MatrilinealSurnameTradition
161     */
162    public function testNewSpouseNames(): void
163    {
164        $fact = $this->createStub(Fact::class);
165        $fact->method('value')->willReturn('Chris /White/');
166
167        $individual = $this->createStub(Individual::class);
168        $individual->method('facts')->willReturn(new Collection([$fact]));
169
170        self::assertSame(
171            ["1 NAME //\n2 TYPE BIRTH"],
172            $this->surname_tradition->newSpouseNames($individual, 'M')
173        );
174
175        self::assertSame(
176            ["1 NAME //\n2 TYPE BIRTH"],
177            $this->surname_tradition->newSpouseNames($individual, 'F')
178        );
179
180        self::assertSame(
181            ["1 NAME //\n2 TYPE BIRTH"],
182            $this->surname_tradition->newSpouseNames($individual, 'U')
183        );
184    }
185}
186