xref: /webtrees/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php (revision cb7a42eae1efabac96d9d7693151fe0421b6717b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9323788f4SGreg Roach * (at your option) any later version.
10323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13323788f4SGreg Roach * GNU General Public License for more details.
14323788f4SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16323788f4SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
21c1010edaSGreg Roach
22*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact;
23*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
25*cb7a42eaSGreg Roachuse Illuminate\Support\Collection;
263cfcc809SGreg Roach
27323788f4SGreg Roach/**
28c4943cffSGreg Roach * Test harness for the class PortugueseSurnameTradition
29323788f4SGreg Roach */
303cfcc809SGreg Roachclass PortugueseSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35323788f4SGreg Roach     * Prepare the environment for these tests
3652348eb8SGreg Roach     *
3752348eb8SGreg Roach     * @return void
38323788f4SGreg Roach     */
395c48bcd6SGreg Roach    protected function setUp(): void
40c1010edaSGreg Roach    {
410115bc16SGreg Roach        parent::setUp();
420115bc16SGreg Roach
4374d6dc0eSGreg Roach        $this->surname_tradition = new PortugueseSurnameTradition();
44323788f4SGreg Roach    }
45323788f4SGreg Roach
46323788f4SGreg Roach    /**
47323788f4SGreg Roach     * Test whether married surnames are used
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52323788f4SGreg Roach     */
539b802b22SGreg Roach    public function testMarriedSurnames(): void
54c1010edaSGreg Roach    {
555e933c21SGreg Roach        self::assertFalse($this->surname_tradition->hasMarriedNames());
56323788f4SGreg Roach    }
57323788f4SGreg Roach
58323788f4SGreg Roach    /**
59c1ec7145SGreg Roach     * Test whether surnames are used
6017d74f3aSGreg Roach     *
6115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
6252348eb8SGreg Roach     *
6352348eb8SGreg Roach     * @return void
64c1ec7145SGreg Roach     */
659b802b22SGreg Roach    public function testSurnames(): void
66c1010edaSGreg Roach    {
675e933c21SGreg Roach        self::assertTrue($this->surname_tradition->hasSurnames());
68c1ec7145SGreg Roach    }
69c1ec7145SGreg Roach
70c1ec7145SGreg Roach    /**
71323788f4SGreg Roach     * Test new child names
7217d74f3aSGreg Roach     *
7315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
7452348eb8SGreg Roach     *
7552348eb8SGreg Roach     * @return void
76323788f4SGreg Roach     */
779b802b22SGreg Roach    public function testNewChildNames(): void
78c1010edaSGreg Roach    {
79*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
80*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
81*cb7a42eaSGreg Roach
82*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
83*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
84*cb7a42eaSGreg Roach
85*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
86*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Maria /Ruiz/ /Lorca/');
87*cb7a42eaSGreg Roach
88*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
89*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
90*cb7a42eaSGreg Roach
915e933c21SGreg Roach        self::assertSame(
92*cb7a42eaSGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
93*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
94*cb7a42eaSGreg Roach        );
95*cb7a42eaSGreg Roach
96*cb7a42eaSGreg Roach        self::assertSame(
97*cb7a42eaSGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
98*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
99*cb7a42eaSGreg Roach        );
100*cb7a42eaSGreg Roach
101*cb7a42eaSGreg Roach        self::assertSame(
102*cb7a42eaSGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
103*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
104323788f4SGreg Roach        );
105323788f4SGreg Roach    }
106323788f4SGreg Roach
107323788f4SGreg Roach    /**
108323788f4SGreg Roach     * Test new child names
10917d74f3aSGreg Roach     *
11015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
11152348eb8SGreg Roach     *
11252348eb8SGreg Roach     * @return void
113323788f4SGreg Roach     */
1149b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
115c1010edaSGreg Roach    {
1165e933c21SGreg Roach        self::assertSame(
117*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
118*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
1191677a03aSGreg Roach        );
1201677a03aSGreg Roach    }
1211677a03aSGreg Roach
1221677a03aSGreg Roach    /**
1231677a03aSGreg Roach     * Test new child names
12417d74f3aSGreg Roach     *
12515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
12652348eb8SGreg Roach     *
12752348eb8SGreg Roach     * @return void
1281677a03aSGreg Roach     */
1299b802b22SGreg Roach    public function testNewChildNamesCompunds(): void
130c1010edaSGreg Roach    {
131*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
132*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
133323788f4SGreg Roach
134*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
135*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
136323788f4SGreg Roach
137*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
138*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Maria /Ruiz/ y /Lorca/');
139*cb7a42eaSGreg Roach
140*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
141*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
142*cb7a42eaSGreg Roach
1435e933c21SGreg Roach        self::assertSame(
144*cb7a42eaSGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"],
145*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
146323788f4SGreg Roach        );
147323788f4SGreg Roach    }
148323788f4SGreg Roach
149323788f4SGreg Roach    /**
150323788f4SGreg Roach     * Test new parent names
15117d74f3aSGreg Roach     *
15215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
15352348eb8SGreg Roach     *
15452348eb8SGreg Roach     * @return void
155323788f4SGreg Roach     */
1569b802b22SGreg Roach    public function testNewParentNames(): void
157c1010edaSGreg Roach    {
158*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
159*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
160323788f4SGreg Roach
161*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
162*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
163323788f4SGreg Roach
1645e933c21SGreg Roach        self::assertSame(
165*cb7a42eaSGreg Roach            ["1 NAME // /Garcia/\n2 TYPE birth\n2 SURN Garcia"],
166*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
167*cb7a42eaSGreg Roach        );
168*cb7a42eaSGreg Roach        self::assertSame(
169*cb7a42eaSGreg Roach            ["1 NAME // /Iglesias/\n2 TYPE birth\n2 SURN Iglesias"],
170*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
171*cb7a42eaSGreg Roach        );
172*cb7a42eaSGreg Roach
173*cb7a42eaSGreg Roach        self::assertSame(
174*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
175*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
176323788f4SGreg Roach        );
177323788f4SGreg Roach    }
178323788f4SGreg Roach
179323788f4SGreg Roach    /**
180323788f4SGreg Roach     * Test new spouse names
18117d74f3aSGreg Roach     *
18215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition
18352348eb8SGreg Roach     *
18452348eb8SGreg Roach     * @return void
185323788f4SGreg Roach     */
1869b802b22SGreg Roach    public function testNewSpouseNames(): void
187c1010edaSGreg Roach    {
188*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
189*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
190*cb7a42eaSGreg Roach
191*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
192*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
193*cb7a42eaSGreg Roach
1945e933c21SGreg Roach        self::assertSame(
195*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
196*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
197*cb7a42eaSGreg Roach        );
198*cb7a42eaSGreg Roach
199*cb7a42eaSGreg Roach        self::assertSame(
200*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
201*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
202*cb7a42eaSGreg Roach        );
203*cb7a42eaSGreg Roach
204*cb7a42eaSGreg Roach        self::assertSame(
205*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
206*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
207323788f4SGreg Roach        );
208323788f4SGreg Roach    }
209323788f4SGreg Roach}
210