xref: /webtrees/tests/app/SurnameTradition/SpanishSurnameTraditionTest.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/**
28323788f4SGreg Roach * Test harness for the class SpanishSurnameTradition
29323788f4SGreg Roach */
303cfcc809SGreg Roachclass SpanishSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35323788f4SGreg Roach     * Test whether married surnames are used
3617d74f3aSGreg Roach     *
3715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
3852348eb8SGreg Roach     *
3952348eb8SGreg Roach     * @return void
40323788f4SGreg Roach     */
419b802b22SGreg Roach    public function testMarriedSurnames(): void
42c1010edaSGreg Roach    {
435e933c21SGreg Roach        self::assertFalse($this->surname_tradition->hasMarriedNames());
44323788f4SGreg Roach    }
45323788f4SGreg Roach
46323788f4SGreg Roach    /**
47c1ec7145SGreg Roach     * Test whether surnames are used
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52c1ec7145SGreg Roach     */
539b802b22SGreg Roach    public function testSurnames(): void
54c1010edaSGreg Roach    {
555e933c21SGreg Roach        self::assertTrue($this->surname_tradition->hasSurnames());
56c1ec7145SGreg Roach    }
57c1ec7145SGreg Roach
58c1ec7145SGreg Roach    /**
59323788f4SGreg Roach     * Test new child names
6017d74f3aSGreg Roach     *
6115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
6252348eb8SGreg Roach     *
6352348eb8SGreg Roach     * @return void
64323788f4SGreg Roach     */
659b802b22SGreg Roach    public function testNewChildNames(): void
66c1010edaSGreg Roach    {
67*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
68*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
69*cb7a42eaSGreg Roach
70*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
71*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
72*cb7a42eaSGreg Roach
73*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
74*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/');
75*cb7a42eaSGreg Roach
76*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
77*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
78*cb7a42eaSGreg Roach
795e933c21SGreg Roach        self::assertSame(
80*cb7a42eaSGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
81*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
82*cb7a42eaSGreg Roach        );
83*cb7a42eaSGreg Roach
84*cb7a42eaSGreg Roach        self::assertSame(
85*cb7a42eaSGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
86*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
87*cb7a42eaSGreg Roach        );
88*cb7a42eaSGreg Roach
89*cb7a42eaSGreg Roach        self::assertSame(
90*cb7a42eaSGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
91*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
92323788f4SGreg Roach        );
93323788f4SGreg Roach    }
94323788f4SGreg Roach
95323788f4SGreg Roach    /**
96323788f4SGreg Roach     * Test new child names
9717d74f3aSGreg Roach     *
9815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
9952348eb8SGreg Roach     *
10052348eb8SGreg Roach     * @return void
101323788f4SGreg Roach     */
1029b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
103c1010edaSGreg Roach    {
1045e933c21SGreg Roach        self::assertSame(
105*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
106*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
1071677a03aSGreg Roach        );
1081677a03aSGreg Roach    }
1091677a03aSGreg Roach
1101677a03aSGreg Roach    /**
1111677a03aSGreg Roach     * Test new child names
11217d74f3aSGreg Roach     *
11315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
11452348eb8SGreg Roach     *
11552348eb8SGreg Roach     * @return void
1161677a03aSGreg Roach     */
117*cb7a42eaSGreg Roach    public function testNewChildNamesCompound(): void
118c1010edaSGreg Roach    {
119*cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
120*cb7a42eaSGreg Roach        $father_fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
121323788f4SGreg Roach
122*cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
123*cb7a42eaSGreg Roach        $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact]));
124323788f4SGreg Roach
125*cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
126*cb7a42eaSGreg Roach        $mother_fact->expects(self::any())->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/');
127*cb7a42eaSGreg Roach
128*cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
129*cb7a42eaSGreg Roach        $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact]));
130*cb7a42eaSGreg Roach
1315e933c21SGreg Roach        self::assertSame(
132*cb7a42eaSGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE birth\n2 SURN Garcia,Ruiz"],
133*cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
134323788f4SGreg Roach        );
135323788f4SGreg Roach    }
136323788f4SGreg Roach
137323788f4SGreg Roach    /**
138323788f4SGreg Roach     * Test new parent names
13917d74f3aSGreg Roach     *
14015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
14152348eb8SGreg Roach     *
14252348eb8SGreg Roach     * @return void
143323788f4SGreg Roach     */
1449b802b22SGreg Roach    public function testNewParentNames(): void
145c1010edaSGreg Roach    {
146*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
147*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
148323788f4SGreg Roach
149*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
150*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
151323788f4SGreg Roach
1525e933c21SGreg Roach        self::assertSame(
153*cb7a42eaSGreg Roach            ["1 NAME /Garcia/ //\n2 TYPE birth\n2 SURN Garcia"],
154*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
155*cb7a42eaSGreg Roach        );
156*cb7a42eaSGreg Roach
157*cb7a42eaSGreg Roach        self::assertSame(
158*cb7a42eaSGreg Roach            ["1 NAME /Iglesias/ //\n2 TYPE birth\n2 SURN Iglesias"],
159*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
160*cb7a42eaSGreg Roach        );
161*cb7a42eaSGreg Roach
162*cb7a42eaSGreg Roach        self::assertSame(
163*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
164*cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
165323788f4SGreg Roach        );
166323788f4SGreg Roach    }
167323788f4SGreg Roach
168323788f4SGreg Roach    /**
169323788f4SGreg Roach     * Test new spouse names
17017d74f3aSGreg Roach     *
17115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
17252348eb8SGreg Roach     *
17352348eb8SGreg Roach     * @return void
174323788f4SGreg Roach     */
1759b802b22SGreg Roach    public function testNewSpouseNames(): void
176c1010edaSGreg Roach    {
177*cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
178*cb7a42eaSGreg Roach        $fact->expects(self::any())->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
179*cb7a42eaSGreg Roach
180*cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
181*cb7a42eaSGreg Roach        $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact]));
182*cb7a42eaSGreg Roach
1835e933c21SGreg Roach        self::assertSame(
184*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
185*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
186323788f4SGreg Roach        );
187*cb7a42eaSGreg Roach
188*cb7a42eaSGreg Roach        self::assertSame(
189*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
190*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
191*cb7a42eaSGreg Roach        );
192*cb7a42eaSGreg Roach
193*cb7a42eaSGreg Roach        self::assertSame(
194*cb7a42eaSGreg Roach            ["1 NAME // //\n2 TYPE birth"],
195*cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
196*cb7a42eaSGreg Roach        );
197*cb7a42eaSGreg Roach    }
198*cb7a42eaSGreg Roach
199*cb7a42eaSGreg Roach    /**
200*cb7a42eaSGreg Roach     * Prepare the environment for these tests
201*cb7a42eaSGreg Roach     *
202*cb7a42eaSGreg Roach     * @return void
203*cb7a42eaSGreg Roach     */
204*cb7a42eaSGreg Roach    protected function setUp(): void
205*cb7a42eaSGreg Roach    {
206*cb7a42eaSGreg Roach        parent::setUp();
207*cb7a42eaSGreg Roach
208*cb7a42eaSGreg Roach        $this->surname_tradition = new SpanishSurnameTradition();
209323788f4SGreg Roach    }
210323788f4SGreg Roach}
211