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\Census; 21 22use Fisharebest\Webtrees\Individual; 23use Fisharebest\Webtrees\Place; 24use Fisharebest\Webtrees\TestCase; 25use Illuminate\Support\Collection; 26use PHPUnit\Framework\Attributes\CoversClass; 27 28#[CoversClass(CensusColumnBornForeignParts::class)] 29#[CoversClass(AbstractCensusColumn::class)] 30class CensusColumnBornForeignPartsTest extends TestCase 31{ 32 private function getPlaceMock(string $place): Place 33 { 34 $placeParts = explode(', ', $place); 35 36 $placeMock = $this->createMock(Place::class); 37 $placeMock->method('gedcomName')->willReturn($place); 38 $placeMock->method('lastParts')->willReturn((new Collection($placeParts))->slice(-1)); 39 40 return $placeMock; 41 } 42 43 public function testBornEnglandCensusEngland(): void 44 { 45 $individual = $this->createMock(Individual::class); 46 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 47 48 $census = $this->createMock(CensusInterface::class); 49 $census->method('censusPlace')->willReturn('England'); 50 51 $column = new CensusColumnBornForeignParts($census, '', ''); 52 53 self::assertSame('', $column->generate($individual, $individual)); 54 } 55 56 public function testBornWalesCensusEngland(): void 57 { 58 $individual = $this->createMock(Individual::class); 59 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales')); 60 61 $census = $this->createMock(CensusInterface::class); 62 $census->method('censusPlace')->willReturn('England'); 63 64 $column = new CensusColumnBornForeignParts($census, '', ''); 65 66 self::assertSame('', $column->generate($individual, $individual)); 67 } 68 69 public function testBornScotlandCensusEngland(): void 70 { 71 $individual = $this->createMock(Individual::class); 72 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland')); 73 74 $census = $this->createMock(CensusInterface::class); 75 $census->method('censusPlace')->willReturn('England'); 76 77 $column = new CensusColumnBornForeignParts($census, '', ''); 78 79 self::assertSame('S', $column->generate($individual, $individual)); 80 } 81 82 public function testBornIrelandCensusEngland(): void 83 { 84 $individual = $this->createMock(Individual::class); 85 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland')); 86 87 $census = $this->createMock(CensusInterface::class); 88 $census->method('censusPlace')->willReturn('England'); 89 90 $column = new CensusColumnBornForeignParts($census, '', ''); 91 92 self::assertSame('I', $column->generate($individual, $individual)); 93 } 94 95 public function testBornForeignCensusEngland(): void 96 { 97 $individual = $this->createMock(Individual::class); 98 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia')); 99 100 $census = $this->createMock(CensusInterface::class); 101 $census->method('censusPlace')->willReturn('England'); 102 103 $column = new CensusColumnBornForeignParts($census, '', ''); 104 105 self::assertSame('F', $column->generate($individual, $individual)); 106 } 107 108 public function testBornEnglandCensusIreland(): void 109 { 110 $individual = $this->createMock(Individual::class); 111 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 112 113 $census = $this->createMock(CensusInterface::class); 114 $census->method('censusPlace')->willReturn('Ireland'); 115 116 $column = new CensusColumnBornForeignParts($census, '', ''); 117 118 self::assertSame('E', $column->generate($individual, $individual)); 119 } 120 121 public function testBornWalesCensusIreland(): void 122 { 123 $individual = $this->createMock(Individual::class); 124 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales')); 125 126 $census = $this->createMock(CensusInterface::class); 127 $census->method('censusPlace')->willReturn('Ireland'); 128 129 $column = new CensusColumnBornForeignParts($census, '', ''); 130 131 self::assertSame('E', $column->generate($individual, $individual)); 132 } 133 134 public function testBornScotlandCensusIreland(): void 135 { 136 $individual = $this->createMock(Individual::class); 137 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland')); 138 139 $census = $this->createMock(CensusInterface::class); 140 $census->method('censusPlace')->willReturn('Ireland'); 141 142 $column = new CensusColumnBornForeignParts($census, '', ''); 143 144 self::assertSame('S', $column->generate($individual, $individual)); 145 } 146 147 public function testBornIrelandCensusIreland(): void 148 { 149 $individual = $this->createMock(Individual::class); 150 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland')); 151 152 $census = $this->createMock(CensusInterface::class); 153 $census->method('censusPlace')->willReturn('Ireland'); 154 155 $column = new CensusColumnBornForeignParts($census, '', ''); 156 157 self::assertSame('', $column->generate($individual, $individual)); 158 } 159 160 public function testBornForeignCensusIreland(): void 161 { 162 $individual = $this->createMock(Individual::class); 163 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia')); 164 165 $census = $this->createMock(CensusInterface::class); 166 $census->method('censusPlace')->willReturn('Ireland'); 167 168 $column = new CensusColumnBornForeignParts($census, '', ''); 169 170 self::assertSame('F', $column->generate($individual, $individual)); 171 } 172 173 public function testBornEnglandCensusScotland(): void 174 { 175 $individual = $this->createMock(Individual::class); 176 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 177 178 $census = $this->createMock(CensusInterface::class); 179 $census->method('censusPlace')->willReturn('Scotland'); 180 181 $column = new CensusColumnBornForeignParts($census, '', ''); 182 183 self::assertSame('E', $column->generate($individual, $individual)); 184 } 185 186 public function testBornWalesCensusScotland(): void 187 { 188 $individual = $this->createMock(Individual::class); 189 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales')); 190 191 $census = $this->createMock(CensusInterface::class); 192 $census->method('censusPlace')->willReturn('Scotland'); 193 194 $column = new CensusColumnBornForeignParts($census, '', ''); 195 196 self::assertSame('E', $column->generate($individual, $individual)); 197 } 198 199 public function testBornScotlandCensusScotland(): void 200 { 201 $individual = $this->createMock(Individual::class); 202 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland')); 203 204 $census = $this->createMock(CensusInterface::class); 205 $census->method('censusPlace')->willReturn('Scotland'); 206 207 $column = new CensusColumnBornForeignParts($census, '', ''); 208 209 self::assertSame('', $column->generate($individual, $individual)); 210 } 211 212 public function testBornIrelandCensusScotland(): void 213 { 214 $individual = $this->createMock(Individual::class); 215 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland')); 216 217 $census = $this->createMock(CensusInterface::class); 218 $census->method('censusPlace')->willReturn('Scotland'); 219 220 $column = new CensusColumnBornForeignParts($census, '', ''); 221 222 self::assertSame('I', $column->generate($individual, $individual)); 223 } 224 225 public function testBornForeignCensusScotland(): void 226 { 227 $individual = $this->createMock(Individual::class); 228 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia')); 229 230 $census = $this->createMock(CensusInterface::class); 231 $census->method('censusPlace')->willReturn('Scotland'); 232 233 $column = new CensusColumnBornForeignParts($census, '', ''); 234 235 self::assertSame('F', $column->generate($individual, $individual)); 236 } 237 238 public function testBornEnglandCensusWales(): void 239 { 240 $individual = $this->createMock(Individual::class); 241 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 242 243 $census = $this->createMock(CensusInterface::class); 244 $census->method('censusPlace')->willReturn('Wales'); 245 246 $column = new CensusColumnBornForeignParts($census, '', ''); 247 248 self::assertSame('', $column->generate($individual, $individual)); 249 } 250 251 public function testBornWalesCensusWales(): void 252 { 253 $individual = $this->createMock(Individual::class); 254 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales')); 255 256 $census = $this->createMock(CensusInterface::class); 257 $census->method('censusPlace')->willReturn('Wales'); 258 259 $column = new CensusColumnBornForeignParts($census, '', ''); 260 261 self::assertSame('', $column->generate($individual, $individual)); 262 } 263 264 public function testBornScotlandCensusWales(): void 265 { 266 $individual = $this->createMock(Individual::class); 267 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland')); 268 269 $census = $this->createMock(CensusInterface::class); 270 $census->method('censusPlace')->willReturn('Wales'); 271 272 $column = new CensusColumnBornForeignParts($census, '', ''); 273 274 self::assertSame('S', $column->generate($individual, $individual)); 275 } 276 277 public function testBornIrelandCensusWales(): void 278 { 279 $individual = $this->createMock(Individual::class); 280 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland')); 281 282 $census = $this->createMock(CensusInterface::class); 283 $census->method('censusPlace')->willReturn('Wales'); 284 285 $column = new CensusColumnBornForeignParts($census, '', ''); 286 287 self::assertSame('I', $column->generate($individual, $individual)); 288 } 289 290 public function testBornForeignCensusWales(): void 291 { 292 $individual = $this->createMock(Individual::class); 293 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia')); 294 295 $census = $this->createMock(CensusInterface::class); 296 $census->method('censusPlace')->willReturn('Wales'); 297 298 $column = new CensusColumnBornForeignParts($census, '', ''); 299 300 self::assertSame('F', $column->generate($individual, $individual)); 301 } 302 303 public function testBornNowhereCensusEngland(): void 304 { 305 $individual = $this->createMock(Individual::class); 306 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); 307 308 $census = $this->createMock(CensusInterface::class); 309 $census->method('censusPlace')->willReturn('England'); 310 311 $column = new CensusColumnBornForeignParts($census, '', ''); 312 313 self::assertSame('', $column->generate($individual, $individual)); 314 } 315 316 public function testBornNowhereCensusWales(): void 317 { 318 $individual = $this->createMock(Individual::class); 319 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); 320 321 $census = $this->createMock(CensusInterface::class); 322 $census->method('censusPlace')->willReturn('Wales'); 323 324 $column = new CensusColumnBornForeignParts($census, '', ''); 325 326 self::assertSame('', $column->generate($individual, $individual)); 327 } 328 329 public function testBornNowhereCensusScotland(): void 330 { 331 $individual = $this->createMock(Individual::class); 332 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); 333 334 $census = $this->createMock(CensusInterface::class); 335 $census->method('censusPlace')->willReturn('Scotland'); 336 337 $column = new CensusColumnBornForeignParts($census, '', ''); 338 339 self::assertSame('', $column->generate($individual, $individual)); 340 } 341} 342