xref: /webtrees/tests/app/SurnameTradition/DefaultSurnameTraditionTest.php (revision 8939e2c24ff4346b8c6b9f3f822a733db666d588)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 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;
263cfcc809SGreg Roach
27323788f4SGreg Roach/**
2817d74f3aSGreg Roach * Test harness for the class DefaultSurnameTradition
29323788f4SGreg Roach */
303cfcc809SGreg Roachclass DefaultSurnameTraditionTest extends TestCase
31c1010edaSGreg Roach{
32c4943cffSGreg Roach    private SurnameTraditionInterface $surname_tradition;
33323788f4SGreg Roach
34323788f4SGreg Roach    /**
35c1ec7145SGreg Roach     * Test whether surnames are used
3617d74f3aSGreg Roach     *
3715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
3852348eb8SGreg Roach     *
3952348eb8SGreg Roach     * @return void
40c1ec7145SGreg Roach     */
419b802b22SGreg Roach    public function testSurnames(): void
42c1010edaSGreg Roach    {
43a171b6a5SGreg Roach        self::assertSame('//', $this->surname_tradition->defaultName());
44c1ec7145SGreg Roach    }
45c1ec7145SGreg Roach
46c1ec7145SGreg Roach    /**
47323788f4SGreg Roach     * Test new child names
4817d74f3aSGreg Roach     *
4915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
5052348eb8SGreg Roach     *
5152348eb8SGreg Roach     * @return void
52323788f4SGreg Roach     */
539b802b22SGreg Roach    public function testNewChildNames(): void
54c1010edaSGreg Roach    {
55cb7a42eaSGreg Roach        $father_fact = $this->createStub(Fact::class);
5683c91e47SGreg Roach        $father_fact->method('value')->willReturn('Chris /White/');
57323788f4SGreg Roach
58cb7a42eaSGreg Roach        $father = $this->createStub(Individual::class);
5983c91e47SGreg Roach        $father->method('facts')->willReturn(new Collection([$father]));
60323788f4SGreg Roach
61cb7a42eaSGreg Roach        $mother_fact = $this->createStub(Fact::class);
6283c91e47SGreg Roach        $mother_fact->method('value')->willReturn('Chris /White/');
63cb7a42eaSGreg Roach
64cb7a42eaSGreg Roach        $mother = $this->createStub(Individual::class);
6583c91e47SGreg Roach        $mother->method('facts')->willReturn(new Collection([$mother_fact]));
66cb7a42eaSGreg Roach
675e933c21SGreg Roach        self::assertSame(
68*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
69cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'M')
70cb7a42eaSGreg Roach        );
71cb7a42eaSGreg Roach
72cb7a42eaSGreg Roach        self::assertSame(
73*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
74cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'F')
75cb7a42eaSGreg Roach        );
76cb7a42eaSGreg Roach
77cb7a42eaSGreg Roach        self::assertSame(
78*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
79cb7a42eaSGreg Roach            $this->surname_tradition->newChildNames($father, $mother, 'U')
80323788f4SGreg Roach        );
81323788f4SGreg Roach    }
82323788f4SGreg Roach
83323788f4SGreg Roach    /**
84323788f4SGreg Roach     * Test new parent names
8517d74f3aSGreg Roach     *
8615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
8752348eb8SGreg Roach     *
8852348eb8SGreg Roach     * @return void
89323788f4SGreg Roach     */
909b802b22SGreg Roach    public function testNewParentNames(): void
91c1010edaSGreg Roach    {
92cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
9383c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
94323788f4SGreg Roach
95cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
9683c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
97323788f4SGreg Roach
985e933c21SGreg Roach        self::assertSame(
99*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
100cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'M')
101cb7a42eaSGreg Roach        );
102cb7a42eaSGreg Roach
103cb7a42eaSGreg Roach        self::assertSame(
104*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
105cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'F')
106cb7a42eaSGreg Roach        );
107cb7a42eaSGreg Roach
108cb7a42eaSGreg Roach        self::assertSame(
109*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
110cb7a42eaSGreg Roach            $this->surname_tradition->newParentNames($individual, 'U')
111323788f4SGreg Roach        );
112323788f4SGreg Roach    }
113323788f4SGreg Roach
114323788f4SGreg Roach    /**
115323788f4SGreg Roach     * Test new spouse names
11617d74f3aSGreg Roach     *
11715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\SurnameTradition\DefaultSurnameTradition
11852348eb8SGreg Roach     *
11952348eb8SGreg Roach     * @return void
120323788f4SGreg Roach     */
1219b802b22SGreg Roach    public function testNewSpouseNames(): void
122c1010edaSGreg Roach    {
123cb7a42eaSGreg Roach        $fact = $this->createStub(Fact::class);
12483c91e47SGreg Roach        $fact->method('value')->willReturn('Chris /White/');
125cb7a42eaSGreg Roach
126cb7a42eaSGreg Roach        $individual = $this->createStub(Individual::class);
12783c91e47SGreg Roach        $individual->method('facts')->willReturn(new Collection([$fact]));
128cb7a42eaSGreg Roach
1295e933c21SGreg Roach        self::assertSame(
130*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
131cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'M')
132323788f4SGreg Roach        );
133cb7a42eaSGreg Roach
134cb7a42eaSGreg Roach        self::assertSame(
135*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
136cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'F')
137cb7a42eaSGreg Roach        );
138cb7a42eaSGreg Roach
139cb7a42eaSGreg Roach        self::assertSame(
140*8939e2c2SGreg Roach            ["1 NAME //\n2 TYPE BIRTH"],
141cb7a42eaSGreg Roach            $this->surname_tradition->newSpouseNames($individual, 'U')
142cb7a42eaSGreg Roach        );
143cb7a42eaSGreg Roach    }
144cb7a42eaSGreg Roach
145cb7a42eaSGreg Roach    /**
146cb7a42eaSGreg Roach     * Prepare the environment for these tests
147cb7a42eaSGreg Roach     *
148cb7a42eaSGreg Roach     * @return void
149cb7a42eaSGreg Roach     */
150cb7a42eaSGreg Roach    protected function setUp(): void
151cb7a42eaSGreg Roach    {
152cb7a42eaSGreg Roach        parent::setUp();
153cb7a42eaSGreg Roach
154cb7a42eaSGreg Roach        $this->surname_tradition = new DefaultSurnameTradition();
155323788f4SGreg Roach    }
156323788f4SGreg Roach}
157