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; 26*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 273cfcc809SGreg Roach 28*202c018bSGreg Roach 29*202c018bSGreg Roach#[CoversClass(IcelandicSurnameTradition::class)] 303cfcc809SGreg Roachclass IcelandicSurnameTraditionTest extends TestCase 31c1010edaSGreg Roach{ 32c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 33323788f4SGreg Roach 34323788f4SGreg Roach /** 35c1ec7145SGreg Roach * Test whether surnames are used 36c1ec7145SGreg Roach */ 379b802b22SGreg Roach public function testSurnames(): void 38c1010edaSGreg Roach { 39a171b6a5SGreg Roach self::assertSame('', $this->surname_tradition->defaultName()); 40c1ec7145SGreg Roach } 41c1ec7145SGreg Roach 42c1ec7145SGreg Roach /** 43323788f4SGreg Roach * Test new son names 44323788f4SGreg Roach */ 459b802b22SGreg Roach public function testNewSonNames(): void 46c1010edaSGreg Roach { 47cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 4883c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 49cb7a42eaSGreg Roach 50cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 5183c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 52cb7a42eaSGreg Roach 53cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 5483c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 55cb7a42eaSGreg Roach 56cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 5783c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 58cb7a42eaSGreg Roach 595e933c21SGreg Roach self::assertSame( 608939e2c2SGreg Roach ["1 NAME Jonsson\n2 TYPE BIRTH\n2 GIVN Jonsson"], 61cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 62323788f4SGreg Roach ); 63323788f4SGreg Roach } 64323788f4SGreg Roach 65323788f4SGreg Roach /** 66323788f4SGreg Roach * Test new daughter names 67323788f4SGreg Roach */ 689b802b22SGreg Roach public function testNewDaughterNames(): void 69c1010edaSGreg Roach { 70cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 7183c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 72cb7a42eaSGreg Roach 73cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 7483c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 75cb7a42eaSGreg Roach 76cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 7783c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 78cb7a42eaSGreg Roach 79cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 8083c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 81cb7a42eaSGreg Roach 825e933c21SGreg Roach self::assertSame( 838939e2c2SGreg Roach ["1 NAME Jonsdottir\n2 TYPE BIRTH\n2 GIVN Jonsdottir"], 84cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 85323788f4SGreg Roach ); 86323788f4SGreg Roach } 87323788f4SGreg Roach 88323788f4SGreg Roach /** 89323788f4SGreg Roach * Test new child names 90323788f4SGreg Roach */ 919b802b22SGreg Roach public function testNewChildNames(): void 92c1010edaSGreg Roach { 93cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 9483c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 95cb7a42eaSGreg Roach 96cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 9783c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 98cb7a42eaSGreg Roach 99cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 10083c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 101cb7a42eaSGreg Roach 102cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 10383c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 104cb7a42eaSGreg Roach 1055e933c21SGreg Roach self::assertSame( 1068939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 107cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 108323788f4SGreg Roach ); 109323788f4SGreg Roach } 110323788f4SGreg Roach 111323788f4SGreg Roach /** 112323788f4SGreg Roach * Test new father names 113323788f4SGreg Roach */ 1149b802b22SGreg Roach public function testNewFatherNames(): void 115c1010edaSGreg Roach { 116cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 11783c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 118cb7a42eaSGreg Roach 119cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 12083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 121cb7a42eaSGreg Roach 1225e933c21SGreg Roach self::assertSame( 1238939e2c2SGreg Roach ["1 NAME Einar\n2 TYPE BIRTH\n2 GIVN Einar"], 124cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 125323788f4SGreg Roach ); 126323788f4SGreg Roach } 127323788f4SGreg Roach 128323788f4SGreg Roach /** 129323788f4SGreg Roach * Test new mother names 130323788f4SGreg Roach */ 1319b802b22SGreg Roach public function testNewMotherNames(): void 132c1010edaSGreg Roach { 133cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 13483c91e47SGreg Roach $fact->method('value')->willReturn('Jon Evasdottir'); 135cb7a42eaSGreg Roach 136cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 13783c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 138cb7a42eaSGreg Roach 1395e933c21SGreg Roach self::assertSame( 1408939e2c2SGreg Roach ["1 NAME Eva\n2 TYPE BIRTH\n2 GIVN Eva"], 141cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 142323788f4SGreg Roach ); 143323788f4SGreg Roach } 144323788f4SGreg Roach 145323788f4SGreg Roach /** 146323788f4SGreg Roach * Test new parent names 147323788f4SGreg Roach */ 1489b802b22SGreg Roach public function testNewParentNames(): void 149c1010edaSGreg Roach { 150cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 15183c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 152323788f4SGreg Roach 153cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 15483c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 155323788f4SGreg Roach 1565e933c21SGreg Roach self::assertSame( 1578939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 158cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 159323788f4SGreg Roach ); 160323788f4SGreg Roach } 161323788f4SGreg Roach 162323788f4SGreg Roach /** 163323788f4SGreg Roach * Test new spouse names 164323788f4SGreg Roach */ 1659b802b22SGreg Roach public function testNewSpouseNames(): void 166c1010edaSGreg Roach { 167cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 16883c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 169cb7a42eaSGreg Roach 170cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 17183c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 172cb7a42eaSGreg Roach 1735e933c21SGreg Roach self::assertSame( 1748939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 175cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 176323788f4SGreg Roach ); 177cb7a42eaSGreg Roach 178cb7a42eaSGreg Roach self::assertSame( 1798939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 180cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 181cb7a42eaSGreg Roach ); 182cb7a42eaSGreg Roach 183cb7a42eaSGreg Roach self::assertSame( 1848939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 185cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 186cb7a42eaSGreg Roach ); 187cb7a42eaSGreg Roach } 188cb7a42eaSGreg Roach 189cb7a42eaSGreg Roach /** 190cb7a42eaSGreg Roach * Prepare the environment for these tests 191cb7a42eaSGreg Roach */ 192cb7a42eaSGreg Roach protected function setUp(): void 193cb7a42eaSGreg Roach { 194cb7a42eaSGreg Roach parent::setUp(); 195cb7a42eaSGreg Roach 196cb7a42eaSGreg Roach $this->surname_tradition = new IcelandicSurnameTradition(); 197323788f4SGreg Roach } 198323788f4SGreg Roach} 199