xref: /webtrees/tests/app/SurnameTradition/IcelandicSurnameTraditionTest.php (revision cb7a42eae1efabac96d9d7693151fe0421b6717b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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
22*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact;
23*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
25*cb7a42eaSGreg 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    /**
35323788f4SGreg Roach     * Test whether married surnames are used
3617d74f3aSGreg Roach     *
3715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
3852348eb8SGreg Roach     *
3952348eb8SGreg Roach     * @return void
40323788f4SGreg Roach     */
419b802b22SGreg Roach    public function testMarriedSurnames(): void
42c1010edaSGreg Roach    {
435e933c21SGreg Roach        self::assertFalse($this->surname_tradition->hasMarriedNames());
44323788f4SGreg Roach    }
45323788f4SGreg Roach
46323788f4SGreg Roach    /**
47c1ec7145SGreg Roach     * Test whether surnames are used
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52c1ec7145SGreg Roach     */
539b802b22SGreg Roach    public function testSurnames(): void
54c1010edaSGreg Roach    {
555e933c21SGreg Roach        self::assertFalse($this->surname_tradition->hasSurnames());
56c1ec7145SGreg Roach    }
57c1ec7145SGreg Roach
58c1ec7145SGreg Roach    /**
59323788f4SGreg Roach     * Test new son names
6017d74f3aSGreg Roach     *
6115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
6252348eb8SGreg Roach     *
6352348eb8SGreg Roach     * @return void
64323788f4SGreg Roach     */
659b802b22SGreg Roach    public function testNewSonNames(): void
66c1010edaSGreg Roach    {
67*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
68*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson');
69*cb7a42eaSGreg Roach
70*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
71*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
72*cb7a42eaSGreg Roach
73*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
74*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir');
75*cb7a42eaSGreg Roach
76*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
77*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
78*cb7a42eaSGreg Roach
795e933c21SGreg Roach        self::assertSame(
80*cb7a42eaSGreg Roach            ["1 NAME Jonsson\n2 TYPE birth\n2 GIVN Jonsson"],
81*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
82323788f4SGreg Roach        );
83323788f4SGreg Roach    }
84323788f4SGreg Roach
85323788f4SGreg Roach    /**
86323788f4SGreg Roach     * Test new daughter names
8717d74f3aSGreg Roach     *
8815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
8952348eb8SGreg Roach     *
9052348eb8SGreg Roach     * @return void
91323788f4SGreg Roach     */
929b802b22SGreg Roach    public function testNewDaughterNames(): void
93c1010edaSGreg Roach    {
94*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
95*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson');
96*cb7a42eaSGreg Roach
97*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
98*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
99*cb7a42eaSGreg Roach
100*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
101*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir');
102*cb7a42eaSGreg Roach
103*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
104*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
105*cb7a42eaSGreg Roach
1065e933c21SGreg Roach        self::assertSame(
107*cb7a42eaSGreg Roach            ["1 NAME Jonsdottir\n2 TYPE birth\n2 GIVN Jonsdottir"],
108*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
109323788f4SGreg Roach        );
110323788f4SGreg Roach    }
111323788f4SGreg Roach
112323788f4SGreg Roach    /**
113323788f4SGreg Roach     * Test new child names
11417d74f3aSGreg Roach     *
11515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
11652348eb8SGreg Roach     *
11752348eb8SGreg Roach     * @return void
118323788f4SGreg Roach     */
1199b802b22SGreg Roach    public function testNewChildNames(): void
120c1010edaSGreg Roach    {
121*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
122*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson');
123*cb7a42eaSGreg Roach
124*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
125*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
126*cb7a42eaSGreg Roach
127*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
128*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir');
129*cb7a42eaSGreg Roach
130*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
131*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
132*cb7a42eaSGreg Roach
1335e933c21SGreg Roach        self::assertSame(
134*cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
135*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
136323788f4SGreg Roach        );
137323788f4SGreg Roach    }
138323788f4SGreg Roach
139323788f4SGreg Roach    /**
140323788f4SGreg Roach     * Test new father names
14117d74f3aSGreg Roach     *
14215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
14352348eb8SGreg Roach     *
14452348eb8SGreg Roach     * @return void
145323788f4SGreg Roach     */
1469b802b22SGreg Roach    public function testNewFatherNames(): void
147c1010edaSGreg Roach    {
148*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
149*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson');
150*cb7a42eaSGreg Roach
151*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
152*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
153*cb7a42eaSGreg Roach
1545e933c21SGreg Roach        self::assertSame(
155*cb7a42eaSGreg Roach            ["1 NAME Einar\n2 TYPE birth\n2 GIVN Einar"],
156*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
157323788f4SGreg Roach        );
158323788f4SGreg Roach    }
159323788f4SGreg Roach
160323788f4SGreg Roach    /**
161323788f4SGreg Roach     * Test new mother names
16217d74f3aSGreg Roach     *
16315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
16452348eb8SGreg Roach     *
16552348eb8SGreg Roach     * @return void
166323788f4SGreg Roach     */
1679b802b22SGreg Roach    public function testNewMotherNames(): void
168c1010edaSGreg Roach    {
169*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
170*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Jon Evasdottir');
171*cb7a42eaSGreg Roach
172*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
173*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
174*cb7a42eaSGreg Roach
1755e933c21SGreg Roach        self::assertSame(
176*cb7a42eaSGreg Roach            ["1 NAME Eva\n2 TYPE birth\n2 GIVN Eva"],
177*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
178323788f4SGreg Roach        );
179323788f4SGreg Roach    }
180323788f4SGreg Roach
181323788f4SGreg Roach    /**
182323788f4SGreg Roach     * Test new parent names
18317d74f3aSGreg Roach     *
18415d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
18552348eb8SGreg Roach     *
18652348eb8SGreg Roach     * @return void
187323788f4SGreg Roach     */
1889b802b22SGreg Roach    public function testNewParentNames(): void
189c1010edaSGreg Roach    {
190*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
191*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson');
192323788f4SGreg Roach
193*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
194*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
195323788f4SGreg Roach
1965e933c21SGreg Roach        self::assertSame(
197*cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
198*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
199323788f4SGreg Roach        );
200323788f4SGreg Roach    }
201323788f4SGreg Roach
202323788f4SGreg Roach    /**
203323788f4SGreg Roach     * Test new spouse names
20417d74f3aSGreg Roach     *
20515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition
20652348eb8SGreg Roach     *
20752348eb8SGreg Roach     * @return void
208323788f4SGreg Roach     */
2099b802b22SGreg Roach    public function testNewSpouseNames(): void
210c1010edaSGreg Roach    {
211*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
212*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson');
213*cb7a42eaSGreg Roach
214*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
215*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
216*cb7a42eaSGreg Roach
2175e933c21SGreg Roach        self::assertSame(
218*cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
219*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
220323788f4SGreg Roach        );
221*cb7a42eaSGreg Roach
222*cb7a42eaSGreg Roach        self::assertSame(
223*cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
224*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
225*cb7a42eaSGreg Roach        );
226*cb7a42eaSGreg Roach
227*cb7a42eaSGreg Roach        self::assertSame(
228*cb7a42eaSGreg Roach            ["1 NAME\n2 TYPE birth"],
229*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
230*cb7a42eaSGreg Roach        );
231*cb7a42eaSGreg Roach    }
232*cb7a42eaSGreg Roach
233*cb7a42eaSGreg Roach    /**
234*cb7a42eaSGreg Roach     * Prepare the environment for these tests
235*cb7a42eaSGreg Roach     *
236*cb7a42eaSGreg Roach     * @return void
237*cb7a42eaSGreg Roach     */
238*cb7a42eaSGreg Roach    protected function setUp(): void
239*cb7a42eaSGreg Roach    {
240*cb7a42eaSGreg Roach        parent::setUp();
241*cb7a42eaSGreg Roach
242*cb7a42eaSGreg Roach        $this->surname_tradition = new IcelandicSurnameTradition();
243323788f4SGreg Roach    }
244323788f4SGreg Roach}
245