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