1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2023 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\SurnameTradition; 21 22use Fisharebest\Webtrees\Fact; 23use Fisharebest\Webtrees\Individual; 24use Fisharebest\Webtrees\TestCase; 25use Illuminate\Support\Collection; 26use PHPUnit\Framework\Attributes\CoversClass; 27 28#[CoversClass(IcelandicSurnameTradition::class)] 29class IcelandicSurnameTraditionTest extends TestCase 30{ 31 private SurnameTraditionInterface $surname_tradition; 32 33 /** 34 * Test whether surnames are used 35 */ 36 public function testSurnames(): void 37 { 38 self::assertSame('', $this->surname_tradition->defaultName()); 39 } 40 41 /** 42 * Test new son names 43 */ 44 public function testNewSonNames(): void 45 { 46 $father_fact = $this->createMock(Fact::class); 47 $father_fact->method('value')->willReturn('Jon Einarsson'); 48 49 $father = $this->createMock(Individual::class); 50 $father->method('facts')->willReturn(new Collection([$father_fact])); 51 52 $mother_fact = $this->createMock(Fact::class); 53 $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 54 55 $mother = $this->createMock(Individual::class); 56 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 57 58 self::assertSame( 59 ["1 NAME Jonsson\n2 TYPE BIRTH\n2 GIVN Jonsson"], 60 $this->surname_tradition->newChildNames($father, $mother, 'M') 61 ); 62 } 63 64 /** 65 * Test new daughter names 66 */ 67 public function testNewDaughterNames(): void 68 { 69 $father_fact = $this->createMock(Fact::class); 70 $father_fact->method('value')->willReturn('Jon Einarsson'); 71 72 $father = $this->createMock(Individual::class); 73 $father->method('facts')->willReturn(new Collection([$father_fact])); 74 75 $mother_fact = $this->createMock(Fact::class); 76 $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 77 78 $mother = $this->createMock(Individual::class); 79 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 80 81 self::assertSame( 82 ["1 NAME Jonsdottir\n2 TYPE BIRTH\n2 GIVN Jonsdottir"], 83 $this->surname_tradition->newChildNames($father, $mother, 'F') 84 ); 85 } 86 87 /** 88 * Test new child names 89 */ 90 public function testNewChildNames(): void 91 { 92 $father_fact = $this->createMock(Fact::class); 93 $father_fact->method('value')->willReturn('Jon Einarsson'); 94 95 $father = $this->createMock(Individual::class); 96 $father->method('facts')->willReturn(new Collection([$father_fact])); 97 98 $mother_fact = $this->createMock(Fact::class); 99 $mother_fact->method('value')->willReturn('Eva Stefansdottir'); 100 101 $mother = $this->createMock(Individual::class); 102 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 103 104 self::assertSame( 105 ["1 NAME\n2 TYPE BIRTH"], 106 $this->surname_tradition->newChildNames($father, $mother, 'U') 107 ); 108 } 109 110 /** 111 * Test new father names 112 */ 113 public function testNewFatherNames(): void 114 { 115 $fact = $this->createMock(Fact::class); 116 $fact->method('value')->willReturn('Jon Einarsson'); 117 118 $individual = $this->createMock(Individual::class); 119 $individual->method('facts')->willReturn(new Collection([$fact])); 120 121 self::assertSame( 122 ["1 NAME Einar\n2 TYPE BIRTH\n2 GIVN Einar"], 123 $this->surname_tradition->newParentNames($individual, 'M') 124 ); 125 } 126 127 /** 128 * Test new mother names 129 */ 130 public function testNewMotherNames(): void 131 { 132 $fact = $this->createMock(Fact::class); 133 $fact->method('value')->willReturn('Jon Evasdottir'); 134 135 $individual = $this->createMock(Individual::class); 136 $individual->method('facts')->willReturn(new Collection([$fact])); 137 138 self::assertSame( 139 ["1 NAME Eva\n2 TYPE BIRTH\n2 GIVN Eva"], 140 $this->surname_tradition->newParentNames($individual, 'F') 141 ); 142 } 143 144 /** 145 * Test new parent names 146 */ 147 public function testNewParentNames(): void 148 { 149 $fact = $this->createMock(Fact::class); 150 $fact->method('value')->willReturn('Jon Einarsson'); 151 152 $individual = $this->createMock(Individual::class); 153 $individual->method('facts')->willReturn(new Collection([$fact])); 154 155 self::assertSame( 156 ["1 NAME\n2 TYPE BIRTH"], 157 $this->surname_tradition->newParentNames($individual, 'U') 158 ); 159 } 160 161 /** 162 * Test new spouse names 163 */ 164 public function testNewSpouseNames(): void 165 { 166 $fact = $this->createMock(Fact::class); 167 $fact->method('value')->willReturn('Jon Einarsson'); 168 169 $individual = $this->createMock(Individual::class); 170 $individual->method('facts')->willReturn(new Collection([$fact])); 171 172 self::assertSame( 173 ["1 NAME\n2 TYPE BIRTH"], 174 $this->surname_tradition->newSpouseNames($individual, 'M') 175 ); 176 177 self::assertSame( 178 ["1 NAME\n2 TYPE BIRTH"], 179 $this->surname_tradition->newSpouseNames($individual, 'F') 180 ); 181 182 self::assertSame( 183 ["1 NAME\n2 TYPE BIRTH"], 184 $this->surname_tradition->newSpouseNames($individual, 'U') 185 ); 186 } 187 188 /** 189 * Prepare the environment for these tests 190 */ 191 protected function setUp(): void 192 { 193 parent::setUp(); 194 195 $this->surname_tradition = new IcelandicSurnameTradition(); 196 } 197} 198