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