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(PaternalSurnameTradition::class)] 303cfcc809SGreg Roachclass PaternalSurnameTraditionTest extends TestCase 31c1010edaSGreg Roach{ 32c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 33323788f4SGreg Roach 34323788f4SGreg Roach /** 35c1ec7145SGreg Roach * Test whether surnames are used 36c1ec7145SGreg Roach */ 379b802b22SGreg Roach public function testSurnames(): void 38c1010edaSGreg Roach { 39a171b6a5SGreg Roach self::assertSame('//', $this->surname_tradition->defaultName()); 40c1ec7145SGreg Roach } 41c1ec7145SGreg Roach 42c1ec7145SGreg Roach /** 43323788f4SGreg Roach * Test new child names 44323788f4SGreg Roach */ 459b802b22SGreg Roach public function testNewChildNames(): void 46c1010edaSGreg Roach { 47*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 4883c91e47SGreg Roach $father_fact->method('value')->willReturn('John /White/'); 49cb7a42eaSGreg Roach 50*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 5183c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 52cb7a42eaSGreg Roach 53*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 5483c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 55cb7a42eaSGreg Roach 56*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 5783c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 58cb7a42eaSGreg Roach 595e933c21SGreg Roach self::assertSame( 608939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 61cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 62cb7a42eaSGreg Roach ); 63cb7a42eaSGreg Roach 64cb7a42eaSGreg Roach self::assertSame( 658939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 66cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 67cb7a42eaSGreg Roach ); 68cb7a42eaSGreg Roach 69cb7a42eaSGreg Roach self::assertSame( 708939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 71cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 72323788f4SGreg Roach ); 73323788f4SGreg Roach } 74323788f4SGreg Roach 75323788f4SGreg Roach /** 76323788f4SGreg Roach * Test new child names 77323788f4SGreg Roach */ 789b802b22SGreg Roach public function testNewChildNamesWithSpfx(): void 79c1010edaSGreg Roach { 80*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 8183c91e47SGreg Roach $father_fact->method('value')->willReturn('John /de White/'); 82cb7a42eaSGreg Roach 83*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 8483c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 85cb7a42eaSGreg Roach 86*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 8783c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 88cb7a42eaSGreg Roach 89*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 9083c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 91cb7a42eaSGreg Roach 925e933c21SGreg Roach self::assertSame( 938939e2c2SGreg Roach ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"], 94cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 95323788f4SGreg Roach ); 96323788f4SGreg Roach } 97323788f4SGreg Roach 98323788f4SGreg Roach /** 998caf8226SGreg Roach * Test new child names 1008caf8226SGreg Roach */ 1019b802b22SGreg Roach public function testNewChildNamesWithMultipleSpfx(): void 102c1010edaSGreg Roach { 103*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 10483c91e47SGreg Roach $father_fact->method('value')->willReturn('John /van der White/'); 105cb7a42eaSGreg Roach 106*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 10783c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 108cb7a42eaSGreg Roach 109*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 11083c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 111cb7a42eaSGreg Roach 112*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 11383c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 114cb7a42eaSGreg Roach 1155e933c21SGreg Roach self::assertSame( 1168939e2c2SGreg Roach ["1 NAME /van der White/\n2 TYPE BIRTH\n2 SPFX van der\n2 SURN White"], 117cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1188caf8226SGreg Roach ); 1198caf8226SGreg Roach } 1208caf8226SGreg Roach 1218caf8226SGreg Roach /** 1229797fe2eSGreg Roach * Test new child names 1239797fe2eSGreg Roach */ 1249b802b22SGreg Roach public function testNewChildNamesWithDutchSpfx(): void 125c1010edaSGreg Roach { 126*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 12783c91e47SGreg Roach $father_fact->method('value')->willReturn('John /\'t White/'); 128cb7a42eaSGreg Roach 129*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 13083c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 131cb7a42eaSGreg Roach 132*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 13383c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 134cb7a42eaSGreg Roach 135*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 13683c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 137cb7a42eaSGreg Roach 1385e933c21SGreg Roach self::assertSame( 1398939e2c2SGreg Roach ["1 NAME /'t White/\n2 TYPE BIRTH\n2 SPFX 't\n2 SURN White"], 140cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1419797fe2eSGreg Roach ); 1429797fe2eSGreg Roach } 1439797fe2eSGreg Roach 1449797fe2eSGreg Roach /** 1459797fe2eSGreg Roach * Test new child names 1469797fe2eSGreg Roach */ 1479b802b22SGreg Roach public function testNewChildNamesWithMultipleDutchSpfx(): void 148c1010edaSGreg Roach { 149*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 15083c91e47SGreg Roach $father_fact->method('value')->willReturn('John /van \'t White/'); 151cb7a42eaSGreg Roach 152*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 15383c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 154cb7a42eaSGreg Roach 155*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 15683c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 157cb7a42eaSGreg Roach 158*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 15983c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 160cb7a42eaSGreg Roach 1615e933c21SGreg Roach self::assertSame( 1628939e2c2SGreg Roach ["1 NAME /van 't White/\n2 TYPE BIRTH\n2 SPFX van 't\n2 SURN White"], 163cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1649797fe2eSGreg Roach ); 1659797fe2eSGreg Roach } 1669797fe2eSGreg Roach 1679797fe2eSGreg Roach /** 168323788f4SGreg Roach * Test new father names 169323788f4SGreg Roach */ 1709b802b22SGreg Roach public function testNewFatherNames(): void 171c1010edaSGreg Roach { 172*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 17383c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 174cb7a42eaSGreg Roach 175*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 17683c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 177cb7a42eaSGreg Roach 1785e933c21SGreg Roach self::assertSame( 1798939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 180cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 181323788f4SGreg Roach ); 182323788f4SGreg Roach } 183323788f4SGreg Roach 184323788f4SGreg Roach /** 185323788f4SGreg Roach * Test new mother names 186323788f4SGreg Roach */ 1879b802b22SGreg Roach public function testNewMotherNames(): void 188c1010edaSGreg Roach { 189*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 19083c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 191cb7a42eaSGreg Roach 192*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 19383c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 194cb7a42eaSGreg Roach 1955e933c21SGreg Roach self::assertSame( 1968939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 197cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 198323788f4SGreg Roach ); 199323788f4SGreg Roach } 200323788f4SGreg Roach 201323788f4SGreg Roach /** 202323788f4SGreg Roach * Test new parent names 203323788f4SGreg Roach */ 2049b802b22SGreg Roach public function testNewParentNames(): void 205c1010edaSGreg Roach { 206*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 20783c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 208cb7a42eaSGreg Roach 209*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 21083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 211cb7a42eaSGreg Roach 2125e933c21SGreg Roach self::assertSame( 2138939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 214cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 215323788f4SGreg Roach ); 216323788f4SGreg Roach } 217323788f4SGreg Roach 218323788f4SGreg Roach /** 219323788f4SGreg Roach * Test new husband names 220323788f4SGreg Roach */ 2219b802b22SGreg Roach public function testNewHusbandNames(): void 222c1010edaSGreg Roach { 223*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 22483c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 225cb7a42eaSGreg Roach 226*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 22783c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 228cb7a42eaSGreg Roach 2295e933c21SGreg Roach self::assertSame( 2308939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 231cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 232323788f4SGreg Roach ); 233323788f4SGreg Roach } 234323788f4SGreg Roach 235323788f4SGreg Roach /** 236323788f4SGreg Roach * Test new wife names 237323788f4SGreg Roach */ 2389b802b22SGreg Roach public function testNewWifeNames(): void 239c1010edaSGreg Roach { 240*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 24183c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 242cb7a42eaSGreg Roach 243*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 24483c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 245cb7a42eaSGreg Roach 2465e933c21SGreg Roach self::assertSame( 2478939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 248cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 249323788f4SGreg Roach ); 250323788f4SGreg Roach } 251323788f4SGreg Roach 252323788f4SGreg Roach /** 2535b2de99fSGreg Roach * Test new wife names 2545b2de99fSGreg Roach */ 2559b802b22SGreg Roach public function testNewWifeNamesWithSpfx(): void 256c1010edaSGreg Roach { 257*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 25883c91e47SGreg Roach $fact->method('value')->willReturn('Chris /van der White/'); 259cb7a42eaSGreg Roach 260*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 26183c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 262cb7a42eaSGreg Roach 2635e933c21SGreg Roach self::assertSame( 2648939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /van der White/\n2 TYPE MARRIED\n2 SPFX van der\n2 SURN White"], 265cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 2665b2de99fSGreg Roach ); 2675b2de99fSGreg Roach } 2685b2de99fSGreg Roach 2695b2de99fSGreg Roach /** 270323788f4SGreg Roach * Test new spouse names 271323788f4SGreg Roach */ 2729b802b22SGreg Roach public function testNewSpouseNames(): void 273c1010edaSGreg Roach { 274*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 27583c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 276cb7a42eaSGreg Roach 277*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 27883c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 279cb7a42eaSGreg Roach 2805e933c21SGreg Roach self::assertSame( 2818939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 282cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 283323788f4SGreg Roach ); 284323788f4SGreg Roach } 285cb7a42eaSGreg Roach 286cb7a42eaSGreg Roach /** 287cb7a42eaSGreg Roach * Prepare the environment for these tests 288cb7a42eaSGreg Roach */ 289cb7a42eaSGreg Roach protected function setUp(): void 290cb7a42eaSGreg Roach { 291cb7a42eaSGreg Roach parent::setUp(); 292cb7a42eaSGreg Roach 293cb7a42eaSGreg Roach $this->surname_tradition = new PaternalSurnameTradition(); 294cb7a42eaSGreg Roach } 295323788f4SGreg Roach} 296