1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2023 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\SurnameTradition; 21 22use Fisharebest\Webtrees\Fact; 23use Fisharebest\Webtrees\Individual; 24use Fisharebest\Webtrees\TestCase; 25use Illuminate\Support\Collection; 26 27/** 28 * Test harness for the class PortugueseSurnameTradition 29 */ 30class PortugueseSurnameTraditionTest extends TestCase 31{ 32 private SurnameTraditionInterface $surname_tradition; 33 34 /** 35 * Prepare the environment for these tests 36 */ 37 protected function setUp(): void 38 { 39 parent::setUp(); 40 41 $this->surname_tradition = new PortugueseSurnameTradition(); 42 } 43 44 /** 45 * Test whether surnames are used 46 * 47 * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 48 */ 49 public function testSurnames(): void 50 { 51 self::assertSame('// //', $this->surname_tradition->defaultName()); 52 } 53 54 /** 55 * Test new child names 56 * 57 * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 58 */ 59 public function testNewChildNames(): void 60 { 61 $father_fact = $this->createStub(Fact::class); 62 $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 63 64 $father = $this->createStub(Individual::class); 65 $father->method('facts')->willReturn(new Collection([$father_fact])); 66 67 $mother_fact = $this->createStub(Fact::class); 68 $mother_fact->method('value')->willReturn('Maria /Ruiz/ /Lorca/'); 69 70 $mother = $this->createStub(Individual::class); 71 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 72 73 self::assertSame( 74 ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 75 $this->surname_tradition->newChildNames($father, $mother, 'M') 76 ); 77 78 self::assertSame( 79 ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 80 $this->surname_tradition->newChildNames($father, $mother, 'F') 81 ); 82 83 self::assertSame( 84 ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 85 $this->surname_tradition->newChildNames($father, $mother, 'U') 86 ); 87 } 88 89 /** 90 * Test new child names 91 * 92 * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 93 */ 94 public function testNewChildNamesWithNoParentsNames(): void 95 { 96 self::assertSame( 97 ["1 NAME // //\n2 TYPE BIRTH"], 98 $this->surname_tradition->newChildNames(null, null, 'U') 99 ); 100 } 101 102 /** 103 * Test new child names 104 * 105 * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 106 */ 107 public function testNewChildNamesCompunds(): void 108 { 109 $father_fact = $this->createStub(Fact::class); 110 $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/'); 111 112 $father = $this->createStub(Individual::class); 113 $father->method('facts')->willReturn(new Collection([$father_fact])); 114 115 $mother_fact = $this->createStub(Fact::class); 116 $mother_fact->method('value')->willReturn('Maria /Ruiz/ y /Lorca/'); 117 118 $mother = $this->createStub(Individual::class); 119 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 120 121 self::assertSame( 122 ["1 NAME /Iglesias/ /Lorca/\n2 TYPE BIRTH\n2 SURN Iglesias,Lorca"], 123 $this->surname_tradition->newChildNames($father, $mother, 'M') 124 ); 125 } 126 127 /** 128 * Test new parent names 129 * 130 * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 131 */ 132 public function testNewParentNames(): void 133 { 134 $fact = $this->createStub(Fact::class); 135 $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 136 137 $individual = $this->createStub(Individual::class); 138 $individual->method('facts')->willReturn(new Collection([$fact])); 139 140 self::assertSame( 141 ["1 NAME // /Garcia/\n2 TYPE BIRTH\n2 SURN Garcia"], 142 $this->surname_tradition->newParentNames($individual, 'M') 143 ); 144 self::assertSame( 145 ["1 NAME // /Iglesias/\n2 TYPE BIRTH\n2 SURN Iglesias"], 146 $this->surname_tradition->newParentNames($individual, 'F') 147 ); 148 149 self::assertSame( 150 ["1 NAME // //\n2 TYPE BIRTH"], 151 $this->surname_tradition->newParentNames($individual, 'U') 152 ); 153 } 154 155 /** 156 * Test new spouse names 157 * 158 * @covers \Fisharebest\Webtrees\SurnameTradition\PortugueseSurnameTradition 159 */ 160 public function testNewSpouseNames(): void 161 { 162 $fact = $this->createStub(Fact::class); 163 $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 164 165 $individual = $this->createStub(Individual::class); 166 $individual->method('facts')->willReturn(new Collection([$fact])); 167 168 self::assertSame( 169 ["1 NAME // //\n2 TYPE BIRTH"], 170 $this->surname_tradition->newSpouseNames($individual, 'M') 171 ); 172 173 self::assertSame( 174 ["1 NAME // //\n2 TYPE BIRTH"], 175 $this->surname_tradition->newSpouseNames($individual, 'F') 176 ); 177 178 self::assertSame( 179 ["1 NAME // //\n2 TYPE BIRTH"], 180 $this->surname_tradition->newSpouseNames($individual, 'U') 181 ); 182 } 183} 184