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 SpanishSurnameTradition 29 */ 30class SpanishSurnameTraditionTest extends TestCase 31{ 32 private SurnameTraditionInterface $surname_tradition; 33 34 /** 35 * Test whether surnames are used 36 * 37 * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition 38 */ 39 public function testSurnames(): void 40 { 41 self::assertSame('// //', $this->surname_tradition->defaultName()); 42 } 43 44 /** 45 * Test new child names 46 * 47 * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition 48 */ 49 public function testNewChildNames(): void 50 { 51 $father_fact = $this->createStub(Fact::class); 52 $father_fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 53 54 $father = $this->createStub(Individual::class); 55 $father->method('facts')->willReturn(new Collection([$father_fact])); 56 57 $mother_fact = $this->createStub(Fact::class); 58 $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ /Lorca/'); 59 60 $mother = $this->createStub(Individual::class); 61 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 62 63 self::assertSame( 64 ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"], 65 $this->surname_tradition->newChildNames($father, $mother, 'M') 66 ); 67 68 self::assertSame( 69 ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"], 70 $this->surname_tradition->newChildNames($father, $mother, 'F') 71 ); 72 73 self::assertSame( 74 ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"], 75 $this->surname_tradition->newChildNames($father, $mother, 'U') 76 ); 77 } 78 79 /** 80 * Test new child names 81 * 82 * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition 83 */ 84 public function testNewChildNamesWithNoParentsNames(): void 85 { 86 self::assertSame( 87 ["1 NAME // //\n2 TYPE BIRTH"], 88 $this->surname_tradition->newChildNames(null, null, 'U') 89 ); 90 } 91 92 /** 93 * Test new child names 94 * 95 * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition 96 */ 97 public function testNewChildNamesCompound(): void 98 { 99 $father_fact = $this->createStub(Fact::class); 100 $father_fact->method('value')->willReturn('Gabriel /Garcia/ y /Iglesias/'); 101 102 $father = $this->createStub(Individual::class); 103 $father->method('facts')->willReturn(new Collection([$father_fact])); 104 105 $mother_fact = $this->createStub(Fact::class); 106 $mother_fact->method('value')->willReturn('Gabriel /Ruiz/ y /Lorca/'); 107 108 $mother = $this->createStub(Individual::class); 109 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 110 111 self::assertSame( 112 ["1 NAME /Garcia/ /Ruiz/\n2 TYPE BIRTH\n2 SURN Garcia,Ruiz"], 113 $this->surname_tradition->newChildNames($father, $mother, 'M') 114 ); 115 } 116 117 /** 118 * Test new parent names 119 * 120 * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition 121 */ 122 public function testNewParentNames(): void 123 { 124 $fact = $this->createStub(Fact::class); 125 $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 126 127 $individual = $this->createStub(Individual::class); 128 $individual->method('facts')->willReturn(new Collection([$fact])); 129 130 self::assertSame( 131 ["1 NAME /Garcia/ //\n2 TYPE BIRTH\n2 SURN Garcia"], 132 $this->surname_tradition->newParentNames($individual, 'M') 133 ); 134 135 self::assertSame( 136 ["1 NAME /Iglesias/ //\n2 TYPE BIRTH\n2 SURN Iglesias"], 137 $this->surname_tradition->newParentNames($individual, 'F') 138 ); 139 140 self::assertSame( 141 ["1 NAME // //\n2 TYPE BIRTH"], 142 $this->surname_tradition->newParentNames($individual, 'U') 143 ); 144 } 145 146 /** 147 * Test new spouse names 148 * 149 * @covers \Fisharebest\Webtrees\SurnameTradition\SpanishSurnameTradition 150 */ 151 public function testNewSpouseNames(): void 152 { 153 $fact = $this->createStub(Fact::class); 154 $fact->method('value')->willReturn('Gabriel /Garcia/ /Iglesias/'); 155 156 $individual = $this->createStub(Individual::class); 157 $individual->method('facts')->willReturn(new Collection([$fact])); 158 159 self::assertSame( 160 ["1 NAME // //\n2 TYPE BIRTH"], 161 $this->surname_tradition->newSpouseNames($individual, 'M') 162 ); 163 164 self::assertSame( 165 ["1 NAME // //\n2 TYPE BIRTH"], 166 $this->surname_tradition->newSpouseNames($individual, 'F') 167 ); 168 169 self::assertSame( 170 ["1 NAME // //\n2 TYPE BIRTH"], 171 $this->surname_tradition->newSpouseNames($individual, 'U') 172 ); 173 } 174 175 /** 176 * Prepare the environment for these tests 177 */ 178 protected function setUp(): void 179 { 180 parent::setUp(); 181 182 $this->surname_tradition = new SpanishSurnameTradition(); 183 } 184} 185