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