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