xref: /webtrees/tests/app/SurnameTradition/DefaultSurnameTraditionTest.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(DefaultSurnameTradition::class)]
303cfcc809SGreg Roachclass DefaultSurnameTraditionTest 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('Chris /White/');
49323788f4SGreg Roach
50cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
5183c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father]));
52323788f4SGreg Roach
53cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
5483c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Chris /White/');
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 //\n2 TYPE BIRTH"],
61cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
62cb7a42eaSGreg Roach        );
63cb7a42eaSGreg Roach
64cb7a42eaSGreg Roach        self::assertSame(
658939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
66cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
67cb7a42eaSGreg Roach        );
68cb7a42eaSGreg Roach
69cb7a42eaSGreg Roach        self::assertSame(
708939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
71cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
72323788f4SGreg Roach        );
73323788f4SGreg Roach    }
74323788f4SGreg Roach
75323788f4SGreg Roach    /**
76323788f4SGreg Roach     * Test new parent names
77323788f4SGreg Roach     */
789b802b22SGreg Roach    public function testNewParentNames(): void
79c1010edaSGreg Roach    {
80cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
8183c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
82323788f4SGreg Roach
83cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
8483c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
85323788f4SGreg Roach
865e933c21SGreg Roach        self::assertSame(
878939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
88cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
89cb7a42eaSGreg Roach        );
90cb7a42eaSGreg Roach
91cb7a42eaSGreg Roach        self::assertSame(
928939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
93cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
94cb7a42eaSGreg Roach        );
95cb7a42eaSGreg Roach
96cb7a42eaSGreg Roach        self::assertSame(
978939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
98cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
99323788f4SGreg Roach        );
100323788f4SGreg Roach    }
101323788f4SGreg Roach
102323788f4SGreg Roach    /**
103323788f4SGreg Roach     * Test new spouse names
104323788f4SGreg Roach     */
1059b802b22SGreg Roach    public function testNewSpouseNames(): void
106c1010edaSGreg Roach    {
107cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
10883c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
109cb7a42eaSGreg Roach
110cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
11183c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
112cb7a42eaSGreg Roach
1135e933c21SGreg Roach        self::assertSame(
1148939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
115cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
116323788f4SGreg Roach        );
117cb7a42eaSGreg Roach
118cb7a42eaSGreg Roach        self::assertSame(
1198939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
120cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
121cb7a42eaSGreg Roach        );
122cb7a42eaSGreg Roach
123cb7a42eaSGreg Roach        self::assertSame(
1248939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
125cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
126cb7a42eaSGreg Roach        );
127cb7a42eaSGreg Roach    }
128cb7a42eaSGreg Roach
129cb7a42eaSGreg Roach    /**
130cb7a42eaSGreg Roach     * Prepare the environment for these tests
131cb7a42eaSGreg Roach     */
132cb7a42eaSGreg Roach    protected function setUp(): void
133cb7a42eaSGreg Roach    {
134cb7a42eaSGreg Roach        parent::setUp();
135cb7a42eaSGreg Roach
136cb7a42eaSGreg Roach        $this->surname_tradition = new DefaultSurnameTradition();
137323788f4SGreg Roach    }
138323788f4SGreg Roach}
139