xref: /webtrees/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php (revision 8634febf6487fcb3ee7b59e88f828071a22cba22)
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 PortugueseSurnameTradition
29 */
30class PortugueseSurnameTraditionTest 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 PortugueseSurnameTradition();
44    }
45
46    /**
47     * Test whether surnames are used
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
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\PortugueseSurnameTradition
62     *
63     * @return void
64     */
65    public function testNewChildNames(): void
66    {
67        $father_fact = $this->createStub(Fact::class);
68        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
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('Maria /Ruiz/ /Lorca/');
75
76        $mother = $this->createStub(Individual::class);
77        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
78
79        self::assertSame(
80            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
81            $this->surname_tradition->newChildNames($father, $mother, 'M')
82        );
83
84        self::assertSame(
85            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
86            $this->surname_tradition->newChildNames($father, $mother, 'F')
87        );
88
89        self::assertSame(
90            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
91            $this->surname_tradition->newChildNames($father, $mother, 'U')
92        );
93    }
94
95    /**
96     * Test new child names
97     *
98     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
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\PortugueseSurnameTradition
114     *
115     * @return void
116     */
117    public function testNewChildNamesCompunds(): void
118    {
119        $father_fact = $this->createStub(Fact::class);
120        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
121
122        $father = $this->createStub(Individual::class);
123        $father->method('facts')->willReturn(new Collection([$father_fact]));
124
125        $mother_fact = $this->createStub(Fact::class);
126        $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/');
127
128        $mother = $this->createStub(Individual::class);
129        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
130
131        self::assertSame(
132            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
133            $this->surname_tradition->newChildNames($father, $mother, 'M')
134        );
135    }
136
137    /**
138     * Test new parent names
139     *
140     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
141     *
142     * @return void
143     */
144    public function testNewParentNames(): void
145    {
146        $fact = $this->createStub(Fact::class);
147        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
148
149        $individual = $this->createStub(Individual::class);
150        $individual->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        self::assertSame(
157            ["1 NAME // /Iglesias/\n2 TYPE BIRTH\n2 SURN Iglesias"],
158            $this->surname_tradition->newParentNames($individual, 'F')
159        );
160
161        self::assertSame(
162            ["1 NAME // //\n2 TYPE BIRTH"],
163            $this->surname_tradition->newParentNames($individual, 'U')
164        );
165    }
166
167    /**
168     * Test new spouse names
169     *
170     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
171     *
172     * @return void
173     */
174    public function testNewSpouseNames(): void
175    {
176        $fact = $this->createStub(Fact::class);
177        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
178
179        $individual = $this->createStub(Individual::class);
180        $individual->method('facts')->willReturn(new Collection([$fact]));
181
182        self::assertSame(
183            ["1 NAME // //\n2 TYPE BIRTH"],
184            $this->surname_tradition->newSpouseNames($individual, 'M')
185        );
186
187        self::assertSame(
188            ["1 NAME // //\n2 TYPE BIRTH"],
189            $this->surname_tradition->newSpouseNames($individual, 'F')
190        );
191
192        self::assertSame(
193            ["1 NAME // //\n2 TYPE BIRTH"],
194            $this->surname_tradition->newSpouseNames($individual, 'U')
195        );
196    }
197}
198