1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 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; 26 27/** 28 * Test harness for the class IcelandicSurnameTradition 29 */ 30class IcelandicSurnameTraditionTest extends TestCase 31{ 32 private SurnameTraditionInterface $surname_tradition; 33 34 /** 35 * Test whether married surnames are used 36 * 37 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 38 * 39 * @return void 40 */ 41 public function testMarriedSurnames(): void 42 { 43 self::assertFalse($this->surname_tradition->hasMarriedNames()); 44 } 45 46 /** 47 * Test whether surnames are used 48 * 49 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 50 * 51 * @return void 52 */ 53 public function testSurnames(): void 54 { 55 self::assertFalse($this->surname_tradition->hasSurnames()); 56 } 57 58 /** 59 * Test new son names 60 * 61 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 62 * 63 * @return void 64 */ 65 public function testNewSonNames(): void 66 { 67 $father_fact = $this->createStub(Fact::class); 68 $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); 69 70 $father = $this->createStub(Individual::class); 71 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 72 73 $mother_fact = $this->createStub(Fact::class); 74 $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir'); 75 76 $mother = $this->createStub(Individual::class); 77 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 78 79 self::assertSame( 80 ["1 NAME Jonsson\n2 TYPE birth\n2 GIVN Jonsson"], 81 $this->surname_tradition->newChildNames($father, $mother, 'M') 82 ); 83 } 84 85 /** 86 * Test new daughter names 87 * 88 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 89 * 90 * @return void 91 */ 92 public function testNewDaughterNames(): void 93 { 94 $father_fact = $this->createStub(Fact::class); 95 $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); 96 97 $father = $this->createStub(Individual::class); 98 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 99 100 $mother_fact = $this->createStub(Fact::class); 101 $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir'); 102 103 $mother = $this->createStub(Individual::class); 104 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 105 106 self::assertSame( 107 ["1 NAME Jonsdottir\n2 TYPE birth\n2 GIVN Jonsdottir"], 108 $this->surname_tradition->newChildNames($father, $mother, 'F') 109 ); 110 } 111 112 /** 113 * Test new child names 114 * 115 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 116 * 117 * @return void 118 */ 119 public function testNewChildNames(): void 120 { 121 $father_fact = $this->createStub(Fact::class); 122 $father_fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); 123 124 $father = $this->createStub(Individual::class); 125 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 126 127 $mother_fact = $this->createStub(Fact::class); 128 $mother_fact->expects(self::any())->method('value')->willReturn('Eva Stefansdottir'); 129 130 $mother = $this->createStub(Individual::class); 131 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 132 133 self::assertSame( 134 ["1 NAME\n2 TYPE birth"], 135 $this->surname_tradition->newChildNames($father, $mother, 'U') 136 ); 137 } 138 139 /** 140 * Test new father names 141 * 142 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 143 * 144 * @return void 145 */ 146 public function testNewFatherNames(): void 147 { 148 $fact = $this->createStub(Fact::class); 149 $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); 150 151 $individual = $this->createStub(Individual::class); 152 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 153 154 self::assertSame( 155 ["1 NAME Einar\n2 TYPE birth\n2 GIVN Einar"], 156 $this->surname_tradition->newParentNames($individual, 'M') 157 ); 158 } 159 160 /** 161 * Test new mother names 162 * 163 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 164 * 165 * @return void 166 */ 167 public function testNewMotherNames(): void 168 { 169 $fact = $this->createStub(Fact::class); 170 $fact->expects(self::any())->method('value')->willReturn('Jon Evasdottir'); 171 172 $individual = $this->createStub(Individual::class); 173 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 174 175 self::assertSame( 176 ["1 NAME Eva\n2 TYPE birth\n2 GIVN Eva"], 177 $this->surname_tradition->newParentNames($individual, 'F') 178 ); 179 } 180 181 /** 182 * Test new parent names 183 * 184 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 185 * 186 * @return void 187 */ 188 public function testNewParentNames(): void 189 { 190 $fact = $this->createStub(Fact::class); 191 $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); 192 193 $individual = $this->createStub(Individual::class); 194 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 195 196 self::assertSame( 197 ["1 NAME\n2 TYPE birth"], 198 $this->surname_tradition->newParentNames($individual, 'U') 199 ); 200 } 201 202 /** 203 * Test new spouse names 204 * 205 * @covers \Fisharebest\Webtrees\SurnameTradition\IcelandicSurnameTradition 206 * 207 * @return void 208 */ 209 public function testNewSpouseNames(): void 210 { 211 $fact = $this->createStub(Fact::class); 212 $fact->expects(self::any())->method('value')->willReturn('Jon Einarsson'); 213 214 $individual = $this->createStub(Individual::class); 215 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 216 217 self::assertSame( 218 ["1 NAME\n2 TYPE birth"], 219 $this->surname_tradition->newSpouseNames($individual, 'M') 220 ); 221 222 self::assertSame( 223 ["1 NAME\n2 TYPE birth"], 224 $this->surname_tradition->newSpouseNames($individual, 'F') 225 ); 226 227 self::assertSame( 228 ["1 NAME\n2 TYPE birth"], 229 $this->surname_tradition->newSpouseNames($individual, 'U') 230 ); 231 } 232 233 /** 234 * Prepare the environment for these tests 235 * 236 * @return void 237 */ 238 protected function setUp(): void 239 { 240 parent::setUp(); 241 242 $this->surname_tradition = new IcelandicSurnameTradition(); 243 } 244} 245