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#[CoversClass(PortugueseSurnameTradition::class)] 293cfcc809SGreg Roachclass PortugueseSurnameTraditionTest extends TestCase 30c1010edaSGreg Roach{ 31c4943cffSGreg Roach private SurnameTraditionInterface $surname_tradition; 32323788f4SGreg Roach 33323788f4SGreg Roach /** 34323788f4SGreg Roach * Prepare the environment for these tests 35323788f4SGreg Roach */ 365c48bcd6SGreg Roach protected function setUp(): void 37c1010edaSGreg Roach { 380115bc16SGreg Roach parent::setUp(); 390115bc16SGreg Roach 4074d6dc0eSGreg Roach $this->surname_tradition = new PortugueseSurnameTradition(); 41323788f4SGreg Roach } 42323788f4SGreg Roach 43323788f4SGreg Roach /** 44c1ec7145SGreg Roach * Test whether surnames are used 45c1ec7145SGreg Roach */ 469b802b22SGreg Roach public function testSurnames(): void 47c1010edaSGreg Roach { 48a171b6a5SGreg Roach self::assertSame('// //', $this->surname_tradition->defaultName()); 49c1ec7145SGreg Roach } 50c1ec7145SGreg Roach 51c1ec7145SGreg Roach /** 52323788f4SGreg Roach * Test new child names 53323788f4SGreg Roach */ 549b802b22SGreg Roach public function testNewChildNames(): void 55c1010edaSGreg Roach { 56*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 5783c91e47SGreg Roach $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 58cb7a42eaSGreg Roach 59*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 6083c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 61cb7a42eaSGreg Roach 62*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 6383c91e47SGreg Roach $mother_fact->method('value')->willReturn('Maria /Ruiz/ /Lorca/'); 64cb7a42eaSGreg Roach 65*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 6683c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 67cb7a42eaSGreg Roach 685e933c21SGreg Roach self::assertSame( 698939e2c2SGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 70cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 71cb7a42eaSGreg Roach ); 72cb7a42eaSGreg Roach 73cb7a42eaSGreg Roach self::assertSame( 748939e2c2SGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 75cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'F') 76cb7a42eaSGreg Roach ); 77cb7a42eaSGreg Roach 78cb7a42eaSGreg Roach self::assertSame( 798939e2c2SGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 80cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'U') 81323788f4SGreg Roach ); 82323788f4SGreg Roach } 83323788f4SGreg Roach 84323788f4SGreg Roach /** 85323788f4SGreg Roach * Test new child names 86323788f4SGreg Roach */ 879b802b22SGreg Roach public function testNewChildNamesWithNoParentsNames(): void 88c1010edaSGreg Roach { 895e933c21SGreg Roach self::assertSame( 908939e2c2SGreg Roach ["1 NAME // //\n2 TYPE BIRTH"], 91cb7a42eaSGreg Roach $this->surname_tradition->newChildNames(null, null, 'U') 921677a03aSGreg Roach ); 931677a03aSGreg Roach } 941677a03aSGreg Roach 951677a03aSGreg Roach /** 961677a03aSGreg Roach * Test new child names 971677a03aSGreg Roach */ 989b802b22SGreg Roach public function testNewChildNamesCompunds(): void 99c1010edaSGreg Roach { 100*62ff2f18SGreg Roach $father_fact = $this->createMock(Fact::class); 10183c91e47SGreg Roach $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/'); 102323788f4SGreg Roach 103*62ff2f18SGreg Roach $father = $this->createMock(Individual::class); 10483c91e47SGreg Roach $father->method('facts')->willReturn(new Collection([$father_fact])); 105323788f4SGreg Roach 106*62ff2f18SGreg Roach $mother_fact = $this->createMock(Fact::class); 10783c91e47SGreg Roach $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/'); 108cb7a42eaSGreg Roach 109*62ff2f18SGreg Roach $mother = $this->createMock(Individual::class); 11083c91e47SGreg Roach $mother->method('facts')->willReturn(new Collection([$mother_fact])); 111cb7a42eaSGreg Roach 1125e933c21SGreg Roach self::assertSame( 1138939e2c2SGreg Roach ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 114cb7a42eaSGreg Roach $this->surname_tradition->newChildNames($father, $mother, 'M') 115323788f4SGreg Roach ); 116323788f4SGreg Roach } 117323788f4SGreg Roach 118323788f4SGreg Roach /** 119323788f4SGreg Roach * Test new parent names 120323788f4SGreg Roach */ 1219b802b22SGreg Roach public function testNewParentNames(): void 122c1010edaSGreg Roach { 123*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 12483c91e47SGreg Roach $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 125323788f4SGreg Roach 126*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 12783c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 128323788f4SGreg Roach 1295e933c21SGreg Roach self::assertSame( 1308939e2c2SGreg Roach ["1 NAME // /Garcia/\n2 TYPE BIRTH\n2 SURN Garcia"], 131cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'M') 132cb7a42eaSGreg Roach ); 133cb7a42eaSGreg Roach self::assertSame( 1348939e2c2SGreg Roach ["1 NAME // /Iglesias/\n2 TYPE BIRTH\n2 SURN Iglesias"], 135cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'F') 136cb7a42eaSGreg Roach ); 137cb7a42eaSGreg Roach 138cb7a42eaSGreg Roach self::assertSame( 1398939e2c2SGreg Roach ["1 NAME // //\n2 TYPE BIRTH"], 140cb7a42eaSGreg Roach $this->surname_tradition->newParentNames($individual, 'U') 141323788f4SGreg Roach ); 142323788f4SGreg Roach } 143323788f4SGreg Roach 144323788f4SGreg Roach /** 145323788f4SGreg Roach * Test new spouse names 146323788f4SGreg Roach */ 1479b802b22SGreg Roach public function testNewSpouseNames(): void 148c1010edaSGreg Roach { 149*62ff2f18SGreg Roach $fact = $this->createMock(Fact::class); 15083c91e47SGreg Roach $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 151cb7a42eaSGreg Roach 152*62ff2f18SGreg Roach $individual = $this->createMock(Individual::class); 15383c91e47SGreg Roach $individual->method('facts')->willReturn(new Collection([$fact])); 154cb7a42eaSGreg Roach 1555e933c21SGreg Roach self::assertSame( 1568939e2c2SGreg Roach ["1 NAME // //\n2 TYPE BIRTH"], 157cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'M') 158cb7a42eaSGreg Roach ); 159cb7a42eaSGreg Roach 160cb7a42eaSGreg Roach self::assertSame( 1618939e2c2SGreg Roach ["1 NAME // //\n2 TYPE BIRTH"], 162cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'F') 163cb7a42eaSGreg Roach ); 164cb7a42eaSGreg Roach 165cb7a42eaSGreg Roach self::assertSame( 1668939e2c2SGreg Roach ["1 NAME // //\n2 TYPE BIRTH"], 167cb7a42eaSGreg Roach $this->surname_tradition->newSpouseNames($individual, 'U') 168323788f4SGreg Roach ); 169323788f4SGreg Roach } 170323788f4SGreg Roach} 171