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