xref: /webtrees/tests/app/SurnameTradition/PatrilinealSurnameTraditionTest.php (revision 17c6a11dd0f7d834aa76b1703185adf9cae1b8a9)
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 PatrilinenalSurnameTradition
29 */
30class PatrilinealSurnameTraditionTest 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 PatrilinealSurnameTradition();
44    }
45
46    /**
47     * Test whether married surnames are used
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition
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\PatrilinealSurnameTradition
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\PatrilinealSurnameTradition
74     *
75     * @return void
76     */
77    public function testNewChildNames(): void
78    {
79        $father_fact = $this->createStub(Fact::class);
80        $father_fact->method('value')->willReturn('John /White/');
81
82        $father = $this->createStub(Individual::class);
83        $father->method('facts')->willReturn(new Collection([$father_fact]));
84
85        $mother_fact = $this->createStub(Fact::class);
86        $mother_fact->method('value')->willReturn('Mary /Black/');
87
88        $mother = $this->createStub(Individual::class);
89        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
90
91        self::assertSame(
92            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
93            $this->surname_tradition->newChildNames($father, $mother, 'M')
94        );
95
96        self::assertSame(
97            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
98            $this->surname_tradition->newChildNames($father, $mother, 'F')
99        );
100
101        self::assertSame(
102            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
103            $this->surname_tradition->newChildNames($father, $mother, 'U')
104        );
105    }
106
107    /**
108     * Test new child names
109     *
110     * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition
111     *
112     * @return void
113     */
114    public function testNewChildNamesWithSpfx(): void
115    {
116        $father_fact = $this->createStub(Fact::class);
117        $father_fact->method('value')->willReturn('John /de White/');
118
119        $father = $this->createStub(Individual::class);
120        $father->method('facts')->willReturn(new Collection([$father_fact]));
121
122        $mother_fact = $this->createStub(Fact::class);
123        $mother_fact->method('value')->willReturn('Mary /van Black/');
124
125        $mother = $this->createStub(Individual::class);
126        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
127
128        self::assertSame(
129            ["1 NAME /de White/\n2 TYPE birth\n2 SPFX de\n2 SURN White"],
130            $this->surname_tradition->newChildNames($father, $mother, 'U')
131        );
132    }
133
134    /**
135     * Test new child names
136     *
137     * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition
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\PatrilinealSurnameTradition
153     *
154     * @return void
155     */
156    public function testNewParentNames(): void
157    {
158        $fact = $this->createStub(Fact::class);
159        $fact->method('value')->willReturn('Chris /White/');
160
161        $individual = $this->createStub(Individual::class);
162        $individual->method('facts')->willReturn(new Collection([$fact]));
163
164        self::assertSame(
165            ["1 NAME /White/\n2 TYPE birth\n2 SURN White"],
166            $this->surname_tradition->newParentNames($individual, 'M')
167        );
168
169        self::assertSame(
170            ["1 NAME //\n2 TYPE birth"],
171            $this->surname_tradition->newParentNames($individual, 'F')
172        );
173
174        self::assertSame(
175            ["1 NAME //\n2 TYPE birth"],
176            $this->surname_tradition->newParentNames($individual, 'U')
177        );
178    }
179
180    /**
181     * Test new spouse names
182     *
183     * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition
184     *
185     * @return void
186     */
187    public function testNewSpouseNames(): void
188    {
189        $fact = $this->createStub(Fact::class);
190        $fact->method('value')->willReturn('Chris /White/');
191
192        $individual = $this->createStub(Individual::class);
193        $individual->method('facts')->willReturn(new Collection([$fact]));
194
195        self::assertSame(
196            ["1 NAME //\n2 TYPE birth"],
197            $this->surname_tradition->newSpouseNames($individual, 'M')
198        );
199
200        self::assertSame(
201            ["1 NAME //\n2 TYPE birth"],
202            $this->surname_tradition->newSpouseNames($individual, 'F')
203        );
204
205        self::assertSame(
206            ["1 NAME //\n2 TYPE birth"],
207            $this->surname_tradition->newSpouseNames($individual, 'U')
208        );
209    }
210}
211