xref: /webtrees/tests/app/SurnameTradition/PortugueseSurnameTraditionTest.php (revision 62ff2f188c699b1144fb2ca2d6da1358d5e1a745)
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
29202c018bSGreg Roach#[CoversClass(PortugueseSurnameTradition::class)]
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
36323788f4SGreg Roach     */
375c48bcd6SGreg Roach    protected function setUp(): void
38c1010edaSGreg Roach    {
390115bc16SGreg Roach        parent::setUp();
400115bc16SGreg Roach
4174d6dc0eSGreg Roach        $this->surname_tradition = new PortugueseSurnameTradition();
42323788f4SGreg Roach    }
43323788f4SGreg Roach
44323788f4SGreg Roach    /**
45c1ec7145SGreg Roach     * Test whether surnames are used
46c1ec7145SGreg Roach     */
479b802b22SGreg Roach    public function testSurnames(): void
48c1010edaSGreg Roach    {
49a171b6a5SGreg Roach        self::assertSame('// //', $this->surname_tradition->defaultName());
50c1ec7145SGreg Roach    }
51c1ec7145SGreg Roach
52c1ec7145SGreg Roach    /**
53323788f4SGreg Roach     * Test new child names
54323788f4SGreg Roach     */
559b802b22SGreg Roach    public function testNewChildNames(): void
56c1010edaSGreg Roach    {
57*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
5883c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
59cb7a42eaSGreg Roach
60*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
6183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
62cb7a42eaSGreg Roach
63*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
6483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Maria /Ruiz/ /Lorca/');
65cb7a42eaSGreg Roach
66*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
6783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
68cb7a42eaSGreg Roach
695e933c21SGreg Roach        self::assertSame(
708939e2c2SGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
71cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
72cb7a42eaSGreg Roach        );
73cb7a42eaSGreg Roach
74cb7a42eaSGreg Roach        self::assertSame(
758939e2c2SGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
76cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
77cb7a42eaSGreg Roach        );
78cb7a42eaSGreg Roach
79cb7a42eaSGreg Roach        self::assertSame(
808939e2c2SGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
81cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
82323788f4SGreg Roach        );
83323788f4SGreg Roach    }
84323788f4SGreg Roach
85323788f4SGreg Roach    /**
86323788f4SGreg Roach     * Test new child names
87323788f4SGreg Roach     */
889b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
89c1010edaSGreg Roach    {
905e933c21SGreg Roach        self::assertSame(
918939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
92cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
931677a03aSGreg Roach        );
941677a03aSGreg Roach    }
951677a03aSGreg Roach
961677a03aSGreg Roach    /**
971677a03aSGreg Roach     * Test new child names
981677a03aSGreg Roach     */
999b802b22SGreg Roach    public function testNewChildNamesCompunds(): void
100c1010edaSGreg Roach    {
101*62ff2f18SGreg Roach        $father_fact = $this->createMock(Fact::class);
10283c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
103323788f4SGreg Roach
104*62ff2f18SGreg Roach        $father = $this->createMock(Individual::class);
10583c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
106323788f4SGreg Roach
107*62ff2f18SGreg Roach        $mother_fact = $this->createMock(Fact::class);
10883c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/');
109cb7a42eaSGreg Roach
110*62ff2f18SGreg Roach        $mother = $this->createMock(Individual::class);
11183c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
112cb7a42eaSGreg Roach
1135e933c21SGreg Roach        self::assertSame(
1148939e2c2SGreg Roach            ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"],
115cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
116323788f4SGreg Roach        );
117323788f4SGreg Roach    }
118323788f4SGreg Roach
119323788f4SGreg Roach    /**
120323788f4SGreg Roach     * Test new parent names
121323788f4SGreg Roach     */
1229b802b22SGreg Roach    public function testNewParentNames(): void
123c1010edaSGreg Roach    {
124*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
12583c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
126323788f4SGreg Roach
127*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
12883c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
129323788f4SGreg Roach
1305e933c21SGreg Roach        self::assertSame(
1318939e2c2SGreg Roach            ["1 NAME // /Garcia/\n2 TYPE BIRTH\n2 SURN Garcia"],
132cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
133cb7a42eaSGreg Roach        );
134cb7a42eaSGreg Roach        self::assertSame(
1358939e2c2SGreg Roach            ["1 NAME // /Iglesias/\n2 TYPE BIRTH\n2 SURN Iglesias"],
136cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
137cb7a42eaSGreg Roach        );
138cb7a42eaSGreg Roach
139cb7a42eaSGreg Roach        self::assertSame(
1408939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
141cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
142323788f4SGreg Roach        );
143323788f4SGreg Roach    }
144323788f4SGreg Roach
145323788f4SGreg Roach    /**
146323788f4SGreg Roach     * Test new spouse names
147323788f4SGreg Roach     */
1489b802b22SGreg Roach    public function testNewSpouseNames(): void
149c1010edaSGreg Roach    {
150*62ff2f18SGreg Roach        $fact = $this->createMock(Fact::class);
15183c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
152cb7a42eaSGreg Roach
153*62ff2f18SGreg Roach        $individual = $this->createMock(Individual::class);
15483c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
155cb7a42eaSGreg Roach
1565e933c21SGreg Roach        self::assertSame(
1578939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
158cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
159cb7a42eaSGreg Roach        );
160cb7a42eaSGreg Roach
161cb7a42eaSGreg Roach        self::assertSame(
1628939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
163cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
164cb7a42eaSGreg Roach        );
165cb7a42eaSGreg Roach
166cb7a42eaSGreg Roach        self::assertSame(
1678939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
168cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
169323788f4SGreg Roach        );
170323788f4SGreg Roach    }
171323788f4SGreg Roach}
172