1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify 7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by 8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9323788f4SGreg Roach * (at your option) any later version. 10323788f4SGreg Roach * This program is distributed in the hope that it will be useful, 11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13323788f4SGreg Roach * GNU General Public License for more details. 14323788f4SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16323788f4SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition; 21c1010edaSGreg Roach 22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Fact; 23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 243cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase; 25cb7a42eaSGreg Roachuse Illuminate\Support\Collection; 26202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 273cfcc809SGreg Roach 28202c018bSGreg Roach 29202c018bSGreg Roach#[CoversClass(PolishSurnameTradition::class)] 30202c018bSGreg Roach#[CoversClass(PatrilinealSurnameTradition::class)] 313cfcc809SGreg Roachclass PolishSurnameTraditionTest extends TestCase 32c1010edaSGreg Roach{ 33c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 34323788f4SGreg Roach 35323788f4SGreg Roach /** 36c1ec7145SGreg Roach * Test whether surnames are used 37c1ec7145SGreg Roach */ 389b802b22SGreg Roach public function testSurnames(): void 39c1010edaSGreg Roach { 40a171b6a5SGreg Roach self::assertSame('//', $this->surname_tradition->defaultName()); 41c1ec7145SGreg Roach } 42c1ec7145SGreg Roach 43c1ec7145SGreg Roach /** 44323788f4SGreg Roach * Test new son names 45323788f4SGreg Roach */ 469b802b22SGreg Roach public function testNewSonNames(): void 47c1010edaSGreg Roach { 48*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 4983c91e47SGreg Roach $father_fact->method('value')->willReturn('John /White/'); 50cb7a42eaSGreg Roach 51*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 5283c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 53cb7a42eaSGreg Roach 54*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 5583c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 56cb7a42eaSGreg Roach 57*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 5883c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 59cb7a42eaSGreg Roach 605e933c21SGreg Roach self::assertSame( 618939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 62cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 63323788f4SGreg Roach ); 64323788f4SGreg Roach } 65323788f4SGreg Roach 66323788f4SGreg Roach /** 67323788f4SGreg Roach * Test new daughter names 68323788f4SGreg Roach */ 699b802b22SGreg Roach public function testNewDaughterNames(): void 70c1010edaSGreg Roach { 71*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 7283c91e47SGreg Roach $father_fact->method('value')->willReturn('John /White/'); 73cb7a42eaSGreg Roach 74*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 7583c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 76cb7a42eaSGreg Roach 77*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 7883c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 79cb7a42eaSGreg Roach 80*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 8183c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 82cb7a42eaSGreg Roach 835e933c21SGreg Roach self::assertSame( 848939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 85cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 86323788f4SGreg Roach ); 87323788f4SGreg Roach } 88323788f4SGreg Roach 89323788f4SGreg Roach /** 90323788f4SGreg Roach * Test new daughter names 91323788f4SGreg Roach */ 929b802b22SGreg Roach public function testNewDaughterNamesInflected(): void 93c1010edaSGreg Roach { 94*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 9583c91e47SGreg Roach $father_fact->method('value')->willReturn('John /Whitecki/'); 96cb7a42eaSGreg Roach 97*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 9883c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 99cb7a42eaSGreg Roach 100*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 10183c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 102cb7a42eaSGreg Roach 103*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 10483c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 105cb7a42eaSGreg Roach 1065e933c21SGreg Roach self::assertSame( 1078939e2c2SGreg Roach ["1 NAME /Whitecka/\n2 TYPE BIRTH\n2 SURN Whitecki"], 108cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 109323788f4SGreg Roach ); 110cb7a42eaSGreg Roach 111*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 11283c91e47SGreg Roach $father_fact->method('value')->willReturn('John /Whitedzki/'); 113cb7a42eaSGreg Roach 114*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 11583c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 116cb7a42eaSGreg Roach 117*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 11883c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 119cb7a42eaSGreg Roach 120*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 12183c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 122cb7a42eaSGreg Roach 1235e933c21SGreg Roach self::assertSame( 1248939e2c2SGreg Roach ["1 NAME /Whitedzka/\n2 TYPE BIRTH\n2 SURN Whitedzki"], 125cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 126323788f4SGreg Roach ); 127cb7a42eaSGreg Roach 128*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 12983c91e47SGreg Roach $father_fact->method('value')->willReturn('John /Whiteski/'); 130cb7a42eaSGreg Roach 131*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 13283c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 133cb7a42eaSGreg Roach 134*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 13583c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 136cb7a42eaSGreg Roach 137*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 13883c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 139cb7a42eaSGreg Roach 1405e933c21SGreg Roach self::assertSame( 1418939e2c2SGreg Roach ["1 NAME /Whiteska/\n2 TYPE BIRTH\n2 SURN Whiteski"], 142cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 143323788f4SGreg Roach ); 144cb7a42eaSGreg Roach 145*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 14683c91e47SGreg Roach $father_fact->method('value')->willReturn('John /Whiteżki/'); 147cb7a42eaSGreg Roach 148*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 14983c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 150cb7a42eaSGreg Roach 151*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 15283c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 153cb7a42eaSGreg Roach 154*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 15583c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 156cb7a42eaSGreg Roach 1575e933c21SGreg Roach self::assertSame( 1588939e2c2SGreg Roach ["1 NAME /Whiteżka/\n2 TYPE BIRTH\n2 SURN Whiteżki"], 159cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 160323788f4SGreg Roach ); 161323788f4SGreg Roach } 162323788f4SGreg Roach 163323788f4SGreg Roach /** 164323788f4SGreg Roach * Test new child names 165323788f4SGreg Roach */ 1669b802b22SGreg Roach public function testNewChildNames(): void 167c1010edaSGreg Roach { 168*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 16983c91e47SGreg Roach $father_fact->method('value')->willReturn('John /White/'); 170cb7a42eaSGreg Roach 171*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 17283c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 173cb7a42eaSGreg Roach 174*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 17583c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 176cb7a42eaSGreg Roach 177*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 17883c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 179cb7a42eaSGreg Roach 1805e933c21SGreg Roach self::assertSame( 1818939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 182cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 183323788f4SGreg Roach ); 184323788f4SGreg Roach } 185323788f4SGreg Roach 186323788f4SGreg Roach /** 1871677a03aSGreg Roach * Test new child names 1881677a03aSGreg Roach */ 1899b802b22SGreg Roach public function testNewChildNamesWithNoParentsNames(): void 190c1010edaSGreg Roach { 1915e933c21SGreg Roach self::assertSame( 1928939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 193cb7a42eaSGreg Roach $this->surname_tradition->newChildNames(null, null, 'U') 1941677a03aSGreg Roach ); 1951677a03aSGreg Roach } 1961677a03aSGreg Roach 1971677a03aSGreg Roach /** 198323788f4SGreg Roach * Test new father names 199323788f4SGreg Roach */ 2009b802b22SGreg Roach public function testNewFatherNames(): void 201c1010edaSGreg Roach { 202*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 20383c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 204cb7a42eaSGreg Roach 205*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 20683c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 207cb7a42eaSGreg Roach 2085e933c21SGreg Roach self::assertSame( 2098939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 210cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 211323788f4SGreg Roach ); 212323788f4SGreg Roach } 213323788f4SGreg Roach 214323788f4SGreg Roach /** 215323788f4SGreg Roach * Test new father names 216323788f4SGreg Roach */ 2179b802b22SGreg Roach public function testNewFatherNamesInflected(): void 218c1010edaSGreg Roach { 219*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 22083c91e47SGreg Roach $fact->method('value')->willReturn('Chris /Whitecka/'); 221cb7a42eaSGreg Roach 222*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 22383c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 224cb7a42eaSGreg Roach 2255e933c21SGreg Roach self::assertSame( 2268939e2c2SGreg Roach ["1 NAME /Whitecki/\n2 TYPE BIRTH\n2 SURN Whitecki"], 227cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 228323788f4SGreg Roach ); 229cb7a42eaSGreg Roach 230*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 23183c91e47SGreg Roach $fact->method('value')->willReturn('Chris /Whitedzka/'); 232cb7a42eaSGreg Roach 233*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 23483c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 235cb7a42eaSGreg Roach 2365e933c21SGreg Roach self::assertSame( 2378939e2c2SGreg Roach ["1 NAME /Whitedzki/\n2 TYPE BIRTH\n2 SURN Whitedzki"], 238cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 239323788f4SGreg Roach ); 240cb7a42eaSGreg Roach 241*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 24283c91e47SGreg Roach $fact->method('value')->willReturn('Chris /Whiteska/'); 243cb7a42eaSGreg Roach 244*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 24583c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 246cb7a42eaSGreg Roach 2475e933c21SGreg Roach self::assertSame( 2488939e2c2SGreg Roach ["1 NAME /Whiteski/\n2 TYPE BIRTH\n2 SURN Whiteski"], 249cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 250323788f4SGreg Roach ); 251cb7a42eaSGreg Roach 252*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 25383c91e47SGreg Roach $fact->method('value')->willReturn('Chris /Whiteżka/'); 254cb7a42eaSGreg Roach 255*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 25683c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 257cb7a42eaSGreg Roach 2585e933c21SGreg Roach self::assertSame( 2598939e2c2SGreg Roach ["1 NAME /Whiteżki/\n2 TYPE BIRTH\n2 SURN Whiteżki"], 260cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 261323788f4SGreg Roach ); 262323788f4SGreg Roach } 263323788f4SGreg Roach 264323788f4SGreg Roach /** 265323788f4SGreg Roach * Test new mother names 266323788f4SGreg Roach */ 2679b802b22SGreg Roach public function testNewMotherNames(): void 268c1010edaSGreg Roach { 269*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 27083c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 271cb7a42eaSGreg Roach 272*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 27383c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 274cb7a42eaSGreg Roach 2755e933c21SGreg Roach self::assertSame( 2768939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 277cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 278323788f4SGreg Roach ); 279323788f4SGreg Roach } 280323788f4SGreg Roach 281323788f4SGreg Roach /** 282323788f4SGreg Roach * Test new parent names 283323788f4SGreg Roach */ 2849b802b22SGreg Roach public function testNewParentNames(): void 285c1010edaSGreg Roach { 286*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 28783c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 288323788f4SGreg Roach 289*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 29083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 291323788f4SGreg Roach 2925e933c21SGreg Roach self::assertSame( 2938939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 294cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 295323788f4SGreg Roach ); 296323788f4SGreg Roach } 297323788f4SGreg Roach 298323788f4SGreg Roach /** 299323788f4SGreg Roach * Test new spouse names 300323788f4SGreg Roach */ 3019b802b22SGreg Roach public function testNewSpouseNames(): void 302c1010edaSGreg Roach { 303*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 30483c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 305cb7a42eaSGreg Roach 306*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 30783c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 308cb7a42eaSGreg Roach 3095e933c21SGreg Roach self::assertSame( 3108939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 311cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 312323788f4SGreg Roach ); 313cb7a42eaSGreg Roach 314cb7a42eaSGreg Roach self::assertSame( 3158939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 316cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 317cb7a42eaSGreg Roach ); 318cb7a42eaSGreg Roach 319cb7a42eaSGreg Roach self::assertSame( 3208939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 321cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 322cb7a42eaSGreg Roach ); 323cb7a42eaSGreg Roach } 324cb7a42eaSGreg Roach 325cb7a42eaSGreg Roach /** 326cb7a42eaSGreg Roach * Prepare the environment for these tests 327cb7a42eaSGreg Roach */ 328cb7a42eaSGreg Roach protected function setUp(): void 329cb7a42eaSGreg Roach { 330cb7a42eaSGreg Roach parent::setUp(); 331cb7a42eaSGreg Roach 332cb7a42eaSGreg Roach $this->surname_tradition = new PolishSurnameTradition(); 333323788f4SGreg Roach } 334323788f4SGreg Roach} 335