xref: /webtrees/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php (revision 5bfc689774bb9a6401271c4ed15a6d50652c991b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5*5bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team
6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9323788f4SGreg Roach * (at your option) any later version.
10323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13323788f4SGreg Roach * GNU General Public License for more details.
14323788f4SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16323788f4SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
21c1010edaSGreg Roach
22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact;
23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
25cb7a42eaSGreg Roachuse Illuminate\Support\Collection;
263cfcc809SGreg Roach
27323788f4SGreg Roach/**
28c4943cffSGreg Roach * Test harness for the class IcelandicSurnameTradition
29323788f4SGreg Roach */
303cfcc809SGreg Roachclass IcelandicSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35c1ec7145SGreg Roach     * Test whether surnames are used
3617d74f3aSGreg Roach     *
3715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
3852348eb8SGreg Roach     *
3952348eb8SGreg Roach     * @return void
40c1ec7145SGreg Roach     */
419b802b22SGreg Roach    public function testSurnames(): void
42c1010edaSGreg Roach    {
43a171b6a5SGreg Roach        self::assertSame('', $this->surname_tradition->defaultName());
44c1ec7145SGreg Roach    }
45c1ec7145SGreg Roach
46c1ec7145SGreg Roach    /**
47323788f4SGreg Roach     * Test new son names
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52323788f4SGreg Roach     */
539b802b22SGreg Roach    public function testNewSonNames(): void
54c1010edaSGreg Roach    {
55cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
5683c91e47SGreg Roach        $father_fact->method('value')->willReturn('Jon Einarsson');
57cb7a42eaSGreg Roach
58cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
5983c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
60cb7a42eaSGreg Roach
61cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
6283c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Eva Stefansdottir');
63cb7a42eaSGreg Roach
64cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
6583c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
66cb7a42eaSGreg Roach
675e933c21SGreg Roach        self::assertSame(
68cb7a42eaSGreg Roach            ["1 NAME Jonsson\n2 TYPE birth\n2 GIVN Jonsson"],
69cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
70323788f4SGreg Roach        );
71323788f4SGreg Roach    }
72323788f4SGreg Roach
73323788f4SGreg Roach    /**
74323788f4SGreg Roach     * Test new daughter names
7517d74f3aSGreg Roach     *
7615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
7752348eb8SGreg Roach     *
7852348eb8SGreg Roach     * @return void
79323788f4SGreg Roach     */
809b802b22SGreg Roach    public function testNewDaughterNames(): void
81c1010edaSGreg Roach    {
82cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
8383c91e47SGreg Roach        $father_fact->method('value')->willReturn('Jon Einarsson');
84cb7a42eaSGreg Roach
85cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
8683c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
87cb7a42eaSGreg Roach
88cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
8983c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Eva Stefansdottir');
90cb7a42eaSGreg Roach
91cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
9283c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
93cb7a42eaSGreg Roach
945e933c21SGreg Roach        self::assertSame(
95cb7a42eaSGreg Roach            ["1 NAME Jonsdottir\n2 TYPE birth\n2 GIVN Jonsdottir"],
96cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
97323788f4SGreg Roach        );
98323788f4SGreg Roach    }
99323788f4SGreg Roach
100323788f4SGreg Roach    /**
101323788f4SGreg Roach     * Test new child names
10217d74f3aSGreg Roach     *
10315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
10452348eb8SGreg Roach     *
10552348eb8SGreg Roach     * @return void
106323788f4SGreg Roach     */
1079b802b22SGreg Roach    public function testNewChildNames(): void
108c1010edaSGreg Roach    {
109cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
11083c91e47SGreg Roach        $father_fact->method('value')->willReturn('Jon Einarsson');
111cb7a42eaSGreg Roach
112cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
11383c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
114cb7a42eaSGreg Roach
115cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
11683c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Eva Stefansdottir');
117cb7a42eaSGreg Roach
118cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
11983c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
120cb7a42eaSGreg Roach
1215e933c21SGreg Roach        self::assertSame(
122cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
123cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
124323788f4SGreg Roach        );
125323788f4SGreg Roach    }
126323788f4SGreg Roach
127323788f4SGreg Roach    /**
128323788f4SGreg Roach     * Test new father names
12917d74f3aSGreg Roach     *
13015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
13152348eb8SGreg Roach     *
13252348eb8SGreg Roach     * @return void
133323788f4SGreg Roach     */
1349b802b22SGreg Roach    public function testNewFatherNames(): void
135c1010edaSGreg Roach    {
136cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
13783c91e47SGreg Roach        $fact->method('value')->willReturn('Jon Einarsson');
138cb7a42eaSGreg Roach
139cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
14083c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
141cb7a42eaSGreg Roach
1425e933c21SGreg Roach        self::assertSame(
143cb7a42eaSGreg Roach            ["1 NAME Einar\n2 TYPE birth\n2 GIVN Einar"],
144cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
145323788f4SGreg Roach        );
146323788f4SGreg Roach    }
147323788f4SGreg Roach
148323788f4SGreg Roach    /**
149323788f4SGreg Roach     * Test new mother names
15017d74f3aSGreg Roach     *
15115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
15252348eb8SGreg Roach     *
15352348eb8SGreg Roach     * @return void
154323788f4SGreg Roach     */
1559b802b22SGreg Roach    public function testNewMotherNames(): void
156c1010edaSGreg Roach    {
157cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
15883c91e47SGreg Roach        $fact->method('value')->willReturn('Jon Evasdottir');
159cb7a42eaSGreg Roach
160cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
16183c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
162cb7a42eaSGreg Roach
1635e933c21SGreg Roach        self::assertSame(
164cb7a42eaSGreg Roach            ["1 NAME Eva\n2 TYPE birth\n2 GIVN Eva"],
165cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
166323788f4SGreg Roach        );
167323788f4SGreg Roach    }
168323788f4SGreg Roach
169323788f4SGreg Roach    /**
170323788f4SGreg Roach     * Test new parent names
17117d74f3aSGreg Roach     *
17215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
17352348eb8SGreg Roach     *
17452348eb8SGreg Roach     * @return void
175323788f4SGreg Roach     */
1769b802b22SGreg Roach    public function testNewParentNames(): void
177c1010edaSGreg Roach    {
178cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
17983c91e47SGreg Roach        $fact->method('value')->willReturn('Jon Einarsson');
180323788f4SGreg Roach
181cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
18283c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
183323788f4SGreg Roach
1845e933c21SGreg Roach        self::assertSame(
185cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
186cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
187323788f4SGreg Roach        );
188323788f4SGreg Roach    }
189323788f4SGreg Roach
190323788f4SGreg Roach    /**
191323788f4SGreg Roach     * Test new spouse names
19217d74f3aSGreg Roach     *
19315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
19452348eb8SGreg Roach     *
19552348eb8SGreg Roach     * @return void
196323788f4SGreg Roach     */
1979b802b22SGreg Roach    public function testNewSpouseNames(): void
198c1010edaSGreg Roach    {
199cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
20083c91e47SGreg Roach        $fact->method('value')->willReturn('Jon Einarsson');
201cb7a42eaSGreg Roach
202cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
20383c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
204cb7a42eaSGreg Roach
2055e933c21SGreg Roach        self::assertSame(
206cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
207cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
208323788f4SGreg Roach        );
209cb7a42eaSGreg Roach
210cb7a42eaSGreg Roach        self::assertSame(
211cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
212cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
213cb7a42eaSGreg Roach        );
214cb7a42eaSGreg Roach
215cb7a42eaSGreg Roach        self::assertSame(
216cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
217cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
218cb7a42eaSGreg Roach        );
219cb7a42eaSGreg Roach    }
220cb7a42eaSGreg Roach
221cb7a42eaSGreg Roach    /**
222cb7a42eaSGreg Roach     * Prepare the environment for these tests
223cb7a42eaSGreg Roach     *
224cb7a42eaSGreg Roach     * @return void
225cb7a42eaSGreg Roach     */
226cb7a42eaSGreg Roach    protected function setUp(): void
227cb7a42eaSGreg Roach    {
228cb7a42eaSGreg Roach        parent::setUp();
229cb7a42eaSGreg Roach
230cb7a42eaSGreg Roach        $this->surname_tradition = new IcelandicSurnameTradition();
231323788f4SGreg Roach    }
232323788f4SGreg Roach}
233