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