xref: /webtrees/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php (revision 8d018ab2fe3b6881cab8124d97e1a69e0be79d32)
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 IcelandicSurnameTradition
29 */
30class IcelandicSurnameTraditionTest extends TestCase
31{
32    private SurnameTraditionInterface $surname_tradition;
33
34    /**
35     * Test whether surnames are used
36     *
37     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
38     *
39     * @return void
40     */
41    public function testSurnames(): void
42    {
43        self::assertSame('', $this->surname_tradition->defaultName());
44    }
45
46    /**
47     * Test new son names
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
50     *
51     * @return void
52     */
53    public function testNewSonNames(): void
54    {
55        $father_fact = $this->createStub(Fact::class);
56        $father_fact->method('value')->willReturn('Jon Einarsson');
57
58        $father = $this->createStub(Individual::class);
59        $father->method('facts')->willReturn(new Collection([$father_fact]));
60
61        $mother_fact = $this->createStub(Fact::class);
62        $mother_fact->method('value')->willReturn('Eva Stefansdottir');
63
64        $mother = $this->createStub(Individual::class);
65        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
66
67        self::assertSame(
68            ["1 NAME Jonsson\n2 TYPE BIRTH\n2 GIVN Jonsson"],
69            $this->surname_tradition->newChildNames($father, $mother, 'M')
70        );
71    }
72
73    /**
74     * Test new daughter names
75     *
76     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
77     *
78     * @return void
79     */
80    public function testNewDaughterNames(): void
81    {
82        $father_fact = $this->createStub(Fact::class);
83        $father_fact->method('value')->willReturn('Jon Einarsson');
84
85        $father = $this->createStub(Individual::class);
86        $father->method('facts')->willReturn(new Collection([$father_fact]));
87
88        $mother_fact = $this->createStub(Fact::class);
89        $mother_fact->method('value')->willReturn('Eva Stefansdottir');
90
91        $mother = $this->createStub(Individual::class);
92        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
93
94        self::assertSame(
95            ["1 NAME Jonsdottir\n2 TYPE BIRTH\n2 GIVN Jonsdottir"],
96            $this->surname_tradition->newChildNames($father, $mother, 'F')
97        );
98    }
99
100    /**
101     * Test new child names
102     *
103     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
104     *
105     * @return void
106     */
107    public function testNewChildNames(): void
108    {
109        $father_fact = $this->createStub(Fact::class);
110        $father_fact->method('value')->willReturn('Jon Einarsson');
111
112        $father = $this->createStub(Individual::class);
113        $father->method('facts')->willReturn(new Collection([$father_fact]));
114
115        $mother_fact = $this->createStub(Fact::class);
116        $mother_fact->method('value')->willReturn('Eva Stefansdottir');
117
118        $mother = $this->createStub(Individual::class);
119        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
120
121        self::assertSame(
122            ["1 NAME\n2 TYPE BIRTH"],
123            $this->surname_tradition->newChildNames($father, $mother, 'U')
124        );
125    }
126
127    /**
128     * Test new father names
129     *
130     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
131     *
132     * @return void
133     */
134    public function testNewFatherNames(): void
135    {
136        $fact = $this->createStub(Fact::class);
137        $fact->method('value')->willReturn('Jon Einarsson');
138
139        $individual = $this->createStub(Individual::class);
140        $individual->method('facts')->willReturn(new Collection([$fact]));
141
142        self::assertSame(
143            ["1 NAME Einar\n2 TYPE BIRTH\n2 GIVN Einar"],
144            $this->surname_tradition->newParentNames($individual, 'M')
145        );
146    }
147
148    /**
149     * Test new mother names
150     *
151     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
152     *
153     * @return void
154     */
155    public function testNewMotherNames(): void
156    {
157        $fact = $this->createStub(Fact::class);
158        $fact->method('value')->willReturn('Jon Evasdottir');
159
160        $individual = $this->createStub(Individual::class);
161        $individual->method('facts')->willReturn(new Collection([$fact]));
162
163        self::assertSame(
164            ["1 NAME Eva\n2 TYPE BIRTH\n2 GIVN Eva"],
165            $this->surname_tradition->newParentNames($individual, 'F')
166        );
167    }
168
169    /**
170     * Test new parent names
171     *
172     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
173     *
174     * @return void
175     */
176    public function testNewParentNames(): void
177    {
178        $fact = $this->createStub(Fact::class);
179        $fact->method('value')->willReturn('Jon Einarsson');
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->newParentNames($individual, 'U')
187        );
188    }
189
190    /**
191     * Test new spouse names
192     *
193     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
194     *
195     * @return void
196     */
197    public function testNewSpouseNames(): void
198    {
199        $fact = $this->createStub(Fact::class);
200        $fact->method('value')->willReturn('Jon Einarsson');
201
202        $individual = $this->createStub(Individual::class);
203        $individual->method('facts')->willReturn(new Collection([$fact]));
204
205        self::assertSame(
206            ["1 NAME\n2 TYPE BIRTH"],
207            $this->surname_tradition->newSpouseNames($individual, 'M')
208        );
209
210        self::assertSame(
211            ["1 NAME\n2 TYPE BIRTH"],
212            $this->surname_tradition->newSpouseNames($individual, 'F')
213        );
214
215        self::assertSame(
216            ["1 NAME\n2 TYPE BIRTH"],
217            $this->surname_tradition->newSpouseNames($individual, 'U')
218        );
219    }
220
221    /**
222     * Prepare the environment for these tests
223     *
224     * @return void
225     */
226    protected function setUp(): void
227    {
228        parent::setUp();
229
230        $this->surname_tradition = new IcelandicSurnameTradition();
231    }
232}
233