1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5*d11be702SGreg 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; 263cfcc809SGreg Roach 27323788f4SGreg Roach/** 28323788f4SGreg Roach * Test harness for the class PaternalSurnameTradition 29323788f4SGreg Roach */ 303cfcc809SGreg Roachclass PaternalSurnameTraditionTest extends TestCase 31c1010edaSGreg Roach{ 32c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 33323788f4SGreg Roach 34323788f4SGreg Roach /** 35c1ec7145SGreg Roach * Test whether surnames are used 3617d74f3aSGreg Roach * 3715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 3852348eb8SGreg Roach * 3952348eb8SGreg Roach * @return void 40c1ec7145SGreg Roach */ 419b802b22SGreg Roach public function testSurnames(): void 42c1010edaSGreg Roach { 43a171b6a5SGreg Roach self::assertSame('//', $this->surname_tradition->defaultName()); 44c1ec7145SGreg Roach } 45c1ec7145SGreg Roach 46c1ec7145SGreg Roach /** 47323788f4SGreg Roach * Test new child names 4817d74f3aSGreg Roach * 4915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 5052348eb8SGreg Roach * 5152348eb8SGreg Roach * @return void 52323788f4SGreg Roach */ 539b802b22SGreg Roach public function testNewChildNames(): void 54c1010edaSGreg Roach { 55cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 5683c91e47SGreg Roach $father_fact->method('value')->willReturn('John /White/'); 57cb7a42eaSGreg Roach 58cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 5983c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 60cb7a42eaSGreg Roach 61cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 6283c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 63cb7a42eaSGreg Roach 64cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 6583c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 66cb7a42eaSGreg Roach 675e933c21SGreg Roach self::assertSame( 688939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 69cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 70cb7a42eaSGreg Roach ); 71cb7a42eaSGreg Roach 72cb7a42eaSGreg Roach self::assertSame( 738939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 74cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 75cb7a42eaSGreg Roach ); 76cb7a42eaSGreg Roach 77cb7a42eaSGreg Roach self::assertSame( 788939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 79cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 80323788f4SGreg Roach ); 81323788f4SGreg Roach } 82323788f4SGreg Roach 83323788f4SGreg Roach /** 84323788f4SGreg Roach * Test new child names 8517d74f3aSGreg Roach * 8615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 8752348eb8SGreg Roach * 8852348eb8SGreg Roach * @return void 89323788f4SGreg Roach */ 909b802b22SGreg Roach public function testNewChildNamesWithSpfx(): void 91c1010edaSGreg Roach { 92cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 9383c91e47SGreg Roach $father_fact->method('value')->willReturn('John /de White/'); 94cb7a42eaSGreg Roach 95cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 9683c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 97cb7a42eaSGreg Roach 98cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 9983c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 100cb7a42eaSGreg Roach 101cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 10283c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 103cb7a42eaSGreg Roach 1045e933c21SGreg Roach self::assertSame( 1058939e2c2SGreg Roach ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"], 106cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 107323788f4SGreg Roach ); 108323788f4SGreg Roach } 109323788f4SGreg Roach 110323788f4SGreg Roach /** 1118caf8226SGreg Roach * Test new child names 1128caf8226SGreg Roach * 11315d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 11452348eb8SGreg Roach * 11552348eb8SGreg Roach * @return void 1168caf8226SGreg Roach */ 1179b802b22SGreg Roach public function testNewChildNamesWithMultipleSpfx(): void 118c1010edaSGreg Roach { 119cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 12083c91e47SGreg Roach $father_fact->method('value')->willReturn('John /van der White/'); 121cb7a42eaSGreg Roach 122cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 12383c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 124cb7a42eaSGreg Roach 125cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 12683c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 127cb7a42eaSGreg Roach 128cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 12983c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 130cb7a42eaSGreg Roach 1315e933c21SGreg Roach self::assertSame( 1328939e2c2SGreg Roach ["1 NAME /van der White/\n2 TYPE BIRTH\n2 SPFX van der\n2 SURN White"], 133cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1348caf8226SGreg Roach ); 1358caf8226SGreg Roach } 1368caf8226SGreg Roach 1378caf8226SGreg Roach /** 1389797fe2eSGreg Roach * Test new child names 1399797fe2eSGreg Roach * 14015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 14152348eb8SGreg Roach * 14252348eb8SGreg Roach * @return void 1439797fe2eSGreg Roach */ 1449b802b22SGreg Roach public function testNewChildNamesWithDutchSpfx(): void 145c1010edaSGreg Roach { 146cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 14783c91e47SGreg Roach $father_fact->method('value')->willReturn('John /\'t White/'); 148cb7a42eaSGreg Roach 149cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 15083c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 151cb7a42eaSGreg Roach 152cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 15383c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 154cb7a42eaSGreg Roach 155cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 15683c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 157cb7a42eaSGreg Roach 1585e933c21SGreg Roach self::assertSame( 1598939e2c2SGreg Roach ["1 NAME /'t White/\n2 TYPE BIRTH\n2 SPFX 't\n2 SURN White"], 160cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1619797fe2eSGreg Roach ); 1629797fe2eSGreg Roach } 1639797fe2eSGreg Roach 1649797fe2eSGreg Roach /** 1659797fe2eSGreg Roach * Test new child names 1669797fe2eSGreg Roach * 16715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 16852348eb8SGreg Roach * 16952348eb8SGreg Roach * @return void 1709797fe2eSGreg Roach */ 1719b802b22SGreg Roach public function testNewChildNamesWithMultipleDutchSpfx(): void 172c1010edaSGreg Roach { 173cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 17483c91e47SGreg Roach $father_fact->method('value')->willReturn('John /van \'t White/'); 175cb7a42eaSGreg Roach 176cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 17783c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 178cb7a42eaSGreg Roach 179cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 18083c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 181cb7a42eaSGreg Roach 182cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 18383c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 184cb7a42eaSGreg Roach 1855e933c21SGreg Roach self::assertSame( 1868939e2c2SGreg Roach ["1 NAME /van 't White/\n2 TYPE BIRTH\n2 SPFX van 't\n2 SURN White"], 187cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1889797fe2eSGreg Roach ); 1899797fe2eSGreg Roach } 1909797fe2eSGreg Roach 1919797fe2eSGreg Roach /** 192323788f4SGreg Roach * Test new father names 19317d74f3aSGreg Roach * 19415d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 19552348eb8SGreg Roach * 19652348eb8SGreg Roach * @return void 197323788f4SGreg Roach */ 1989b802b22SGreg Roach public function testNewFatherNames(): void 199c1010edaSGreg Roach { 200cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 20183c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 202cb7a42eaSGreg Roach 203cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 20483c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 205cb7a42eaSGreg Roach 2065e933c21SGreg Roach self::assertSame( 2078939e2c2SGreg Roach ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 208cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 209323788f4SGreg Roach ); 210323788f4SGreg Roach } 211323788f4SGreg Roach 212323788f4SGreg Roach /** 213323788f4SGreg Roach * Test new mother names 21417d74f3aSGreg Roach * 21515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 21652348eb8SGreg Roach * 21752348eb8SGreg Roach * @return void 218323788f4SGreg Roach */ 2199b802b22SGreg Roach public function testNewMotherNames(): void 220c1010edaSGreg Roach { 221cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 22283c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 223cb7a42eaSGreg Roach 224cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 22583c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 226cb7a42eaSGreg Roach 2275e933c21SGreg Roach self::assertSame( 2288939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 229cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 230323788f4SGreg Roach ); 231323788f4SGreg Roach } 232323788f4SGreg Roach 233323788f4SGreg Roach /** 234323788f4SGreg Roach * Test new parent names 23517d74f3aSGreg Roach * 23615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 23752348eb8SGreg Roach * 23852348eb8SGreg Roach * @return void 239323788f4SGreg Roach */ 2409b802b22SGreg Roach public function testNewParentNames(): void 241c1010edaSGreg Roach { 242cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 24383c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 244cb7a42eaSGreg Roach 245cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 24683c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 247cb7a42eaSGreg Roach 2485e933c21SGreg Roach self::assertSame( 2498939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 250cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 251323788f4SGreg Roach ); 252323788f4SGreg Roach } 253323788f4SGreg Roach 254323788f4SGreg Roach /** 255323788f4SGreg Roach * Test new husband names 25617d74f3aSGreg Roach * 25715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 25852348eb8SGreg Roach * 25952348eb8SGreg Roach * @return void 260323788f4SGreg Roach */ 2619b802b22SGreg Roach public function testNewHusbandNames(): void 262c1010edaSGreg Roach { 263cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 26483c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 265cb7a42eaSGreg Roach 266cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 26783c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 268cb7a42eaSGreg Roach 2695e933c21SGreg Roach self::assertSame( 2708939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 271cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 272323788f4SGreg Roach ); 273323788f4SGreg Roach } 274323788f4SGreg Roach 275323788f4SGreg Roach /** 276323788f4SGreg Roach * Test new wife names 27717d74f3aSGreg Roach * 27815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 27952348eb8SGreg Roach * 28052348eb8SGreg Roach * @return void 281323788f4SGreg Roach */ 2829b802b22SGreg Roach public function testNewWifeNames(): void 283c1010edaSGreg Roach { 284cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 28583c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 286cb7a42eaSGreg Roach 287cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 28883c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 289cb7a42eaSGreg Roach 2905e933c21SGreg Roach self::assertSame( 2918939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 292cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 293323788f4SGreg Roach ); 294323788f4SGreg Roach } 295323788f4SGreg Roach 296323788f4SGreg Roach /** 2975b2de99fSGreg Roach * Test new wife names 2985b2de99fSGreg Roach * 29915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 30052348eb8SGreg Roach * 30152348eb8SGreg Roach * @return void 3025b2de99fSGreg Roach */ 3039b802b22SGreg Roach public function testNewWifeNamesWithSpfx(): void 304c1010edaSGreg Roach { 305cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 30683c91e47SGreg Roach $fact->method('value')->willReturn('Chris /van der White/'); 307cb7a42eaSGreg Roach 308cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 30983c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 310cb7a42eaSGreg Roach 3115e933c21SGreg Roach self::assertSame( 3128939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH", "1 NAME /van der White/\n2 TYPE MARRIED\n2 SPFX van der\n2 SURN White"], 313cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 3145b2de99fSGreg Roach ); 3155b2de99fSGreg Roach } 3165b2de99fSGreg Roach 3175b2de99fSGreg Roach /** 318323788f4SGreg Roach * Test new spouse names 31917d74f3aSGreg Roach * 32015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 32152348eb8SGreg Roach * 32252348eb8SGreg Roach * @return void 323323788f4SGreg Roach */ 3249b802b22SGreg Roach public function testNewSpouseNames(): void 325c1010edaSGreg Roach { 326cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 32783c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 328cb7a42eaSGreg Roach 329cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 33083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 331cb7a42eaSGreg Roach 3325e933c21SGreg Roach self::assertSame( 3338939e2c2SGreg Roach ["1 NAME //\n2 TYPE BIRTH"], 334cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 335323788f4SGreg Roach ); 336323788f4SGreg Roach } 337cb7a42eaSGreg Roach 338cb7a42eaSGreg Roach /** 339cb7a42eaSGreg Roach * Prepare the environment for these tests 340cb7a42eaSGreg Roach * 341cb7a42eaSGreg Roach * @return void 342cb7a42eaSGreg Roach */ 343cb7a42eaSGreg Roach protected function setUp(): void 344cb7a42eaSGreg Roach { 345cb7a42eaSGreg Roach parent::setUp(); 346cb7a42eaSGreg Roach 347cb7a42eaSGreg Roach $this->surname_tradition = new PaternalSurnameTradition(); 348cb7a42eaSGreg Roach } 349323788f4SGreg Roach} 350