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/** 28c4943cffSGreg Roach * Test harness for the class PortugueseSurnameTradition 29323788f4SGreg Roach */ 303cfcc809SGreg Roachclass PortugueseSurnameTraditionTest extends TestCase 31c1010edaSGreg Roach{ 32c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 33323788f4SGreg Roach 34323788f4SGreg Roach /** 35323788f4SGreg Roach * Prepare the environment for these tests 3652348eb8SGreg Roach * 3752348eb8SGreg Roach * @return void 38323788f4SGreg Roach */ 395c48bcd6SGreg Roach protected function setUp(): void 40c1010edaSGreg Roach { 410115bc16SGreg Roach parent::setUp(); 420115bc16SGreg Roach 4374d6dc0eSGreg Roach $this->surname_tradition = new PortugueseSurnameTradition(); 44323788f4SGreg Roach } 45323788f4SGreg Roach 46323788f4SGreg Roach /** 47c1ec7145SGreg Roach * Test whether surnames are used 4817d74f3aSGreg Roach * 4915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 5052348eb8SGreg Roach * 5152348eb8SGreg Roach * @return void 52c1ec7145SGreg Roach */ 539b802b22SGreg Roach public function testSurnames(): void 54c1010edaSGreg Roach { 55*a171b6a5SGreg Roach self::assertSame('// //', $this->surname_tradition->defaultName()); 56c1ec7145SGreg Roach } 57c1ec7145SGreg Roach 58c1ec7145SGreg Roach /** 59323788f4SGreg Roach * Test new child names 6017d74f3aSGreg Roach * 6115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 6252348eb8SGreg Roach * 6352348eb8SGreg Roach * @return void 64323788f4SGreg Roach */ 659b802b22SGreg Roach public function testNewChildNames(): void 66c1010edaSGreg Roach { 67cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 6883c91e47SGreg Roach $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 69cb7a42eaSGreg Roach 70cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 7183c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 72cb7a42eaSGreg Roach 73cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 7483c91e47SGreg Roach $mother_fact->method('value')->willReturn('Maria /Ruiz/ /Lorca/'); 75cb7a42eaSGreg Roach 76cb7a42eaSGreg Roach $mother = $this->createStub(Individual::class); 7783c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 78cb7a42eaSGreg Roach 795e933c21SGreg Roach self::assertSame( 80cb7a42eaSGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], 81cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 82cb7a42eaSGreg Roach ); 83cb7a42eaSGreg Roach 84cb7a42eaSGreg Roach self::assertSame( 85cb7a42eaSGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], 86cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 87cb7a42eaSGreg Roach ); 88cb7a42eaSGreg Roach 89cb7a42eaSGreg Roach self::assertSame( 90cb7a42eaSGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], 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\PortugueseSurnameTradition 9952348eb8SGreg Roach * 10052348eb8SGreg Roach * @return void 101323788f4SGreg Roach */ 1029b802b22SGreg Roach public function testNewChildNamesWithNoParentsNames(): void 103c1010edaSGreg Roach { 1045e933c21SGreg Roach self::assertSame( 105cb7a42eaSGreg Roach ["1 NAME // //\n2 TYPE birth"], 106cb7a42eaSGreg Roach $this->surname_tradition->newChildNames(null, null, 'U') 1071677a03aSGreg Roach ); 1081677a03aSGreg Roach } 1091677a03aSGreg Roach 1101677a03aSGreg Roach /** 1111677a03aSGreg Roach * Test new child names 11217d74f3aSGreg Roach * 11315d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 11452348eb8SGreg Roach * 11552348eb8SGreg Roach * @return void 1161677a03aSGreg Roach */ 1179b802b22SGreg Roach public function testNewChildNamesCompunds(): void 118c1010edaSGreg Roach { 119cb7a42eaSGreg Roach $father_fact = $this->createStub(Fact::class); 12083c91e47SGreg Roach $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/'); 121323788f4SGreg Roach 122cb7a42eaSGreg Roach $father = $this->createStub(Individual::class); 12383c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 124323788f4SGreg Roach 125cb7a42eaSGreg Roach $mother_fact = $this->createStub(Fact::class); 12683c91e47SGreg Roach $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/'); 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( 132cb7a42eaSGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE birth\n2 SURN Iglesias,Lorca"], 133cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 134323788f4SGreg Roach ); 135323788f4SGreg Roach } 136323788f4SGreg Roach 137323788f4SGreg Roach /** 138323788f4SGreg Roach * Test new parent names 13917d74f3aSGreg Roach * 14015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 14152348eb8SGreg Roach * 14252348eb8SGreg Roach * @return void 143323788f4SGreg Roach */ 1449b802b22SGreg Roach public function testNewParentNames(): void 145c1010edaSGreg Roach { 146cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 14783c91e47SGreg Roach $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 148323788f4SGreg Roach 149cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 15083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 151323788f4SGreg Roach 1525e933c21SGreg Roach self::assertSame( 153cb7a42eaSGreg Roach ["1 NAME // /Garcia/\n2 TYPE birth\n2 SURN Garcia"], 154cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 155cb7a42eaSGreg Roach ); 156cb7a42eaSGreg Roach self::assertSame( 157cb7a42eaSGreg Roach ["1 NAME // /Iglesias/\n2 TYPE birth\n2 SURN Iglesias"], 158cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 159cb7a42eaSGreg Roach ); 160cb7a42eaSGreg Roach 161cb7a42eaSGreg Roach self::assertSame( 162cb7a42eaSGreg Roach ["1 NAME // //\n2 TYPE birth"], 163cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 164323788f4SGreg Roach ); 165323788f4SGreg Roach } 166323788f4SGreg Roach 167323788f4SGreg Roach /** 168323788f4SGreg Roach * Test new spouse names 16917d74f3aSGreg Roach * 17015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 17152348eb8SGreg Roach * 17252348eb8SGreg Roach * @return void 173323788f4SGreg Roach */ 1749b802b22SGreg Roach public function testNewSpouseNames(): void 175c1010edaSGreg Roach { 176cb7a42eaSGreg Roach $fact = $this->createStub(Fact::class); 17783c91e47SGreg Roach $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 178cb7a42eaSGreg Roach 179cb7a42eaSGreg Roach $individual = $this->createStub(Individual::class); 18083c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 181cb7a42eaSGreg Roach 1825e933c21SGreg Roach self::assertSame( 183cb7a42eaSGreg Roach ["1 NAME // //\n2 TYPE birth"], 184cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 185cb7a42eaSGreg Roach ); 186cb7a42eaSGreg Roach 187cb7a42eaSGreg Roach self::assertSame( 188cb7a42eaSGreg Roach ["1 NAME // //\n2 TYPE birth"], 189cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 190cb7a42eaSGreg Roach ); 191cb7a42eaSGreg Roach 192cb7a42eaSGreg Roach self::assertSame( 193cb7a42eaSGreg Roach ["1 NAME // //\n2 TYPE birth"], 194cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 195323788f4SGreg Roach ); 196323788f4SGreg Roach } 197323788f4SGreg Roach} 198