xref: /webtrees/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php (revision 9d74ed0ab3ae61aa8ae07578e026f14020844ce9)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\SurnameTradition;
21
22use Fisharebest\Webtrees\Fact;
23use Fisharebest\Webtrees\Individual;
24use Fisharebest\Webtrees\TestCase;
25use Illuminate\Support\Collection;
26use PHPUnit\Framework\Attributes\CoversClass;
27
28#[CoversClass(DefaultSurnameTradition::class)]
29class DefaultSurnameTraditionTest extends TestCase
30{
31    private SurnameTraditionInterface $surname_tradition;
32
33    /**
34     * Test whether surnames are used
35     */
36    public function testSurnames(): void
37    {
38        self::assertSame('//', $this->surname_tradition->defaultName());
39    }
40
41    /**
42     * Test new child names
43     */
44    public function testNewChildNames(): void
45    {
46        $father_fact = $this->createMock(Fact::class);
47        $father_fact->method('value')->willReturn('Chris /White/');
48
49        $father = $this->createMock(Individual::class);
50        $father->method('facts')->willReturn(new Collection([$father]));
51
52        $mother_fact = $this->createMock(Fact::class);
53        $mother_fact->method('value')->willReturn('Chris /White/');
54
55        $mother = $this->createMock(Individual::class);
56        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
57
58        self::assertSame(
59            ["1 NAME //\n2 TYPE BIRTH"],
60            $this->surname_tradition->newChildNames($father, $mother, 'M')
61        );
62
63        self::assertSame(
64            ["1 NAME //\n2 TYPE BIRTH"],
65            $this->surname_tradition->newChildNames($father, $mother, 'F')
66        );
67
68        self::assertSame(
69            ["1 NAME //\n2 TYPE BIRTH"],
70            $this->surname_tradition->newChildNames($father, $mother, 'U')
71        );
72    }
73
74    /**
75     * Test new parent names
76     */
77    public function testNewParentNames(): void
78    {
79        $fact = $this->createMock(Fact::class);
80        $fact->method('value')->willReturn('Chris /White/');
81
82        $individual = $this->createMock(Individual::class);
83        $individual->method('facts')->willReturn(new Collection([$fact]));
84
85        self::assertSame(
86            ["1 NAME //\n2 TYPE BIRTH"],
87            $this->surname_tradition->newParentNames($individual, 'M')
88        );
89
90        self::assertSame(
91            ["1 NAME //\n2 TYPE BIRTH"],
92            $this->surname_tradition->newParentNames($individual, 'F')
93        );
94
95        self::assertSame(
96            ["1 NAME //\n2 TYPE BIRTH"],
97            $this->surname_tradition->newParentNames($individual, 'U')
98        );
99    }
100
101    /**
102     * Test new spouse names
103     */
104    public function testNewSpouseNames(): void
105    {
106        $fact = $this->createMock(Fact::class);
107        $fact->method('value')->willReturn('Chris /White/');
108
109        $individual = $this->createMock(Individual::class);
110        $individual->method('facts')->willReturn(new Collection([$fact]));
111
112        self::assertSame(
113            ["1 NAME //\n2 TYPE BIRTH"],
114            $this->surname_tradition->newSpouseNames($individual, 'M')
115        );
116
117        self::assertSame(
118            ["1 NAME //\n2 TYPE BIRTH"],
119            $this->surname_tradition->newSpouseNames($individual, 'F')
120        );
121
122        self::assertSame(
123            ["1 NAME //\n2 TYPE BIRTH"],
124            $this->surname_tradition->newSpouseNames($individual, 'U')
125        );
126    }
127
128    /**
129     * Prepare the environment for these tests
130     */
131    protected function setUp(): void
132    {
133        parent::setUp();
134
135        $this->surname_tradition = new DefaultSurnameTradition();
136    }
137}
138