xref: /webtrees/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php (revision b52a415d9d1e0b9a0fa9ea0bcfa09b8564512a75)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 SpanishSurnameTradition
29 */
30class SpanishSurnameTraditionTest extends TestCase
31{
32    private SurnameTraditionInterface $surname_tradition;
33
34    /**
35     * Test whether married surnames are used
36     *
37     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
38     *
39     * @return void
40     */
41    public function testMarriedSurnames(): void
42    {
43        self::assertFalse($this->surname_tradition->hasMarriedNames());
44    }
45
46    /**
47     * Test whether surnames are used
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
50     *
51     * @return void
52     */
53    public function testSurnames(): void
54    {
55        self::assertTrue($this->surname_tradition->hasSurnames());
56    }
57
58    /**
59     * Test new child names
60     *
61     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
62     *
63     * @return void
64     */
65    public function testNewChildNames(): void
66    {
67        $father_fact = $this->createStub(Fact::class);
68        $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
69
70        $father = $this->createStub(Individual::class);
71        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
72
73        $mother_fact = $this->createStub(Fact::class);
74        $mother_fact->expects(self::any())->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/');
75
76        $mother = $this->createStub(Individual::class);
77        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
78
79        self::assertSame(
80            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
81            $this->surname_tradition->newChildNames($father, $mother, 'M')
82        );
83
84        self::assertSame(
85            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
86            $this->surname_tradition->newChildNames($father, $mother, 'F')
87        );
88
89        self::assertSame(
90            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
91            $this->surname_tradition->newChildNames($father, $mother, 'U')
92        );
93    }
94
95    /**
96     * Test new child names
97     *
98     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
99     *
100     * @return void
101     */
102    public function testNewChildNamesWithNoParentsNames(): void
103    {
104        self::assertSame(
105            ["1 NAME // //\n2 TYPE birth"],
106            $this->surname_tradition->newChildNames(null, null, 'U')
107        );
108    }
109
110    /**
111     * Test new child names
112     *
113     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
114     *
115     * @return void
116     */
117    public function testNewChildNamesCompound(): void
118    {
119        $father_fact = $this->createStub(Fact::class);
120        $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
121
122        $father = $this->createStub(Individual::class);
123        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
124
125        $mother_fact = $this->createStub(Fact::class);
126        $mother_fact->expects(self::any())->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/');
127
128        $mother = $this->createStub(Individual::class);
129        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
130
131        self::assertSame(
132            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
133            $this->surname_tradition->newChildNames($father, $mother, 'M')
134        );
135    }
136
137    /**
138     * Test new parent names
139     *
140     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
141     *
142     * @return void
143     */
144    public function testNewParentNames(): void
145    {
146        $fact = $this->createStub(Fact::class);
147        $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
148
149        $individual = $this->createStub(Individual::class);
150        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
151
152        self::assertSame(
153            ["1 NAME /Garcia/ //\n2 TYPE birth\n2 SURN Garcia"],
154            $this->surname_tradition->newParentNames($individual, 'M')
155        );
156
157        self::assertSame(
158            ["1 NAME /Iglesias/ //\n2 TYPE birth\n2 SURN Iglesias"],
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\SpanishSurnameTradition
172     *
173     * @return void
174     */
175    public function testNewSpouseNames(): void
176    {
177        $fact = $this->createStub(Fact::class);
178        $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
179
180        $individual = $this->createStub(Individual::class);
181        $individual->expects(self::any())->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    /**
200     * Prepare the environment for these tests
201     *
202     * @return void
203     */
204    protected function setUp(): void
205    {
206        parent::setUp();
207
208        $this->surname_tradition = new SpanishSurnameTradition();
209    }
210}
211