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