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