xref: /webtrees/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php (revision 3340ecd27b8901a894bff51b7c40bfa2896a552b)
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 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 married surnames are used
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
50     *
51     * @return void
52     */
53    public function testMarriedSurnames(): void
54    {
55        self::assertFalse($this->surname_tradition->hasMarriedNames());
56    }
57
58    /**
59     * Test whether surnames are used
60     *
61     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
62     *
63     * @return void
64     */
65    public function testSurnames(): void
66    {
67        self::assertTrue($this->surname_tradition->hasSurnames());
68    }
69
70    /**
71     * Test new child names
72     *
73     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
74     *
75     * @return void
76     */
77    public function testNewChildNames(): void
78    {
79        $father_fact = $this->createStub(Fact::class);
80        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
81
82        $father = $this->createStub(Individual::class);
83        $father->method('facts')->willReturn(new Collection([$father_fact]));
84
85        $mother_fact = $this->createStub(Fact::class);
86        $mother_fact->method('value')->willReturn('Maria /Ruiz/ /Lorca/');
87
88        $mother = $this->createStub(Individual::class);
89        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
90
91        self::assertSame(
92            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
93            $this->surname_tradition->newChildNames($father, $mother, 'M')
94        );
95
96        self::assertSame(
97            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
98            $this->surname_tradition->newChildNames($father, $mother, 'F')
99        );
100
101        self::assertSame(
102            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
103            $this->surname_tradition->newChildNames($father, $mother, 'U')
104        );
105    }
106
107    /**
108     * Test new child names
109     *
110     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
111     *
112     * @return void
113     */
114    public function testNewChildNamesWithNoParentsNames(): void
115    {
116        self::assertSame(
117            ["1 NAME // //\n2 TYPE birth"],
118            $this->surname_tradition->newChildNames(null, null, 'U')
119        );
120    }
121
122    /**
123     * Test new child names
124     *
125     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
126     *
127     * @return void
128     */
129    public function testNewChildNamesCompunds(): void
130    {
131        $father_fact = $this->createStub(Fact::class);
132        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
133
134        $father = $this->createStub(Individual::class);
135        $father->method('facts')->willReturn(new Collection([$father_fact]));
136
137        $mother_fact = $this->createStub(Fact::class);
138        $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/');
139
140        $mother = $this->createStub(Individual::class);
141        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
142
143        self::assertSame(
144            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
145            $this->surname_tradition->newChildNames($father, $mother, 'M')
146        );
147    }
148
149    /**
150     * Test new parent names
151     *
152     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
153     *
154     * @return void
155     */
156    public function testNewParentNames(): void
157    {
158        $fact = $this->createStub(Fact::class);
159        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
160
161        $individual = $this->createStub(Individual::class);
162        $individual->method('facts')->willReturn(new Collection([$fact]));
163
164        self::assertSame(
165            ["1 NAME // /Garcia/\n2 TYPE birth\n2 SURN Garcia"],
166            $this->surname_tradition->newParentNames($individual, 'M')
167        );
168        self::assertSame(
169            ["1 NAME // /Iglesias/\n2 TYPE birth\n2 SURN Iglesias"],
170            $this->surname_tradition->newParentNames($individual, 'F')
171        );
172
173        self::assertSame(
174            ["1 NAME // //\n2 TYPE birth"],
175            $this->surname_tradition->newParentNames($individual, 'U')
176        );
177    }
178
179    /**
180     * Test new spouse names
181     *
182     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
183     *
184     * @return void
185     */
186    public function testNewSpouseNames(): void
187    {
188        $fact = $this->createStub(Fact::class);
189        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
190
191        $individual = $this->createStub(Individual::class);
192        $individual->method('facts')->willReturn(new Collection([$fact]));
193
194        self::assertSame(
195            ["1 NAME // //\n2 TYPE birth"],
196            $this->surname_tradition->newSpouseNames($individual, 'M')
197        );
198
199        self::assertSame(
200            ["1 NAME // //\n2 TYPE birth"],
201            $this->surname_tradition->newSpouseNames($individual, 'F')
202        );
203
204        self::assertSame(
205            ["1 NAME // //\n2 TYPE birth"],
206            $this->surname_tradition->newSpouseNames($individual, 'U')
207        );
208    }
209}
210