xref: /webtrees/tests/app/SurnameTradition/SpanishSurnameTraditionTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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;
26*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
273cfcc809SGreg Roach
28*202c018bSGreg Roach
29*202c018bSGreg Roach#[CoversClass(SpanishSurnameTradition::class)]
303cfcc809SGreg Roachclass SpanishSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35c1ec7145SGreg Roach     * Test whether surnames are used
36c1ec7145SGreg Roach     */
379b802b22SGreg Roach    public function testSurnames(): void
38c1010edaSGreg Roach    {
39a171b6a5SGreg Roach        self::assertSame('// //', $this->surname_tradition->defaultName());
40c1ec7145SGreg Roach    }
41c1ec7145SGreg Roach
42c1ec7145SGreg Roach    /**
43323788f4SGreg Roach     * Test new child names
44323788f4SGreg Roach     */
459b802b22SGreg Roach    public function testNewChildNames(): void
46c1010edaSGreg Roach    {
47cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
4883c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
49cb7a42eaSGreg Roach
50cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
5183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
52cb7a42eaSGreg Roach
53cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
5483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/');
55cb7a42eaSGreg Roach
56cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
5783c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
58cb7a42eaSGreg Roach
595e933c21SGreg Roach        self::assertSame(
608939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
61cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
62cb7a42eaSGreg Roach        );
63cb7a42eaSGreg Roach
64cb7a42eaSGreg Roach        self::assertSame(
658939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
66cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
67cb7a42eaSGreg Roach        );
68cb7a42eaSGreg Roach
69cb7a42eaSGreg Roach        self::assertSame(
708939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
71cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
72323788f4SGreg Roach        );
73323788f4SGreg Roach    }
74323788f4SGreg Roach
75323788f4SGreg Roach    /**
76323788f4SGreg Roach     * Test new child names
77323788f4SGreg Roach     */
789b802b22SGreg Roach    public function testNewChildNamesWithNoParentsNames(): void
79c1010edaSGreg Roach    {
805e933c21SGreg Roach        self::assertSame(
818939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
82cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames(null, null, 'U')
831677a03aSGreg Roach        );
841677a03aSGreg Roach    }
851677a03aSGreg Roach
861677a03aSGreg Roach    /**
871677a03aSGreg Roach     * Test new child names
881677a03aSGreg Roach     */
89cb7a42eaSGreg Roach    public function testNewChildNamesCompound(): void
90c1010edaSGreg Roach    {
91cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
9283c91e47SGreg Roach        $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/');
93323788f4SGreg Roach
94cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
9583c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father_fact]));
96323788f4SGreg Roach
97cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
9883c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/');
99cb7a42eaSGreg Roach
100cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
10183c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
102cb7a42eaSGreg Roach
1035e933c21SGreg Roach        self::assertSame(
1048939e2c2SGreg Roach            ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"],
105cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
106323788f4SGreg Roach        );
107323788f4SGreg Roach    }
108323788f4SGreg Roach
109323788f4SGreg Roach    /**
110323788f4SGreg Roach     * Test new parent names
111323788f4SGreg Roach     */
1129b802b22SGreg Roach    public function testNewParentNames(): void
113c1010edaSGreg Roach    {
114cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
11583c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
116323788f4SGreg Roach
117cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
11883c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
119323788f4SGreg Roach
1205e933c21SGreg Roach        self::assertSame(
1218939e2c2SGreg Roach            ["1 NAME /Garcia/ //\n2 TYPE BIRTH\n2 SURN Garcia"],
122cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
123cb7a42eaSGreg Roach        );
124cb7a42eaSGreg Roach
125cb7a42eaSGreg Roach        self::assertSame(
1268939e2c2SGreg Roach            ["1 NAME /Iglesias/ //\n2 TYPE BIRTH\n2 SURN Iglesias"],
127cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
128cb7a42eaSGreg Roach        );
129cb7a42eaSGreg Roach
130cb7a42eaSGreg Roach        self::assertSame(
1318939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
132cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
133323788f4SGreg Roach        );
134323788f4SGreg Roach    }
135323788f4SGreg Roach
136323788f4SGreg Roach    /**
137323788f4SGreg Roach     * Test new spouse names
138323788f4SGreg Roach     */
1399b802b22SGreg Roach    public function testNewSpouseNames(): void
140c1010edaSGreg Roach    {
141cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
14283c91e47SGreg Roach        $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/');
143cb7a42eaSGreg Roach
144cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
14583c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
146cb7a42eaSGreg Roach
1475e933c21SGreg Roach        self::assertSame(
1488939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
149cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
150323788f4SGreg Roach        );
151cb7a42eaSGreg Roach
152cb7a42eaSGreg Roach        self::assertSame(
1538939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
154cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
155cb7a42eaSGreg Roach        );
156cb7a42eaSGreg Roach
157cb7a42eaSGreg Roach        self::assertSame(
1588939e2c2SGreg Roach            ["1 NAME // //\n2 TYPE BIRTH"],
159cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
160cb7a42eaSGreg Roach        );
161cb7a42eaSGreg Roach    }
162cb7a42eaSGreg Roach
163cb7a42eaSGreg Roach    /**
164cb7a42eaSGreg Roach     * Prepare the environment for these tests
165cb7a42eaSGreg Roach     */
166cb7a42eaSGreg Roach    protected function setUp(): void
167cb7a42eaSGreg Roach    {
168cb7a42eaSGreg Roach        parent::setUp();
169cb7a42eaSGreg Roach
170cb7a42eaSGreg Roach        $this->surname_tradition = new SpanishSurnameTradition();
171323788f4SGreg Roach    }
172323788f4SGreg Roach}
173