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