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