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