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