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