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 PolishSurnameTradition 29 */ 30class PolishSurnameTraditionTest extends TestCase 31{ 32 private SurnameTraditionInterface $surname_tradition; 33 34 /** 35 * Test whether married surnames are used 36 * 37 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 38 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 39 * 40 * @return void 41 */ 42 public function testMarriedSurnames(): void 43 { 44 self::assertTrue($this->surname_tradition->hasMarriedNames()); 45 } 46 47 /** 48 * Test whether surnames are used 49 * 50 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 51 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 52 * 53 * @return void 54 */ 55 public function testSurnames(): void 56 { 57 self::assertTrue($this->surname_tradition->hasSurnames()); 58 } 59 60 /** 61 * Test new son names 62 * 63 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 64 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 65 * 66 * @return void 67 */ 68 public function testNewSonNames(): void 69 { 70 $father_fact = $this->createStub(Fact::class); 71 $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); 72 73 $father = $this->createStub(Individual::class); 74 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 75 76 $mother_fact = $this->createStub(Fact::class); 77 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 78 79 $mother = $this->createStub(Individual::class); 80 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 81 82 self::assertSame( 83 ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 84 $this->surname_tradition->newChildNames($father, $mother, 'M') 85 ); 86 } 87 88 /** 89 * Test new daughter names 90 * 91 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 92 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 93 * 94 * @return void 95 */ 96 public function testNewDaughterNames(): void 97 { 98 $father_fact = $this->createStub(Fact::class); 99 $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); 100 101 $father = $this->createStub(Individual::class); 102 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 103 104 $mother_fact = $this->createStub(Fact::class); 105 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 106 107 $mother = $this->createStub(Individual::class); 108 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 109 110 self::assertSame( 111 ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 112 $this->surname_tradition->newChildNames($father, $mother, 'F') 113 ); 114 } 115 116 /** 117 * Test new daughter names 118 * 119 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 120 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 121 * 122 * @return void 123 */ 124 public function testNewDaughterNamesInflected(): void 125 { 126 $father_fact = $this->createStub(Fact::class); 127 $father_fact->expects(self::any())->method('value')->willReturn('John /Whitecki/'); 128 129 $father = $this->createStub(Individual::class); 130 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 131 132 $mother_fact = $this->createStub(Fact::class); 133 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 134 135 $mother = $this->createStub(Individual::class); 136 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 137 138 self::assertSame( 139 ["1 NAME /Whitecka/\n2 TYPE birth\n2 SURN Whitecki"], 140 $this->surname_tradition->newChildNames($father, $mother, 'F') 141 ); 142 143 $father_fact = $this->createStub(Fact::class); 144 $father_fact->expects(self::any())->method('value')->willReturn('John /Whitedzki/'); 145 146 $father = $this->createStub(Individual::class); 147 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 148 149 $mother_fact = $this->createStub(Fact::class); 150 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 151 152 $mother = $this->createStub(Individual::class); 153 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 154 155 self::assertSame( 156 ["1 NAME /Whitedzka/\n2 TYPE birth\n2 SURN Whitedzki"], 157 $this->surname_tradition->newChildNames($father, $mother, 'F') 158 ); 159 160 $father_fact = $this->createStub(Fact::class); 161 $father_fact->expects(self::any())->method('value')->willReturn('John /Whiteski/'); 162 163 $father = $this->createStub(Individual::class); 164 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 165 166 $mother_fact = $this->createStub(Fact::class); 167 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 168 169 $mother = $this->createStub(Individual::class); 170 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 171 172 self::assertSame( 173 ["1 NAME /Whiteska/\n2 TYPE birth\n2 SURN Whiteski"], 174 $this->surname_tradition->newChildNames($father, $mother, 'F') 175 ); 176 177 $father_fact = $this->createStub(Fact::class); 178 $father_fact->expects(self::any())->method('value')->willReturn('John /Whiteżki/'); 179 180 $father = $this->createStub(Individual::class); 181 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 182 183 $mother_fact = $this->createStub(Fact::class); 184 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 185 186 $mother = $this->createStub(Individual::class); 187 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 188 189 self::assertSame( 190 ["1 NAME /Whiteżka/\n2 TYPE birth\n2 SURN Whiteżki"], 191 $this->surname_tradition->newChildNames($father, $mother, 'F') 192 ); 193 } 194 195 /** 196 * Test new child names 197 * 198 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 199 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 200 * 201 * @return void 202 */ 203 public function testNewChildNames(): void 204 { 205 $father_fact = $this->createStub(Fact::class); 206 $father_fact->expects(self::any())->method('value')->willReturn('John /White/'); 207 208 $father = $this->createStub(Individual::class); 209 $father->expects(self::any())->method('facts')->willReturn(new Collection([$father_fact])); 210 211 $mother_fact = $this->createStub(Fact::class); 212 $mother_fact->expects(self::any())->method('value')->willReturn('Mary /Black/'); 213 214 $mother = $this->createStub(Individual::class); 215 $mother->expects(self::any())->method('facts')->willReturn(new Collection([$mother_fact])); 216 217 self::assertSame( 218 ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 219 $this->surname_tradition->newChildNames($father, $mother, 'U') 220 ); 221 } 222 223 /** 224 * Test new child names 225 * 226 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 227 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 228 * 229 * @return void 230 */ 231 public function testNewChildNamesWithNoParentsNames(): void 232 { 233 self::assertSame( 234 ["1 NAME //\n2 TYPE birth"], 235 $this->surname_tradition->newChildNames(null, null, 'U') 236 ); 237 } 238 239 /** 240 * Test new father names 241 * 242 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 243 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 244 * 245 * @return void 246 */ 247 public function testNewFatherNames(): void 248 { 249 $fact = $this->createStub(Fact::class); 250 $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); 251 252 $individual = $this->createStub(Individual::class); 253 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 254 255 self::assertSame( 256 ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 257 $this->surname_tradition->newParentNames($individual, 'M') 258 ); 259 } 260 261 /** 262 * Test new father names 263 * 264 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 265 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 266 * 267 * @return void 268 */ 269 public function testNewFatherNamesInflected(): void 270 { 271 $fact = $this->createStub(Fact::class); 272 $fact->expects(self::any())->method('value')->willReturn('Chris /Whitecka/'); 273 274 $individual = $this->createStub(Individual::class); 275 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 276 277 self::assertSame( 278 ["1 NAME /Whitecki/\n2 TYPE birth\n2 SURN Whitecki"], 279 $this->surname_tradition->newParentNames($individual, 'M') 280 ); 281 282 $fact = $this->createStub(Fact::class); 283 $fact->expects(self::any())->method('value')->willReturn('Chris /Whitedzka/'); 284 285 $individual = $this->createStub(Individual::class); 286 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 287 288 self::assertSame( 289 ["1 NAME /Whitedzki/\n2 TYPE birth\n2 SURN Whitedzki"], 290 $this->surname_tradition->newParentNames($individual, 'M') 291 ); 292 293 $fact = $this->createStub(Fact::class); 294 $fact->expects(self::any())->method('value')->willReturn('Chris /Whiteska/'); 295 296 $individual = $this->createStub(Individual::class); 297 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 298 299 self::assertSame( 300 ["1 NAME /Whiteski/\n2 TYPE birth\n2 SURN Whiteski"], 301 $this->surname_tradition->newParentNames($individual, 'M') 302 ); 303 304 $fact = $this->createStub(Fact::class); 305 $fact->expects(self::any())->method('value')->willReturn('Chris /Whiteżka/'); 306 307 $individual = $this->createStub(Individual::class); 308 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 309 310 self::assertSame( 311 ["1 NAME /Whiteżki/\n2 TYPE birth\n2 SURN Whiteżki"], 312 $this->surname_tradition->newParentNames($individual, 'M') 313 ); 314 } 315 316 /** 317 * Test new mother names 318 * 319 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 320 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 321 * 322 * @return void 323 */ 324 public function testNewMotherNames(): void 325 { 326 $fact = $this->createStub(Fact::class); 327 $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); 328 329 $individual = $this->createStub(Individual::class); 330 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 331 332 self::assertSame( 333 ["1 NAME //\n2 TYPE birth"], 334 $this->surname_tradition->newParentNames($individual, 'F') 335 ); 336 } 337 338 /** 339 * Test new parent names 340 * 341 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 342 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 343 * 344 * @return void 345 */ 346 public function testNewParentNames(): void 347 { 348 $fact = $this->createStub(Fact::class); 349 $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); 350 351 $individual = $this->createStub(Individual::class); 352 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 353 354 self::assertSame( 355 ["1 NAME //\n2 TYPE birth"], 356 $this->surname_tradition->newParentNames($individual, 'U') 357 ); 358 } 359 360 /** 361 * Test new spouse names 362 * 363 * @covers \Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition 364 * @covers \Fisharebest\Webtrees\SurnameTradition\PatrilinealSurnameTradition 365 * 366 * @return void 367 */ 368 public function testNewSpouseNames(): void 369 { 370 $fact = $this->createStub(Fact::class); 371 $fact->expects(self::any())->method('value')->willReturn('Chris /White/'); 372 373 $individual = $this->createStub(Individual::class); 374 $individual->expects(self::any())->method('facts')->willReturn(new Collection([$fact])); 375 376 self::assertSame( 377 ["1 NAME //\n2 TYPE birth"], 378 $this->surname_tradition->newSpouseNames($individual, 'M') 379 ); 380 381 self::assertSame( 382 ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], 383 $this->surname_tradition->newSpouseNames($individual, 'F') 384 ); 385 386 self::assertSame( 387 ["1 NAME //\n2 TYPE birth"], 388 $this->surname_tradition->newSpouseNames($individual, 'U') 389 ); 390 } 391 392 /** 393 * Prepare the environment for these tests 394 * 395 * @return void 396 */ 397 protected function setUp(): void 398 { 399 parent::setUp(); 400 401 $this->surname_tradition = new PolishSurnameTradition(); 402 } 403} 404