xref: /webtrees/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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;
26use PHPUnit\Framework\Attributes\CoversClass;
27
28
29#[CoversClass(PortugueseSurnameTradition::class)]
30class PortugueseSurnameTraditionTest 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 PortugueseSurnameTradition();
42    }
43
44    /**
45     * Test whether surnames are used
46     */
47    public function testSurnames(): void
48    {
49        self::assertSame('// //', $this->surname_tradition->defaultName());
50    }
51
52    /**
53     * Test new child names
54     */
55    public function testNewChildNames(): void
56    {
57        $father_fact = $this->createStub(Fact::class);
58        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
59
60        $father = $this->createStub(Individual::class);
61        $father->method('facts')->willReturn(new Collection([$father_fact]));
62
63        $mother_fact = $this->createStub(Fact::class);
64        $mother_fact->method('value')->willReturn('Maria /Ruiz/ /Lorca/');
65
66        $mother = $this->createStub(Individual::class);
67        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
68
69        self::assertSame(
70            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
71            $this->surname_tradition->newChildNames($father, $mother, 'M')
72        );
73
74        self::assertSame(
75            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
76            $this->surname_tradition->newChildNames($father, $mother, 'F')
77        );
78
79        self::assertSame(
80            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
81            $this->surname_tradition->newChildNames($father, $mother, 'U')
82        );
83    }
84
85    /**
86     * Test new child names
87     */
88    public function testNewChildNamesWithNoParentsNames(): void
89    {
90        self::assertSame(
91            ["1 NAME // //\n2 TYPE BIRTH"],
92            $this->surname_tradition->newChildNames(null, null, 'U')
93        );
94    }
95
96    /**
97     * Test new child names
98     */
99    public function testNewChildNamesCompunds(): void
100    {
101        $father_fact = $this->createStub(Fact::class);
102        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
103
104        $father = $this->createStub(Individual::class);
105        $father->method('facts')->willReturn(new Collection([$father_fact]));
106
107        $mother_fact = $this->createStub(Fact::class);
108        $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/');
109
110        $mother = $this->createStub(Individual::class);
111        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
112
113        self::assertSame(
114            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
115            $this->surname_tradition->newChildNames($father, $mother, 'M')
116        );
117    }
118
119    /**
120     * Test new parent names
121     */
122    public function testNewParentNames(): void
123    {
124        $fact = $this->createStub(Fact::class);
125        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
126
127        $individual = $this->createStub(Individual::class);
128        $individual->method('facts')->willReturn(new Collection([$fact]));
129
130        self::assertSame(
131            ["1 NAME // /Garcia/\n2 TYPE BIRTH\n2 SURN Garcia"],
132            $this->surname_tradition->newParentNames($individual, 'M')
133        );
134        self::assertSame(
135            ["1 NAME // /Iglesias/\n2 TYPE BIRTH\n2 SURN Iglesias"],
136            $this->surname_tradition->newParentNames($individual, 'F')
137        );
138
139        self::assertSame(
140            ["1 NAME // //\n2 TYPE BIRTH"],
141            $this->surname_tradition->newParentNames($individual, 'U')
142        );
143    }
144
145    /**
146     * Test new spouse names
147     */
148    public function testNewSpouseNames(): void
149    {
150        $fact = $this->createStub(Fact::class);
151        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
152
153        $individual = $this->createStub(Individual::class);
154        $individual->method('facts')->willReturn(new Collection([$fact]));
155
156        self::assertSame(
157            ["1 NAME // //\n2 TYPE BIRTH"],
158            $this->surname_tradition->newSpouseNames($individual, 'M')
159        );
160
161        self::assertSame(
162            ["1 NAME // //\n2 TYPE BIRTH"],
163            $this->surname_tradition->newSpouseNames($individual, 'F')
164        );
165
166        self::assertSame(
167            ["1 NAME // //\n2 TYPE BIRTH"],
168            $this->surname_tradition->newSpouseNames($individual, 'U')
169        );
170    }
171}
172