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(MatrilinealSurnameTradition::class)] 30class MatrilinealSurnameTraditionTest 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 MatrilinealSurnameTradition(); 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->createMock(Fact::class); 58 $father_fact->method('value')->willReturn('John /White/'); 59 60 $father = $this->createMock(Individual::class); 61 $father->method('facts')->willReturn(new Collection([$father_fact])); 62 63 $mother_fact = $this->createMock(Fact::class); 64 $mother_fact->method('value')->willReturn('Mary /Black/'); 65 66 $mother = $this->createMock(Individual::class); 67 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 68 69 self::assertSame( 70 ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"], 71 $this->surname_tradition->newChildNames($father, $mother, 'M') 72 ); 73 74 self::assertSame( 75 ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"], 76 $this->surname_tradition->newChildNames($father, $mother, 'F') 77 ); 78 79 self::assertSame( 80 ["1 NAME /Black/\n2 TYPE BIRTH\n2 SURN Black"], 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->createMock(Fact::class); 91 $father_fact->method('value')->willReturn('John /de White/'); 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('Mary /van Black/'); 98 99 $mother = $this->createMock(Individual::class); 100 $mother->method('facts')->willReturn(new Collection([$mother_fact])); 101 102 self::assertSame( 103 ["1 NAME /van Black/\n2 TYPE BIRTH\n2 SPFX van\n2 SURN Black"], 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->createMock(Fact::class); 125 $fact->method('value')->willReturn('Chris /White/'); 126 127 $individual = $this->createMock(Individual::class); 128 $individual->method('facts')->willReturn(new Collection([$fact])); 129 130 131 self::assertSame( 132 ["1 NAME //\n2 TYPE BIRTH"], 133 $this->surname_tradition->newParentNames($individual, 'M') 134 ); 135 136 self::assertSame( 137 ["1 NAME /White/\n2 TYPE BIRTH\n2 SURN White"], 138 $this->surname_tradition->newParentNames($individual, 'F') 139 ); 140 141 self::assertSame( 142 ["1 NAME //\n2 TYPE BIRTH"], 143 $this->surname_tradition->newParentNames($individual, 'U') 144 ); 145 } 146 147 /** 148 * Test new spouse names 149 */ 150 public function testNewSpouseNames(): void 151 { 152 $fact = $this->createMock(Fact::class); 153 $fact->method('value')->willReturn('Chris /White/'); 154 155 $individual = $this->createMock(Individual::class); 156 $individual->method('facts')->willReturn(new Collection([$fact])); 157 158 self::assertSame( 159 ["1 NAME //\n2 TYPE BIRTH"], 160 $this->surname_tradition->newSpouseNames($individual, 'M') 161 ); 162 163 self::assertSame( 164 ["1 NAME //\n2 TYPE BIRTH"], 165 $this->surname_tradition->newSpouseNames($individual, 'F') 166 ); 167 168 self::assertSame( 169 ["1 NAME //\n2 TYPE BIRTH"], 170 $this->surname_tradition->newSpouseNames($individual, 'U') 171 ); 172 } 173} 174