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\Date; 23use Fisharebest\Webtrees\Fact; 24use Fisharebest\Webtrees\Individual; 25use Fisharebest\Webtrees\Place; 26use Fisharebest\Webtrees\TestCase; 27use Illuminate\Support\Collection; 28use PHPUnit\Framework\Attributes\CoversClass; 29 30#[CoversClass(CensusColumnNationality::class)] 31#[CoversClass(AbstractCensusColumn::class)] 32class CensusColumnNationalityTest extends TestCase 33{ 34 private function getPlaceMock(string $place): Place 35 { 36 $placeMock = $this->createMock(Place::class); 37 $placeMock->method('gedcomName')->willReturn($place); 38 39 return $placeMock; 40 } 41 42 public function testNoBirthPlace(): void 43 { 44 $individual = $this->createMock(Individual::class); 45 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); 46 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 47 48 $census = $this->createMock(CensusInterface::class); 49 $census->method('censusPlace')->willReturn('Deutschland'); 50 51 $column = new CensusColumnNationality($census, '', ''); 52 53 self::assertSame('Deutsch', $column->generate($individual, $individual)); 54 } 55 56 public function testPlaceCountry(): void 57 { 58 $individual = $this->createMock(Individual::class); 59 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia')); 60 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 61 62 $census = $this->createMock(CensusInterface::class); 63 $census->method('censusPlace')->willReturn('England'); 64 65 $column = new CensusColumnNationality($census, '', ''); 66 67 self::assertSame('Australia', $column->generate($individual, $individual)); 68 } 69 70 public function testBritish(): void 71 { 72 $individual = $this->createMock(Individual::class); 73 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 74 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 75 76 $census = $this->createMock(CensusInterface::class); 77 $census->method('censusPlace')->willReturn('England'); 78 79 $column = new CensusColumnNationality($census, '', ''); 80 81 self::assertSame('British', $column->generate($individual, $individual)); 82 } 83 84 public function testEmigrated(): void 85 { 86 $place1 = $this->createMock(Place::class); 87 $place1->method('gedcomName')->willReturn('United States'); 88 89 $fact1 = $this->createMock(Fact::class); 90 $fact1->method('place')->willReturn($place1); 91 $fact1->method('date')->willReturn(new Date('1855')); 92 93 $place2 = $this->createMock(Place::class); 94 $place2->method('gedcomName')->willReturn('Australia'); 95 96 $fact2 = $this->createMock(Fact::class); 97 $fact2->method('place')->willReturn($place2); 98 $fact2->method('date')->willReturn(new Date('1865')); 99 100 $individual = $this->createMock(Individual::class); 101 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 102 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([ 103 $fact1, 104 $fact2, 105 ])); 106 107 $census = $this->createMock(CensusInterface::class); 108 $census->method('censusPlace')->willReturn('England'); 109 $census->method('censusDate')->willReturn('01 JUN 1860'); 110 111 $column = new CensusColumnNationality($census, '', ''); 112 113 self::assertSame('United States', $column->generate($individual, $individual)); 114 } 115} 116