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