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