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(IcelandicSurnameTradition::class)] 293cfcc809SGreg Roachclass IcelandicSurnameTraditionTest 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 son names 43323788f4SGreg Roach */ 449b802b22SGreg Roach public function testNewSonNames(): void 45c1010edaSGreg Roach { 46*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 4783c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 48cb7a42eaSGreg Roach 49*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 5083c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 51cb7a42eaSGreg Roach 52*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 5383c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 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 Jonsson\n2 TYPE BIRTH\n2 GIVN Jonsson"], 60cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 61323788f4SGreg Roach ); 62323788f4SGreg Roach } 63323788f4SGreg Roach 64323788f4SGreg Roach /** 65323788f4SGreg Roach * Test new daughter names 66323788f4SGreg Roach */ 679b802b22SGreg Roach public function testNewDaughterNames(): void 68c1010edaSGreg Roach { 69*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 7083c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 71cb7a42eaSGreg Roach 72*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 7383c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 74cb7a42eaSGreg Roach 75*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 7683c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 77cb7a42eaSGreg Roach 78*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 7983c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 80cb7a42eaSGreg Roach 815e933c21SGreg Roach self::assertSame( 828939e2c2SGreg Roach ["1 NAME Jonsdottir\n2 TYPE BIRTH\n2 GIVN Jonsdottir"], 83cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 84323788f4SGreg Roach ); 85323788f4SGreg Roach } 86323788f4SGreg Roach 87323788f4SGreg Roach /** 88323788f4SGreg Roach * Test new child names 89323788f4SGreg Roach */ 909b802b22SGreg Roach public function testNewChildNames(): void 91c1010edaSGreg Roach { 92*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 9383c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 94cb7a42eaSGreg Roach 95*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 9683c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 97cb7a42eaSGreg Roach 98*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 9983c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 100cb7a42eaSGreg Roach 101*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 10283c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 103cb7a42eaSGreg Roach 1045e933c21SGreg Roach self::assertSame( 1058939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 106cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 107323788f4SGreg Roach ); 108323788f4SGreg Roach } 109323788f4SGreg Roach 110323788f4SGreg Roach /** 111323788f4SGreg Roach * Test new father names 112323788f4SGreg Roach */ 1139b802b22SGreg Roach public function testNewFatherNames(): void 114c1010edaSGreg Roach { 115*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 11683c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 117cb7a42eaSGreg Roach 118*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 11983c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 120cb7a42eaSGreg Roach 1215e933c21SGreg Roach self::assertSame( 1228939e2c2SGreg Roach ["1 NAME Einar\n2 TYPE BIRTH\n2 GIVN Einar"], 123cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 124323788f4SGreg Roach ); 125323788f4SGreg Roach } 126323788f4SGreg Roach 127323788f4SGreg Roach /** 128323788f4SGreg Roach * Test new mother names 129323788f4SGreg Roach */ 1309b802b22SGreg Roach public function testNewMotherNames(): void 131c1010edaSGreg Roach { 132*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 13383c91e47SGreg Roach $fact->method('value')->willReturn('Jon Evasdottir'); 134cb7a42eaSGreg Roach 135*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 13683c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 137cb7a42eaSGreg Roach 1385e933c21SGreg Roach self::assertSame( 1398939e2c2SGreg Roach ["1 NAME Eva\n2 TYPE BIRTH\n2 GIVN Eva"], 140cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 141323788f4SGreg Roach ); 142323788f4SGreg Roach } 143323788f4SGreg Roach 144323788f4SGreg Roach /** 145323788f4SGreg Roach * Test new parent names 146323788f4SGreg Roach */ 1479b802b22SGreg Roach public function testNewParentNames(): void 148c1010edaSGreg Roach { 149*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 15083c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 151323788f4SGreg Roach 152*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 15383c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 154323788f4SGreg Roach 1555e933c21SGreg Roach self::assertSame( 1568939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 157cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 158323788f4SGreg Roach ); 159323788f4SGreg Roach } 160323788f4SGreg Roach 161323788f4SGreg Roach /** 162323788f4SGreg Roach * Test new spouse names 163323788f4SGreg Roach */ 1649b802b22SGreg Roach public function testNewSpouseNames(): void 165c1010edaSGreg Roach { 166*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 16783c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 168cb7a42eaSGreg Roach 169*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 17083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 171cb7a42eaSGreg Roach 1725e933c21SGreg Roach self::assertSame( 1738939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 174cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 175323788f4SGreg Roach ); 176cb7a42eaSGreg Roach 177cb7a42eaSGreg Roach self::assertSame( 1788939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 179cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 180cb7a42eaSGreg Roach ); 181cb7a42eaSGreg Roach 182cb7a42eaSGreg Roach self::assertSame( 1838939e2c2SGreg Roach ["1 NAME\n2 TYPE BIRTH"], 184cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 185cb7a42eaSGreg Roach ); 186cb7a42eaSGreg Roach } 187cb7a42eaSGreg Roach 188cb7a42eaSGreg Roach /** 189cb7a42eaSGreg Roach * Prepare the environment for these tests 190cb7a42eaSGreg Roach */ 191cb7a42eaSGreg Roach protected function setUp(): void 192cb7a42eaSGreg Roach { 193cb7a42eaSGreg Roach parent::setUp(); 194cb7a42eaSGreg Roach 195cb7a42eaSGreg Roach $this->surname_tradition = new IcelandicSurnameTradition(); 196323788f4SGreg Roach } 197323788f4SGreg Roach} 198