xref: /webtrees/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php (revision b1331e2ee95636c32070e430b0bcc725662cb8b9)
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;
26
27/**
28 * Test harness for the class DefaultSurnameTradition
29 */
30class DefaultSurnameTraditionTest extends TestCase
31{
32    private SurnameTraditionInterface $surname_tradition;
33
34    /**
35     * Test whether surnames are used
36     *
37     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
38     */
39    public function testSurnames(): void
40    {
41        self::assertSame('//', $this->surname_tradition->defaultName());
42    }
43
44    /**
45     * Test new child names
46     *
47     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
48     */
49    public function testNewChildNames(): void
50    {
51        $father_fact = $this->createStub(Fact::class);
52        $father_fact->method('value')->willReturn('Chris /White/');
53
54        $father = $this->createStub(Individual::class);
55        $father->method('facts')->willReturn(new Collection([$father]));
56
57        $mother_fact = $this->createStub(Fact::class);
58        $mother_fact->method('value')->willReturn('Chris /White/');
59
60        $mother = $this->createStub(Individual::class);
61        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
62
63        self::assertSame(
64            ["1 NAME //\n2 TYPE BIRTH"],
65            $this->surname_tradition->newChildNames($father, $mother, 'M')
66        );
67
68        self::assertSame(
69            ["1 NAME //\n2 TYPE BIRTH"],
70            $this->surname_tradition->newChildNames($father, $mother, 'F')
71        );
72
73        self::assertSame(
74            ["1 NAME //\n2 TYPE BIRTH"],
75            $this->surname_tradition->newChildNames($father, $mother, 'U')
76        );
77    }
78
79    /**
80     * Test new parent names
81     *
82     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
83     */
84    public function testNewParentNames(): void
85    {
86        $fact = $this->createStub(Fact::class);
87        $fact->method('value')->willReturn('Chris /White/');
88
89        $individual = $this->createStub(Individual::class);
90        $individual->method('facts')->willReturn(new Collection([$fact]));
91
92        self::assertSame(
93            ["1 NAME //\n2 TYPE BIRTH"],
94            $this->surname_tradition->newParentNames($individual, 'M')
95        );
96
97        self::assertSame(
98            ["1 NAME //\n2 TYPE BIRTH"],
99            $this->surname_tradition->newParentNames($individual, 'F')
100        );
101
102        self::assertSame(
103            ["1 NAME //\n2 TYPE BIRTH"],
104            $this->surname_tradition->newParentNames($individual, 'U')
105        );
106    }
107
108    /**
109     * Test new spouse names
110     *
111     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
112     */
113    public function testNewSpouseNames(): void
114    {
115        $fact = $this->createStub(Fact::class);
116        $fact->method('value')->willReturn('Chris /White/');
117
118        $individual = $this->createStub(Individual::class);
119        $individual->method('facts')->willReturn(new Collection([$fact]));
120
121        self::assertSame(
122            ["1 NAME //\n2 TYPE BIRTH"],
123            $this->surname_tradition->newSpouseNames($individual, 'M')
124        );
125
126        self::assertSame(
127            ["1 NAME //\n2 TYPE BIRTH"],
128            $this->surname_tradition->newSpouseNames($individual, 'F')
129        );
130
131        self::assertSame(
132            ["1 NAME //\n2 TYPE BIRTH"],
133            $this->surname_tradition->newSpouseNames($individual, 'U')
134        );
135    }
136
137    /**
138     * Prepare the environment for these tests
139     */
140    protected function setUp(): void
141    {
142        parent::setUp();
143
144        $this->surname_tradition = new DefaultSurnameTradition();
145    }
146}
147