1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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; 26202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 273cfcc809SGreg Roach 28202c018bSGreg Roach#[CoversClass(DefaultSurnameTradition::class)] 293cfcc809SGreg Roachclass DefaultSurnameTraditionTest extends TestCase 30c1010edaSGreg Roach{ 31c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 32323788f4SGreg Roach 33323788f4SGreg Roach /** 34c1ec7145SGreg Roach * Test whether surnames are used 35c1ec7145SGreg Roach */ 369b802b22SGreg Roach public function testSurnames(): void 37c1010edaSGreg Roach { 38a171b6a5SGreg Roach self::assertSame('//', $this->surname_tradition->defaultName()); 39c1ec7145SGreg Roach } 40c1ec7145SGreg Roach 41c1ec7145SGreg Roach /** 42323788f4SGreg Roach * Test new child names 43323788f4SGreg Roach */ 449b802b22SGreg Roach public function testNewChildNames(): void 45c1010edaSGreg Roach { 46*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 4783c91e47SGreg Roach $father_fact->method('value')->willReturn('Chris /White/'); 48323788f4SGreg Roach 49*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 5083c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father])); 51323788f4SGreg Roach 52*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 5383c91e47SGreg Roach $mother_fact->method('value')->willReturn('Chris /White/'); 54cb7a42eaSGreg Roach 55*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 5683c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 57cb7a42eaSGreg Roach 585e933c21SGreg Roach self::assertSame( 598939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 60cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 61cb7a42eaSGreg Roach ); 62cb7a42eaSGreg Roach 63cb7a42eaSGreg Roach self::assertSame( 648939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 65cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 66cb7a42eaSGreg Roach ); 67cb7a42eaSGreg Roach 68cb7a42eaSGreg Roach self::assertSame( 698939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 70cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 71323788f4SGreg Roach ); 72323788f4SGreg Roach } 73323788f4SGreg Roach 74323788f4SGreg Roach /** 75323788f4SGreg Roach * Test new parent names 76323788f4SGreg Roach */ 779b802b22SGreg Roach public function testNewParentNames(): void 78c1010edaSGreg Roach { 79*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 8083c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 81323788f4SGreg Roach 82*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 8383c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 84323788f4SGreg Roach 855e933c21SGreg Roach self::assertSame( 868939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 87cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 88cb7a42eaSGreg Roach ); 89cb7a42eaSGreg Roach 90cb7a42eaSGreg Roach self::assertSame( 918939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 92cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 93cb7a42eaSGreg Roach ); 94cb7a42eaSGreg Roach 95cb7a42eaSGreg Roach self::assertSame( 968939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 97cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 98323788f4SGreg Roach ); 99323788f4SGreg Roach } 100323788f4SGreg Roach 101323788f4SGreg Roach /** 102323788f4SGreg Roach * Test new spouse names 103323788f4SGreg Roach */ 1049b802b22SGreg Roach public function testNewSpouseNames(): void 105c1010edaSGreg Roach { 106*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 10783c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 108cb7a42eaSGreg Roach 109*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 11083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 111cb7a42eaSGreg Roach 1125e933c21SGreg Roach self::assertSame( 1138939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 114cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 115323788f4SGreg Roach ); 116cb7a42eaSGreg Roach 117cb7a42eaSGreg Roach self::assertSame( 1188939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 119cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 120cb7a42eaSGreg Roach ); 121cb7a42eaSGreg Roach 122cb7a42eaSGreg Roach self::assertSame( 1238939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 124cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 125cb7a42eaSGreg Roach ); 126cb7a42eaSGreg Roach } 127cb7a42eaSGreg Roach 128cb7a42eaSGreg Roach /** 129cb7a42eaSGreg Roach * Prepare the environment for these tests 130cb7a42eaSGreg Roach */ 131cb7a42eaSGreg Roach protected function setUp(): void 132cb7a42eaSGreg Roach { 133cb7a42eaSGreg Roach parent::setUp(); 134cb7a42eaSGreg Roach 135cb7a42eaSGreg Roach $this->surname_tradition = new DefaultSurnameTradition(); 136323788f4SGreg Roach } 137323788f4SGreg Roach} 138