1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 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/** 28c4943cffSGreg Roach * Test harness for the class IcelandicSurnameTradition 29323788f4SGreg Roach */ 303cfcc809SGreg Roachclass IcelandicSurnameTraditionTest extends TestCase 31c1010edaSGreg Roach{ 32c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 33323788f4SGreg Roach 34323788f4SGreg Roach /** 35323788f4SGreg Roach * Test whether married surnames are used 3617d74f3aSGreg Roach * 3715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 3852348eb8SGreg Roach * 3952348eb8SGreg Roach * @return void 40323788f4SGreg Roach */ 419b802b22SGreg Roach public function testMarriedSurnames(): void 42c1010edaSGreg Roach { 435e933c21SGreg Roach self::assertFalse($this->surname_tradition->hasMarriedNames()); 44323788f4SGreg Roach } 45323788f4SGreg Roach 46323788f4SGreg Roach /** 47c1ec7145SGreg Roach * Test whether surnames are used 4817d74f3aSGreg Roach * 4915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 5052348eb8SGreg Roach * 5152348eb8SGreg Roach * @return void 52c1ec7145SGreg Roach */ 539b802b22SGreg Roach public function testSurnames(): void 54c1010edaSGreg Roach { 555e933c21SGreg Roach self::assertFalse($this->surname_tradition->hasSurnames()); 56c1ec7145SGreg Roach } 57c1ec7145SGreg Roach 58c1ec7145SGreg Roach /** 59323788f4SGreg Roach * Test new son names 6017d74f3aSGreg Roach * 6115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 6252348eb8SGreg Roach * 6352348eb8SGreg Roach * @return void 64323788f4SGreg Roach */ 659b802b22SGreg Roach public function testNewSonNames(): void 66c1010edaSGreg Roach { 67cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 68*83c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 69cb7a42eaSGreg Roach 70cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 71*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 72cb7a42eaSGreg Roach 73cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 74*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 75cb7a42eaSGreg Roach 76cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 77*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 78cb7a42eaSGreg Roach 795e933c21SGreg Roach self::assertSame( 80cb7a42eaSGreg Roach ["1 NAME Jonsson\n2 TYPE birth\n2 GIVN Jonsson"], 81cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 82323788f4SGreg Roach ); 83323788f4SGreg Roach } 84323788f4SGreg Roach 85323788f4SGreg Roach /** 86323788f4SGreg Roach * Test new daughter names 8717d74f3aSGreg Roach * 8815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 8952348eb8SGreg Roach * 9052348eb8SGreg Roach * @return void 91323788f4SGreg Roach */ 929b802b22SGreg Roach public function testNewDaughterNames(): void 93c1010edaSGreg Roach { 94cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 95*83c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 96cb7a42eaSGreg Roach 97cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 98*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 99cb7a42eaSGreg Roach 100cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 101*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 102cb7a42eaSGreg Roach 103cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 104*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 105cb7a42eaSGreg Roach 1065e933c21SGreg Roach self::assertSame( 107cb7a42eaSGreg Roach ["1 NAME Jonsdottir\n2 TYPE birth\n2 GIVN Jonsdottir"], 108cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 109323788f4SGreg Roach ); 110323788f4SGreg Roach } 111323788f4SGreg Roach 112323788f4SGreg Roach /** 113323788f4SGreg Roach * Test new child names 11417d74f3aSGreg Roach * 11515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 11652348eb8SGreg Roach * 11752348eb8SGreg Roach * @return void 118323788f4SGreg Roach */ 1199b802b22SGreg Roach public function testNewChildNames(): void 120c1010edaSGreg Roach { 121cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 122*83c91e47SGreg Roach $father_fact->method('value')->willReturn('Jon Einarsson'); 123cb7a42eaSGreg Roach 124cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 125*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 126cb7a42eaSGreg Roach 127cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 128*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 129cb7a42eaSGreg Roach 130cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 131*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 132cb7a42eaSGreg Roach 1335e933c21SGreg Roach self::assertSame( 134cb7a42eaSGreg Roach ["1 NAME\n2 TYPE birth"], 135cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 136323788f4SGreg Roach ); 137323788f4SGreg Roach } 138323788f4SGreg Roach 139323788f4SGreg Roach /** 140323788f4SGreg Roach * Test new father names 14117d74f3aSGreg Roach * 14215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 14352348eb8SGreg Roach * 14452348eb8SGreg Roach * @return void 145323788f4SGreg Roach */ 1469b802b22SGreg Roach public function testNewFatherNames(): void 147c1010edaSGreg Roach { 148cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 149*83c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 150cb7a42eaSGreg Roach 151cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 152*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 153cb7a42eaSGreg Roach 1545e933c21SGreg Roach self::assertSame( 155cb7a42eaSGreg Roach ["1 NAME Einar\n2 TYPE birth\n2 GIVN Einar"], 156cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 157323788f4SGreg Roach ); 158323788f4SGreg Roach } 159323788f4SGreg Roach 160323788f4SGreg Roach /** 161323788f4SGreg Roach * Test new mother names 16217d74f3aSGreg Roach * 16315d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 16452348eb8SGreg Roach * 16552348eb8SGreg Roach * @return void 166323788f4SGreg Roach */ 1679b802b22SGreg Roach public function testNewMotherNames(): void 168c1010edaSGreg Roach { 169cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 170*83c91e47SGreg Roach $fact->method('value')->willReturn('Jon Evasdottir'); 171cb7a42eaSGreg Roach 172cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 173*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 174cb7a42eaSGreg Roach 1755e933c21SGreg Roach self::assertSame( 176cb7a42eaSGreg Roach ["1 NAME Eva\n2 TYPE birth\n2 GIVN Eva"], 177cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 178323788f4SGreg Roach ); 179323788f4SGreg Roach } 180323788f4SGreg Roach 181323788f4SGreg Roach /** 182323788f4SGreg Roach * Test new parent names 18317d74f3aSGreg Roach * 18415d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 18552348eb8SGreg Roach * 18652348eb8SGreg Roach * @return void 187323788f4SGreg Roach */ 1889b802b22SGreg Roach public function testNewParentNames(): void 189c1010edaSGreg Roach { 190cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 191*83c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 192323788f4SGreg Roach 193cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 194*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 195323788f4SGreg Roach 1965e933c21SGreg Roach self::assertSame( 197cb7a42eaSGreg Roach ["1 NAME\n2 TYPE birth"], 198cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 199323788f4SGreg Roach ); 200323788f4SGreg Roach } 201323788f4SGreg Roach 202323788f4SGreg Roach /** 203323788f4SGreg Roach * Test new spouse names 20417d74f3aSGreg Roach * 20515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 20652348eb8SGreg Roach * 20752348eb8SGreg Roach * @return void 208323788f4SGreg Roach */ 2099b802b22SGreg Roach public function testNewSpouseNames(): void 210c1010edaSGreg Roach { 211cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 212*83c91e47SGreg Roach $fact->method('value')->willReturn('Jon Einarsson'); 213cb7a42eaSGreg Roach 214cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 215*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 216cb7a42eaSGreg Roach 2175e933c21SGreg Roach self::assertSame( 218cb7a42eaSGreg Roach ["1 NAME\n2 TYPE birth"], 219cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 220323788f4SGreg Roach ); 221cb7a42eaSGreg Roach 222cb7a42eaSGreg Roach self::assertSame( 223cb7a42eaSGreg Roach ["1 NAME\n2 TYPE birth"], 224cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 225cb7a42eaSGreg Roach ); 226cb7a42eaSGreg Roach 227cb7a42eaSGreg Roach self::assertSame( 228cb7a42eaSGreg Roach ["1 NAME\n2 TYPE birth"], 229cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 230cb7a42eaSGreg Roach ); 231cb7a42eaSGreg Roach } 232cb7a42eaSGreg Roach 233cb7a42eaSGreg Roach /** 234cb7a42eaSGreg Roach * Prepare the environment for these tests 235cb7a42eaSGreg Roach * 236cb7a42eaSGreg Roach * @return void 237cb7a42eaSGreg Roach */ 238cb7a42eaSGreg Roach protected function setUp(): void 239cb7a42eaSGreg Roach { 240cb7a42eaSGreg Roach parent::setUp(); 241cb7a42eaSGreg Roach 242cb7a42eaSGreg Roach $this->surname_tradition = new IcelandicSurnameTradition(); 243323788f4SGreg Roach } 244323788f4SGreg Roach} 245