xref: /webtrees/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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;
26202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
273cfcc809SGreg Roach
28202c018bSGreg Roach#[CoversClass(SpanishSurnameTradition::class)]
293cfcc809SGreg Roachclass SpanishSurnameTraditionTest extends TestCase
30c1010edaSGreg Roach{
31c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
32323788f4SGreg Roach
33323788f4SGreg Roach    /**
34c1ec7145SGreg Roach     * Test whether surnames are used
35c1ec7145SGreg Roach     */
369b802b22SGreg Roach    public function testSurnames(): void
37c1010edaSGreg Roach    {
38a171b6a5SGreg Roach        self::assertSame('// //', $this->surname_tradition->defaultName());
39c1ec7145SGreg Roach    }
40c1ec7145SGreg Roach
41c1ec7145SGreg Roach    /**
42323788f4SGreg Roach     * Test new child names
43323788f4SGreg Roach     */
449b802b22SGreg Roach    public function testNewChildNames(): void
45c1010edaSGreg Roach    {
46*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
4783c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
48cb7a42eaSGreg Roach
49*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
5083c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
51cb7a42eaSGreg Roach
52*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
5383c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/');
54cb7a42eaSGreg Roach
55*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
5683c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
57cb7a42eaSGreg Roach
585e933c21SGreg Roach        self::assertSame(
598939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
60cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
61cb7a42eaSGreg Roach        );
62cb7a42eaSGreg Roach
63cb7a42eaSGreg Roach        self::assertSame(
648939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
65cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
66cb7a42eaSGreg Roach        );
67cb7a42eaSGreg Roach
68cb7a42eaSGreg Roach        self::assertSame(
698939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
70cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
71323788f4SGreg Roach        );
72323788f4SGreg Roach    }
73323788f4SGreg Roach
74323788f4SGreg Roach    /**
75323788f4SGreg Roach     * Test new child names
76323788f4SGreg Roach     */
779b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
78c1010edaSGreg Roach    {
795e933c21SGreg Roach        self::assertSame(
808939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
81cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
821677a03aSGreg Roach        );
831677a03aSGreg Roach    }
841677a03aSGreg Roach
851677a03aSGreg Roach    /**
861677a03aSGreg Roach     * Test new child names
871677a03aSGreg Roach     */
88cb7a42eaSGreg Roach    public function testNewChildNamesCompound(): void
89c1010edaSGreg Roach    {
90*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
9183c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
92323788f4SGreg Roach
93*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
9483c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
95323788f4SGreg Roach
96*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
9783c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/');
98cb7a42eaSGreg Roach
99*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
10083c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
101cb7a42eaSGreg Roach
1025e933c21SGreg Roach        self::assertSame(
1038939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
104cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
105323788f4SGreg Roach        );
106323788f4SGreg Roach    }
107323788f4SGreg Roach
108323788f4SGreg Roach    /**
109323788f4SGreg Roach     * Test new parent names
110323788f4SGreg Roach     */
1119b802b22SGreg Roach    public function testNewParentNames(): void
112c1010edaSGreg Roach    {
113*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
11483c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
115323788f4SGreg Roach
116*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
11783c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
118323788f4SGreg Roach
1195e933c21SGreg Roach        self::assertSame(
1208939e2c2SGreg Roach            ["1 NAME /Garcia/ //\n2 TYPE BIRTH\n2 SURN Garcia"],
121cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
122cb7a42eaSGreg Roach        );
123cb7a42eaSGreg Roach
124cb7a42eaSGreg Roach        self::assertSame(
1258939e2c2SGreg Roach            ["1 NAME /Iglesias/ //\n2 TYPE BIRTH\n2 SURN Iglesias"],
126cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
127cb7a42eaSGreg Roach        );
128cb7a42eaSGreg Roach
129cb7a42eaSGreg Roach        self::assertSame(
1308939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
131cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
132323788f4SGreg Roach        );
133323788f4SGreg Roach    }
134323788f4SGreg Roach
135323788f4SGreg Roach    /**
136323788f4SGreg Roach     * Test new spouse names
137323788f4SGreg Roach     */
1389b802b22SGreg Roach    public function testNewSpouseNames(): void
139c1010edaSGreg Roach    {
140*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
14183c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
142cb7a42eaSGreg Roach
143*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
14483c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
145cb7a42eaSGreg Roach
1465e933c21SGreg Roach        self::assertSame(
1478939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
148cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
149323788f4SGreg Roach        );
150cb7a42eaSGreg Roach
151cb7a42eaSGreg Roach        self::assertSame(
1528939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
153cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
154cb7a42eaSGreg Roach        );
155cb7a42eaSGreg Roach
156cb7a42eaSGreg Roach        self::assertSame(
1578939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
158cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
159cb7a42eaSGreg Roach        );
160cb7a42eaSGreg Roach    }
161cb7a42eaSGreg Roach
162cb7a42eaSGreg Roach    /**
163cb7a42eaSGreg Roach     * Prepare the environment for these tests
164cb7a42eaSGreg Roach     */
165cb7a42eaSGreg Roach    protected function setUp(): void
166cb7a42eaSGreg Roach    {
167cb7a42eaSGreg Roach        parent::setUp();
168cb7a42eaSGreg Roach
169cb7a42eaSGreg Roach        $this->surname_tradition = new SpanishSurnameTradition();
170323788f4SGreg Roach    }
171323788f4SGreg Roach}
172