xref: /webtrees/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php (revision 8939e2c24ff4346b8c6b9f3f822a733db666d588)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 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
22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact;
23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
25cb7a42eaSGreg 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    /**
35c1ec7145SGreg Roach     * Test whether surnames are used
3617d74f3aSGreg Roach     *
3715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
3852348eb8SGreg Roach     *
3952348eb8SGreg Roach     * @return void
40c1ec7145SGreg Roach     */
419b802b22SGreg Roach    public function testSurnames(): void
42c1010edaSGreg Roach    {
43a171b6a5SGreg Roach        self::assertSame('// //', $this->surname_tradition->defaultName());
44c1ec7145SGreg Roach    }
45c1ec7145SGreg Roach
46c1ec7145SGreg Roach    /**
47323788f4SGreg Roach     * Test new child names
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52323788f4SGreg Roach     */
539b802b22SGreg Roach    public function testNewChildNames(): void
54c1010edaSGreg Roach    {
55cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
5683c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
57cb7a42eaSGreg Roach
58cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
5983c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
60cb7a42eaSGreg Roach
61cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
6283c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/');
63cb7a42eaSGreg Roach
64cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
6583c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
66cb7a42eaSGreg Roach
675e933c21SGreg Roach        self::assertSame(
68*8939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
69cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
70cb7a42eaSGreg Roach        );
71cb7a42eaSGreg Roach
72cb7a42eaSGreg Roach        self::assertSame(
73*8939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
74cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
75cb7a42eaSGreg Roach        );
76cb7a42eaSGreg Roach
77cb7a42eaSGreg Roach        self::assertSame(
78*8939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
79cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
80323788f4SGreg Roach        );
81323788f4SGreg Roach    }
82323788f4SGreg Roach
83323788f4SGreg Roach    /**
84323788f4SGreg Roach     * Test new child names
8517d74f3aSGreg Roach     *
8615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
8752348eb8SGreg Roach     *
8852348eb8SGreg Roach     * @return void
89323788f4SGreg Roach     */
909b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
91c1010edaSGreg Roach    {
925e933c21SGreg Roach        self::assertSame(
93*8939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
94cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
951677a03aSGreg Roach        );
961677a03aSGreg Roach    }
971677a03aSGreg Roach
981677a03aSGreg Roach    /**
991677a03aSGreg Roach     * Test new child names
10017d74f3aSGreg Roach     *
10115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
10252348eb8SGreg Roach     *
10352348eb8SGreg Roach     * @return void
1041677a03aSGreg Roach     */
105cb7a42eaSGreg Roach    public function testNewChildNamesCompound(): void
106c1010edaSGreg Roach    {
107cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
10883c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
109323788f4SGreg Roach
110cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
11183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
112323788f4SGreg Roach
113cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
11483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/');
115cb7a42eaSGreg Roach
116cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
11783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
118cb7a42eaSGreg Roach
1195e933c21SGreg Roach        self::assertSame(
120*8939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
121cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
122323788f4SGreg Roach        );
123323788f4SGreg Roach    }
124323788f4SGreg Roach
125323788f4SGreg Roach    /**
126323788f4SGreg Roach     * Test new parent names
12717d74f3aSGreg Roach     *
12815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
12952348eb8SGreg Roach     *
13052348eb8SGreg Roach     * @return void
131323788f4SGreg Roach     */
1329b802b22SGreg Roach    public function testNewParentNames(): void
133c1010edaSGreg Roach    {
134cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
13583c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
136323788f4SGreg Roach
137cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
13883c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
139323788f4SGreg Roach
1405e933c21SGreg Roach        self::assertSame(
141*8939e2c2SGreg Roach            ["1 NAME /Garcia/ //\n2 TYPE BIRTH\n2 SURN Garcia"],
142cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
143cb7a42eaSGreg Roach        );
144cb7a42eaSGreg Roach
145cb7a42eaSGreg Roach        self::assertSame(
146*8939e2c2SGreg Roach            ["1 NAME /Iglesias/ //\n2 TYPE BIRTH\n2 SURN Iglesias"],
147cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
148cb7a42eaSGreg Roach        );
149cb7a42eaSGreg Roach
150cb7a42eaSGreg Roach        self::assertSame(
151*8939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
152cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
153323788f4SGreg Roach        );
154323788f4SGreg Roach    }
155323788f4SGreg Roach
156323788f4SGreg Roach    /**
157323788f4SGreg Roach     * Test new spouse names
15817d74f3aSGreg Roach     *
15915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition
16052348eb8SGreg Roach     *
16152348eb8SGreg Roach     * @return void
162323788f4SGreg Roach     */
1639b802b22SGreg Roach    public function testNewSpouseNames(): void
164c1010edaSGreg Roach    {
165cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
16683c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
167cb7a42eaSGreg Roach
168cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
16983c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
170cb7a42eaSGreg Roach
1715e933c21SGreg Roach        self::assertSame(
172*8939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
173cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
174323788f4SGreg Roach        );
175cb7a42eaSGreg Roach
176cb7a42eaSGreg Roach        self::assertSame(
177*8939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
178cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
179cb7a42eaSGreg Roach        );
180cb7a42eaSGreg Roach
181cb7a42eaSGreg Roach        self::assertSame(
182*8939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
183cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
184cb7a42eaSGreg Roach        );
185cb7a42eaSGreg Roach    }
186cb7a42eaSGreg Roach
187cb7a42eaSGreg Roach    /**
188cb7a42eaSGreg Roach     * Prepare the environment for these tests
189cb7a42eaSGreg Roach     *
190cb7a42eaSGreg Roach     * @return void
191cb7a42eaSGreg Roach     */
192cb7a42eaSGreg Roach    protected function setUp(): void
193cb7a42eaSGreg Roach    {
194cb7a42eaSGreg Roach        parent::setUp();
195cb7a42eaSGreg Roach
196cb7a42eaSGreg Roach        $this->surname_tradition = new SpanishSurnameTradition();
197323788f4SGreg Roach    }
198323788f4SGreg Roach}
199