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(PaternalSurnameTradition::class)] 30class PaternalSurnameTraditionTest 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->createStub(Fact::class); 48 $father_fact->method('value')->willReturn('John /White/'); 49 50 $father = $this->createStub(Individual::class); 51 $father->method('facts')->willReturn(new Collection([$father_fact])); 52 53 $mother_fact = $this->createStub(Fact::class); 54 $mother_fact->method('value')->willReturn('Mary /Black/'); 55 56 $mother = $this->createStub(Individual::class); 57 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 58 59 self::assertSame( 60 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 61 $this->surname_tradition->newChildNames($father, $mother, 'M') 62 ); 63 64 self::assertSame( 65 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 66 $this->surname_tradition->newChildNames($father, $mother, 'F') 67 ); 68 69 self::assertSame( 70 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 71 $this->surname_tradition->newChildNames($father, $mother, 'U') 72 ); 73 } 74 75 /** 76 * Test new child names 77 */ 78 public function testNewChildNamesWithSpfx(): void 79 { 80 $father_fact = $this->createStub(Fact::class); 81 $father_fact->method('value')->willReturn('John /de White/'); 82 83 $father = $this->createStub(Individual::class); 84 $father->method('facts')->willReturn(new Collection([$father_fact])); 85 86 $mother_fact = $this->createStub(Fact::class); 87 $mother_fact->method('value')->willReturn('Mary /van Black/'); 88 89 $mother = $this->createStub(Individual::class); 90 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 91 92 self::assertSame( 93 ["1 NAME /de White/\n2 TYPE BIRTH\n2 SPFX de\n2 SURN White"], 94 $this->surname_tradition->newChildNames($father, $mother, 'U') 95 ); 96 } 97 98 /** 99 * Test new child names 100 */ 101 public function testNewChildNamesWithMultipleSpfx(): void 102 { 103 $father_fact = $this->createStub(Fact::class); 104 $father_fact->method('value')->willReturn('John /van der White/'); 105 106 $father = $this->createStub(Individual::class); 107 $father->method('facts')->willReturn(new Collection([$father_fact])); 108 109 $mother_fact = $this->createStub(Fact::class); 110 $mother_fact->method('value')->willReturn('Mary /van Black/'); 111 112 $mother = $this->createStub(Individual::class); 113 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 114 115 self::assertSame( 116 ["1 NAME /van der White/\n2 TYPE BIRTH\n2 SPFX van der\n2 SURN White"], 117 $this->surname_tradition->newChildNames($father, $mother, 'U') 118 ); 119 } 120 121 /** 122 * Test new child names 123 */ 124 public function testNewChildNamesWithDutchSpfx(): void 125 { 126 $father_fact = $this->createStub(Fact::class); 127 $father_fact->method('value')->willReturn('John /\'t White/'); 128 129 $father = $this->createStub(Individual::class); 130 $father->method('facts')->willReturn(new Collection([$father_fact])); 131 132 $mother_fact = $this->createStub(Fact::class); 133 $mother_fact->method('value')->willReturn('Mary /van Black/'); 134 135 $mother = $this->createStub(Individual::class); 136 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 137 138 self::assertSame( 139 ["1 NAME /'t White/\n2 TYPE BIRTH\n2 SPFX 't\n2 SURN White"], 140 $this->surname_tradition->newChildNames($father, $mother, 'U') 141 ); 142 } 143 144 /** 145 * Test new child names 146 */ 147 public function testNewChildNamesWithMultipleDutchSpfx(): void 148 { 149 $father_fact = $this->createStub(Fact::class); 150 $father_fact->method('value')->willReturn('John /van \'t White/'); 151 152 $father = $this->createStub(Individual::class); 153 $father->method('facts')->willReturn(new Collection([$father_fact])); 154 155 $mother_fact = $this->createStub(Fact::class); 156 $mother_fact->method('value')->willReturn('Mary /van Black/'); 157 158 $mother = $this->createStub(Individual::class); 159 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 160 161 self::assertSame( 162 ["1 NAME /van 't White/\n2 TYPE BIRTH\n2 SPFX van 't\n2 SURN White"], 163 $this->surname_tradition->newChildNames($father, $mother, 'U') 164 ); 165 } 166 167 /** 168 * Test new father names 169 */ 170 public function testNewFatherNames(): void 171 { 172 $fact = $this->createStub(Fact::class); 173 $fact->method('value')->willReturn('Chris /White/'); 174 175 $individual = $this->createStub(Individual::class); 176 $individual->method('facts')->willReturn(new Collection([$fact])); 177 178 self::assertSame( 179 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 180 $this->surname_tradition->newParentNames($individual, 'M') 181 ); 182 } 183 184 /** 185 * Test new mother names 186 */ 187 public function testNewMotherNames(): void 188 { 189 $fact = $this->createStub(Fact::class); 190 $fact->method('value')->willReturn('Chris /White/'); 191 192 $individual = $this->createStub(Individual::class); 193 $individual->method('facts')->willReturn(new Collection([$fact])); 194 195 self::assertSame( 196 ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 197 $this->surname_tradition->newParentNames($individual, 'F') 198 ); 199 } 200 201 /** 202 * Test new parent names 203 */ 204 public function testNewParentNames(): void 205 { 206 $fact = $this->createStub(Fact::class); 207 $fact->method('value')->willReturn('Chris /White/'); 208 209 $individual = $this->createStub(Individual::class); 210 $individual->method('facts')->willReturn(new Collection([$fact])); 211 212 self::assertSame( 213 ["1 NAME //\n2 TYPE BIRTH"], 214 $this->surname_tradition->newParentNames($individual, 'U') 215 ); 216 } 217 218 /** 219 * Test new husband names 220 */ 221 public function testNewHusbandNames(): void 222 { 223 $fact = $this->createStub(Fact::class); 224 $fact->method('value')->willReturn('Chris /White/'); 225 226 $individual = $this->createStub(Individual::class); 227 $individual->method('facts')->willReturn(new Collection([$fact])); 228 229 self::assertSame( 230 ["1 NAME //\n2 TYPE BIRTH"], 231 $this->surname_tradition->newSpouseNames($individual, 'M') 232 ); 233 } 234 235 /** 236 * Test new wife names 237 */ 238 public function testNewWifeNames(): void 239 { 240 $fact = $this->createStub(Fact::class); 241 $fact->method('value')->willReturn('Chris /White/'); 242 243 $individual = $this->createStub(Individual::class); 244 $individual->method('facts')->willReturn(new Collection([$fact])); 245 246 self::assertSame( 247 ["1 NAME //\n2 TYPE BIRTH", "1 NAME /White/\n2 TYPE MARRIED\n2 SURN White"], 248 $this->surname_tradition->newSpouseNames($individual, 'F') 249 ); 250 } 251 252 /** 253 * Test new wife names 254 */ 255 public function testNewWifeNamesWithSpfx(): void 256 { 257 $fact = $this->createStub(Fact::class); 258 $fact->method('value')->willReturn('Chris /van der White/'); 259 260 $individual = $this->createStub(Individual::class); 261 $individual->method('facts')->willReturn(new Collection([$fact])); 262 263 self::assertSame( 264 ["1 NAME //\n2 TYPE BIRTH", "1 NAME /van der White/\n2 TYPE MARRIED\n2 SPFX van der\n2 SURN White"], 265 $this->surname_tradition->newSpouseNames($individual, 'F') 266 ); 267 } 268 269 /** 270 * Test new spouse names 271 */ 272 public function testNewSpouseNames(): void 273 { 274 $fact = $this->createStub(Fact::class); 275 $fact->method('value')->willReturn('Chris /White/'); 276 277 $individual = $this->createStub(Individual::class); 278 $individual->method('facts')->willReturn(new Collection([$fact])); 279 280 self::assertSame( 281 ["1 NAME //\n2 TYPE BIRTH"], 282 $this->surname_tradition->newSpouseNames($individual, 'U') 283 ); 284 } 285 286 /** 287 * Prepare the environment for these tests 288 */ 289 protected function setUp(): void 290 { 291 parent::setUp(); 292 293 $this->surname_tradition = new PaternalSurnameTradition(); 294 } 295} 296