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; 26 27/** 28 * Test harness for the class PaternalSurnameTradition 29 */ 30class PaternalSurnameTraditionTest extends TestCase 31{ 32 private SurnameTraditionInterface $surname_tradition; 33 34 /** 35 * Test whether surnames are used 36 * 37 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 38 */ 39 public function testSurnames(): void 40 { 41 self::assertSame('//', $this->surname_tradition->defaultName()); 42 } 43 44 /** 45 * Test new child names 46 * 47 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 48 */ 49 public function testNewChildNames(): void 50 { 51 $father_fact = $this->createStub(Fact::class); 52 $father_fact->method('value')->willReturn('John /White/'); 53 54 $father = $this->createStub(Individual::class); 55 $father->method('facts')->willReturn(new Collection([$father_fact])); 56 57 $mother_fact = $this->createStub(Fact::class); 58 $mother_fact->method('value')->willReturn('Mary /Black/'); 59 60 $mother = $this->createStub(Individual::class); 61 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 62 63 self::assertSame( 64 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 65 $this->surname_tradition->newChildNames($father, $mother, 'M') 66 ); 67 68 self::assertSame( 69 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 70 $this->surname_tradition->newChildNames($father, $mother, 'F') 71 ); 72 73 self::assertSame( 74 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 75 $this->surname_tradition->newChildNames($father, $mother, 'U') 76 ); 77 } 78 79 /** 80 * Test new child names 81 * 82 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 83 */ 84 public function testNewChildNamesWithSpfx(): void 85 { 86 $father_fact = $this->createStub(Fact::class); 87 $father_fact->method('value')->willReturn('John /de White/'); 88 89 $father = $this->createStub(Individual::class); 90 $father->method('facts')->willReturn(new Collection([$father_fact])); 91 92 $mother_fact = $this->createStub(Fact::class); 93 $mother_fact->method('value')->willReturn('Mary /van Black/'); 94 95 $mother = $this->createStub(Individual::class); 96 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 97 98 self::assertSame( 99 ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"], 100 $this->surname_tradition->newChildNames($father, $mother, 'U') 101 ); 102 } 103 104 /** 105 * Test new child names 106 * 107 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 108 */ 109 public function testNewChildNamesWithMultipleSpfx(): void 110 { 111 $father_fact = $this->createStub(Fact::class); 112 $father_fact->method('value')->willReturn('John /van der White/'); 113 114 $father = $this->createStub(Individual::class); 115 $father->method('facts')->willReturn(new Collection([$father_fact])); 116 117 $mother_fact = $this->createStub(Fact::class); 118 $mother_fact->method('value')->willReturn('Mary /van Black/'); 119 120 $mother = $this->createStub(Individual::class); 121 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 122 123 self::assertSame( 124 ["1 NAME /van der White/\n2 TYPE BIRTH\n2 SPFX van der\n2 SURN White"], 125 $this->surname_tradition->newChildNames($father, $mother, 'U') 126 ); 127 } 128 129 /** 130 * Test new child names 131 * 132 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 133 */ 134 public function testNewChildNamesWithDutchSpfx(): void 135 { 136 $father_fact = $this->createStub(Fact::class); 137 $father_fact->method('value')->willReturn('John /\'t White/'); 138 139 $father = $this->createStub(Individual::class); 140 $father->method('facts')->willReturn(new Collection([$father_fact])); 141 142 $mother_fact = $this->createStub(Fact::class); 143 $mother_fact->method('value')->willReturn('Mary /van Black/'); 144 145 $mother = $this->createStub(Individual::class); 146 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 147 148 self::assertSame( 149 ["1 NAME /'t White/\n2 TYPE BIRTH\n2 SPFX 't\n2 SURN White"], 150 $this->surname_tradition->newChildNames($father, $mother, 'U') 151 ); 152 } 153 154 /** 155 * Test new child names 156 * 157 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 158 */ 159 public function testNewChildNamesWithMultipleDutchSpfx(): void 160 { 161 $father_fact = $this->createStub(Fact::class); 162 $father_fact->method('value')->willReturn('John /van \'t White/'); 163 164 $father = $this->createStub(Individual::class); 165 $father->method('facts')->willReturn(new Collection([$father_fact])); 166 167 $mother_fact = $this->createStub(Fact::class); 168 $mother_fact->method('value')->willReturn('Mary /van Black/'); 169 170 $mother = $this->createStub(Individual::class); 171 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 172 173 self::assertSame( 174 ["1 NAME /van 't White/\n2 TYPE BIRTH\n2 SPFX van 't\n2 SURN White"], 175 $this->surname_tradition->newChildNames($father, $mother, 'U') 176 ); 177 } 178 179 /** 180 * Test new father names 181 * 182 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 183 */ 184 public function testNewFatherNames(): void 185 { 186 $fact = $this->createStub(Fact::class); 187 $fact->method('value')->willReturn('Chris /White/'); 188 189 $individual = $this->createStub(Individual::class); 190 $individual->method('facts')->willReturn(new Collection([$fact])); 191 192 self::assertSame( 193 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 194 $this->surname_tradition->newParentNames($individual, 'M') 195 ); 196 } 197 198 /** 199 * Test new mother names 200 * 201 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 202 */ 203 public function testNewMotherNames(): void 204 { 205 $fact = $this->createStub(Fact::class); 206 $fact->method('value')->willReturn('Chris /White/'); 207 208 $individual = $this->createStub(Individual::class); 209 $individual->method('facts')->willReturn(new Collection([$fact])); 210 211 self::assertSame( 212 ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 213 $this->surname_tradition->newParentNames($individual, 'F') 214 ); 215 } 216 217 /** 218 * Test new parent names 219 * 220 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 221 */ 222 public function testNewParentNames(): void 223 { 224 $fact = $this->createStub(Fact::class); 225 $fact->method('value')->willReturn('Chris /White/'); 226 227 $individual = $this->createStub(Individual::class); 228 $individual->method('facts')->willReturn(new Collection([$fact])); 229 230 self::assertSame( 231 ["1 NAME //\n2 TYPE BIRTH"], 232 $this->surname_tradition->newParentNames($individual, 'U') 233 ); 234 } 235 236 /** 237 * Test new husband names 238 * 239 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 240 */ 241 public function testNewHusbandNames(): void 242 { 243 $fact = $this->createStub(Fact::class); 244 $fact->method('value')->willReturn('Chris /White/'); 245 246 $individual = $this->createStub(Individual::class); 247 $individual->method('facts')->willReturn(new Collection([$fact])); 248 249 self::assertSame( 250 ["1 NAME //\n2 TYPE BIRTH"], 251 $this->surname_tradition->newSpouseNames($individual, 'M') 252 ); 253 } 254 255 /** 256 * Test new wife names 257 * 258 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 259 */ 260 public function testNewWifeNames(): void 261 { 262 $fact = $this->createStub(Fact::class); 263 $fact->method('value')->willReturn('Chris /White/'); 264 265 $individual = $this->createStub(Individual::class); 266 $individual->method('facts')->willReturn(new Collection([$fact])); 267 268 self::assertSame( 269 ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 270 $this->surname_tradition->newSpouseNames($individual, 'F') 271 ); 272 } 273 274 /** 275 * Test new wife names 276 * 277 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 278 */ 279 public function testNewWifeNamesWithSpfx(): void 280 { 281 $fact = $this->createStub(Fact::class); 282 $fact->method('value')->willReturn('Chris /van der White/'); 283 284 $individual = $this->createStub(Individual::class); 285 $individual->method('facts')->willReturn(new Collection([$fact])); 286 287 self::assertSame( 288 ["1 NAME //\n2 TYPE BIRTH", "1 NAME /van der White/\n2 TYPE MARRIED\n2 SPFX van der\n2 SURN White"], 289 $this->surname_tradition->newSpouseNames($individual, 'F') 290 ); 291 } 292 293 /** 294 * Test new spouse names 295 * 296 * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 297 */ 298 public function testNewSpouseNames(): void 299 { 300 $fact = $this->createStub(Fact::class); 301 $fact->method('value')->willReturn('Chris /White/'); 302 303 $individual = $this->createStub(Individual::class); 304 $individual->method('facts')->willReturn(new Collection([$fact])); 305 306 self::assertSame( 307 ["1 NAME //\n2 TYPE BIRTH"], 308 $this->surname_tradition->newSpouseNames($individual, 'U') 309 ); 310 } 311 312 /** 313 * Prepare the environment for these tests 314 */ 315 protected function setUp(): void 316 { 317 parent::setUp(); 318 319 $this->surname_tradition = new PaternalSurnameTradition(); 320 } 321} 322