xref: /webtrees/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php (revision 3340ecd27b8901a894bff51b7c40bfa2896a552b)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 married surnames are used
36     *
37     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
38     *
39     * @return void
40     */
41    public function testMarriedSurnames(): void
42    {
43        self::assertFalse($this->surname_tradition->hasMarriedNames());
44    }
45
46    /**
47     * Test whether surnames are used
48     *
49     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
50     *
51     * @return void
52     */
53    public function testSurnames(): void
54    {
55        self::assertTrue($this->surname_tradition->hasSurnames());
56    }
57
58    /**
59     * Test new child names
60     *
61     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
62     *
63     * @return void
64     */
65    public function testNewChildNames(): void
66    {
67        $father_fact = $this->createStub(Fact::class);
68        $father_fact->method('value')->willReturn('Chris /White/');
69
70        $father = $this->createStub(Individual::class);
71        $father->method('facts')->willReturn(new Collection([$father]));
72
73        $mother_fact = $this->createStub(Fact::class);
74        $mother_fact->method('value')->willReturn('Chris /White/');
75
76        $mother = $this->createStub(Individual::class);
77        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
78
79        self::assertSame(
80            ["1 NAME //\n2 TYPE birth"],
81            $this->surname_tradition->newChildNames($father, $mother, 'M')
82        );
83
84        self::assertSame(
85            ["1 NAME //\n2 TYPE birth"],
86            $this->surname_tradition->newChildNames($father, $mother, 'F')
87        );
88
89        self::assertSame(
90            ["1 NAME //\n2 TYPE birth"],
91            $this->surname_tradition->newChildNames($father, $mother, 'U')
92        );
93    }
94
95    /**
96     * Test new parent names
97     *
98     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
99     *
100     * @return void
101     */
102    public function testNewParentNames(): void
103    {
104        $fact = $this->createStub(Fact::class);
105        $fact->method('value')->willReturn('Chris /White/');
106
107        $individual = $this->createStub(Individual::class);
108        $individual->method('facts')->willReturn(new Collection([$fact]));
109
110        self::assertSame(
111            ["1 NAME //\n2 TYPE birth"],
112            $this->surname_tradition->newParentNames($individual, 'M')
113        );
114
115        self::assertSame(
116            ["1 NAME //\n2 TYPE birth"],
117            $this->surname_tradition->newParentNames($individual, 'F')
118        );
119
120        self::assertSame(
121            ["1 NAME //\n2 TYPE birth"],
122            $this->surname_tradition->newParentNames($individual, 'U')
123        );
124    }
125
126    /**
127     * Test new spouse names
128     *
129     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
130     *
131     * @return void
132     */
133    public function testNewSpouseNames(): void
134    {
135        $fact = $this->createStub(Fact::class);
136        $fact->method('value')->willReturn('Chris /White/');
137
138        $individual = $this->createStub(Individual::class);
139        $individual->method('facts')->willReturn(new Collection([$fact]));
140
141        self::assertSame(
142            ["1 NAME //\n2 TYPE birth"],
143            $this->surname_tradition->newSpouseNames($individual, 'M')
144        );
145
146        self::assertSame(
147            ["1 NAME //\n2 TYPE birth"],
148            $this->surname_tradition->newSpouseNames($individual, 'F')
149        );
150
151        self::assertSame(
152            ["1 NAME //\n2 TYPE birth"],
153            $this->surname_tradition->newSpouseNames($individual, 'U')
154        );
155    }
156
157    /**
158     * Prepare the environment for these tests
159     *
160     * @return void
161     */
162    protected function setUp(): void
163    {
164        parent::setUp();
165
166        $this->surname_tradition = new DefaultSurnameTradition();
167    }
168}
169