1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 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 /** 35323788f4SGreg Roach * Test whether married surnames are used 3617d74f3aSGreg Roach * 3715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 3852348eb8SGreg Roach * 3952348eb8SGreg Roach * @return void 40323788f4SGreg Roach */ 419b802b22SGreg Roach public function testMarriedSurnames(): void 42c1010edaSGreg Roach { 435e933c21SGreg Roach self::assertTrue($this->surname_tradition->hasMarriedNames()); 44323788f4SGreg Roach } 45323788f4SGreg Roach 46323788f4SGreg Roach /** 47c1ec7145SGreg Roach * Test whether surnames are used 4817d74f3aSGreg Roach * 4915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 5052348eb8SGreg Roach * 5152348eb8SGreg Roach * @return void 52c1ec7145SGreg Roach */ 539b802b22SGreg Roach public function testSurnames(): void 54c1010edaSGreg Roach { 555e933c21SGreg Roach self::assertTrue($this->surname_tradition->hasSurnames()); 56c1ec7145SGreg Roach } 57c1ec7145SGreg Roach 58c1ec7145SGreg Roach /** 59323788f4SGreg Roach * Test new child names 6017d74f3aSGreg Roach * 6115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 6252348eb8SGreg Roach * 6352348eb8SGreg Roach * @return void 64323788f4SGreg Roach */ 659b802b22SGreg Roach public function testNewChildNames(): void 66c1010edaSGreg Roach { 67cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 68*83c91e47SGreg Roach $father_fact->method('value')->willReturn('John /White/'); 69cb7a42eaSGreg Roach 70cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 71*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 72cb7a42eaSGreg Roach 73cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 74*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /Black/'); 75cb7a42eaSGreg Roach 76cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 77*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 78cb7a42eaSGreg Roach 795e933c21SGreg Roach self::assertSame( 80cb7a42eaSGreg Roach ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 81cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 82cb7a42eaSGreg Roach ); 83cb7a42eaSGreg Roach 84cb7a42eaSGreg Roach self::assertSame( 85cb7a42eaSGreg Roach ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 86cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 87cb7a42eaSGreg Roach ); 88cb7a42eaSGreg Roach 89cb7a42eaSGreg Roach self::assertSame( 90cb7a42eaSGreg Roach ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 91cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 92323788f4SGreg Roach ); 93323788f4SGreg Roach } 94323788f4SGreg Roach 95323788f4SGreg Roach /** 96323788f4SGreg Roach * Test new child names 9717d74f3aSGreg Roach * 9815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 9952348eb8SGreg Roach * 10052348eb8SGreg Roach * @return void 101323788f4SGreg Roach */ 1029b802b22SGreg Roach public function testNewChildNamesWithSpfx(): void 103c1010edaSGreg Roach { 104cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 105*83c91e47SGreg Roach $father_fact->method('value')->willReturn('John /de White/'); 106cb7a42eaSGreg Roach 107cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 108*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 109cb7a42eaSGreg Roach 110cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 111*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 112cb7a42eaSGreg Roach 113cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 114*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 115cb7a42eaSGreg Roach 1165e933c21SGreg Roach self::assertSame( 117cb7a42eaSGreg Roach ["1 NAME /de White/\n2 TYPE birth\n2 SPFX de\n2 SURN White"], 118cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 119323788f4SGreg Roach ); 120323788f4SGreg Roach } 121323788f4SGreg Roach 122323788f4SGreg Roach /** 1238caf8226SGreg Roach * Test new child names 1248caf8226SGreg Roach * 12515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 12652348eb8SGreg Roach * 12752348eb8SGreg Roach * @return void 1288caf8226SGreg Roach */ 1299b802b22SGreg Roach public function testNewChildNamesWithMultipleSpfx(): void 130c1010edaSGreg Roach { 131cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 132*83c91e47SGreg Roach $father_fact->method('value')->willReturn('John /van der White/'); 133cb7a42eaSGreg Roach 134cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 135*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 136cb7a42eaSGreg Roach 137cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 138*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 139cb7a42eaSGreg Roach 140cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 141*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 142cb7a42eaSGreg Roach 1435e933c21SGreg Roach self::assertSame( 144cb7a42eaSGreg Roach ["1 NAME /van der White/\n2 TYPE birth\n2 SPFX van der\n2 SURN White"], 145cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1468caf8226SGreg Roach ); 1478caf8226SGreg Roach } 1488caf8226SGreg Roach 1498caf8226SGreg Roach /** 1509797fe2eSGreg Roach * Test new child names 1519797fe2eSGreg Roach * 15215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 15352348eb8SGreg Roach * 15452348eb8SGreg Roach * @return void 1559797fe2eSGreg Roach */ 1569b802b22SGreg Roach public function testNewChildNamesWithDutchSpfx(): void 157c1010edaSGreg Roach { 158cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 159*83c91e47SGreg Roach $father_fact->method('value')->willReturn('John /\'t White/'); 160cb7a42eaSGreg Roach 161cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 162*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 163cb7a42eaSGreg Roach 164cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 165*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 166cb7a42eaSGreg Roach 167cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 168*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 169cb7a42eaSGreg Roach 1705e933c21SGreg Roach self::assertSame( 171cb7a42eaSGreg Roach ["1 NAME /'t White/\n2 TYPE birth\n2 SPFX 't\n2 SURN White"], 172cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 1739797fe2eSGreg Roach ); 1749797fe2eSGreg Roach } 1759797fe2eSGreg Roach 1769797fe2eSGreg Roach /** 1779797fe2eSGreg Roach * Test new child names 1789797fe2eSGreg Roach * 17915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 18052348eb8SGreg Roach * 18152348eb8SGreg Roach * @return void 1829797fe2eSGreg Roach */ 1839b802b22SGreg Roach public function testNewChildNamesWithMultipleDutchSpfx(): void 184c1010edaSGreg Roach { 185cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 186*83c91e47SGreg Roach $father_fact->method('value')->willReturn('John /van \'t White/'); 187cb7a42eaSGreg Roach 188cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 189*83c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 190cb7a42eaSGreg Roach 191cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 192*83c91e47SGreg Roach $mother_fact->method('value')->willReturn('Mary /van Black/'); 193cb7a42eaSGreg Roach 194cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 195*83c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 196cb7a42eaSGreg Roach 1975e933c21SGreg Roach self::assertSame( 198cb7a42eaSGreg Roach ["1 NAME /van 't White/\n2 TYPE birth\n2 SPFX van 't\n2 SURN White"], 199cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 2009797fe2eSGreg Roach ); 2019797fe2eSGreg Roach } 2029797fe2eSGreg Roach 2039797fe2eSGreg Roach /** 204323788f4SGreg Roach * Test new father names 20517d74f3aSGreg Roach * 20615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 20752348eb8SGreg Roach * 20852348eb8SGreg Roach * @return void 209323788f4SGreg Roach */ 2109b802b22SGreg Roach public function testNewFatherNames(): void 211c1010edaSGreg Roach { 212cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 213*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 214cb7a42eaSGreg Roach 215cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 216*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 217cb7a42eaSGreg Roach 2185e933c21SGreg Roach self::assertSame( 219cb7a42eaSGreg Roach ["1 NAME /White/\n2 TYPE birth\n2 SURN White"], 220cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 221323788f4SGreg Roach ); 222323788f4SGreg Roach } 223323788f4SGreg Roach 224323788f4SGreg Roach /** 225323788f4SGreg Roach * Test new mother names 22617d74f3aSGreg Roach * 22715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 22852348eb8SGreg Roach * 22952348eb8SGreg Roach * @return void 230323788f4SGreg Roach */ 2319b802b22SGreg Roach public function testNewMotherNames(): void 232c1010edaSGreg Roach { 233cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 234*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 235cb7a42eaSGreg Roach 236cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 237*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 238cb7a42eaSGreg Roach 2395e933c21SGreg Roach self::assertSame( 240cb7a42eaSGreg Roach ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], 241cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 242323788f4SGreg Roach ); 243323788f4SGreg Roach } 244323788f4SGreg Roach 245323788f4SGreg Roach /** 246323788f4SGreg Roach * Test new parent names 24717d74f3aSGreg Roach * 24815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 24952348eb8SGreg Roach * 25052348eb8SGreg Roach * @return void 251323788f4SGreg Roach */ 2529b802b22SGreg Roach public function testNewParentNames(): void 253c1010edaSGreg Roach { 254cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 255*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 256cb7a42eaSGreg Roach 257cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 258*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 259cb7a42eaSGreg Roach 2605e933c21SGreg Roach self::assertSame( 261cb7a42eaSGreg Roach ["1 NAME //\n2 TYPE birth"], 262cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 263323788f4SGreg Roach ); 264323788f4SGreg Roach } 265323788f4SGreg Roach 266323788f4SGreg Roach /** 267323788f4SGreg Roach * Test new husband names 26817d74f3aSGreg Roach * 26915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 27052348eb8SGreg Roach * 27152348eb8SGreg Roach * @return void 272323788f4SGreg Roach */ 2739b802b22SGreg Roach public function testNewHusbandNames(): void 274c1010edaSGreg Roach { 275cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 276*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 277cb7a42eaSGreg Roach 278cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 279*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 280cb7a42eaSGreg Roach 2815e933c21SGreg Roach self::assertSame( 282cb7a42eaSGreg Roach ["1 NAME //\n2 TYPE birth"], 283cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 284323788f4SGreg Roach ); 285323788f4SGreg Roach } 286323788f4SGreg Roach 287323788f4SGreg Roach /** 288323788f4SGreg Roach * Test new wife names 28917d74f3aSGreg Roach * 29015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 29152348eb8SGreg Roach * 29252348eb8SGreg Roach * @return void 293323788f4SGreg Roach */ 2949b802b22SGreg Roach public function testNewWifeNames(): void 295c1010edaSGreg Roach { 296cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 297*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 298cb7a42eaSGreg Roach 299cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 300*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 301cb7a42eaSGreg Roach 3025e933c21SGreg Roach self::assertSame( 303cb7a42eaSGreg Roach ["1 NAME //\n2 TYPE birth", "1 NAME /White/\n2 TYPE married\n2 SURN White"], 304cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 305323788f4SGreg Roach ); 306323788f4SGreg Roach } 307323788f4SGreg Roach 308323788f4SGreg Roach /** 3095b2de99fSGreg Roach * Test new wife names 3105b2de99fSGreg Roach * 31115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 31252348eb8SGreg Roach * 31352348eb8SGreg Roach * @return void 3145b2de99fSGreg Roach */ 3159b802b22SGreg Roach public function testNewWifeNamesWithSpfx(): void 316c1010edaSGreg Roach { 317cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 318*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /van der White/'); 319cb7a42eaSGreg Roach 320cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 321*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 322cb7a42eaSGreg Roach 3235e933c21SGreg Roach self::assertSame( 324cb7a42eaSGreg Roach ["1 NAME //\n2 TYPE birth", "1 NAME /van der White/\n2 TYPE married\n2 SPFX van der\n2 SURN White"], 325cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 3265b2de99fSGreg Roach ); 3275b2de99fSGreg Roach } 3285b2de99fSGreg Roach 3295b2de99fSGreg Roach /** 330323788f4SGreg Roach * Test new spouse names 33117d74f3aSGreg Roach * 33215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PaternalSurnameTradition 33352348eb8SGreg Roach * 33452348eb8SGreg Roach * @return void 335323788f4SGreg Roach */ 3369b802b22SGreg Roach public function testNewSpouseNames(): void 337c1010edaSGreg Roach { 338cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 339*83c91e47SGreg Roach $fact->method('value')->willReturn('Chris /White/'); 340cb7a42eaSGreg Roach 341cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 342*83c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 343cb7a42eaSGreg Roach 3445e933c21SGreg Roach self::assertSame( 345cb7a42eaSGreg Roach ["1 NAME //\n2 TYPE birth"], 346cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 347323788f4SGreg Roach ); 348323788f4SGreg Roach } 349cb7a42eaSGreg Roach 350cb7a42eaSGreg Roach /** 351cb7a42eaSGreg Roach * Prepare the environment for these tests 352cb7a42eaSGreg Roach * 353cb7a42eaSGreg Roach * @return void 354cb7a42eaSGreg Roach */ 355cb7a42eaSGreg Roach protected function setUp(): void 356cb7a42eaSGreg Roach { 357cb7a42eaSGreg Roach parent::setUp(); 358cb7a42eaSGreg Roach 359cb7a42eaSGreg Roach $this->surname_tradition = new PaternalSurnameTradition(); 360cb7a42eaSGreg Roach } 361323788f4SGreg Roach} 362