17338314fSGreg Roach<?php 23976b470SGreg Roach 37338314fSGreg Roach/** 47338314fSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 67338314fSGreg Roach * This program is free software: you can redistribute it and/or modify 77338314fSGreg Roach * it under the terms of the GNU General Public License as published by 87338314fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 97338314fSGreg Roach * (at your option) any later version. 107338314fSGreg Roach * This program is distributed in the hope that it will be useful, 117338314fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 127338314fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 137338314fSGreg Roach * GNU General Public License for more details. 147338314fSGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 167338314fSGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 207338314fSGreg Roachnamespace Fisharebest\Webtrees\Census; 217338314fSGreg Roach 227338314fSGreg Roachuse Fisharebest\Webtrees\Date; 23ddf438a5SGreg Roachuse Fisharebest\Webtrees\Fact; 24ddf438a5SGreg Roachuse Fisharebest\Webtrees\Individual; 2552348eb8SGreg Roachuse Fisharebest\Webtrees\Place; 263cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase; 2739ca88baSGreg Roachuse Illuminate\Support\Collection; 28*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 297338314fSGreg Roach 30*202c018bSGreg Roach#[CoversClass(CensusColumnNationality::class)] 31*202c018bSGreg Roach#[CoversClass(AbstractCensusColumn::class)] 323cfcc809SGreg Roachclass CensusColumnNationalityTest extends TestCase 33c1010edaSGreg Roach{ 345e933c21SGreg Roach private function getPlaceMock(string $place): Place 35c1010edaSGreg Roach { 36cd94ca66SGreg Roach $placeMock = $this->createMock(Place::class); 370ecdbde6SGreg Roach $placeMock->method('gedcomName')->willReturn($place); 3816d0b7f7SRico Sonntag 3916d0b7f7SRico Sonntag return $placeMock; 4016d0b7f7SRico Sonntag } 4116d0b7f7SRico Sonntag 429b802b22SGreg Roach public function testNoBirthPlace(): void 43c1010edaSGreg Roach { 44cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 450ecdbde6SGreg Roach $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); 460ecdbde6SGreg Roach $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 4752f14e58SGreg Roach 48cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 490ecdbde6SGreg Roach $census->method('censusPlace')->willReturn('Deutschland'); 5052f14e58SGreg Roach 5152f14e58SGreg Roach $column = new CensusColumnNationality($census, '', ''); 5252f14e58SGreg Roach 535e933c21SGreg Roach self::assertSame('Deutsch', $column->generate($individual, $individual)); 5452f14e58SGreg Roach } 5552f14e58SGreg Roach 569b802b22SGreg Roach public function testPlaceCountry(): void 57c1010edaSGreg Roach { 58cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 590ecdbde6SGreg Roach $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia')); 600ecdbde6SGreg Roach $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 617338314fSGreg Roach 62cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 630ecdbde6SGreg Roach $census->method('censusPlace')->willReturn('England'); 647338314fSGreg Roach 657338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 667338314fSGreg Roach 675e933c21SGreg Roach self::assertSame('Australia', $column->generate($individual, $individual)); 687338314fSGreg Roach } 697338314fSGreg Roach 709b802b22SGreg Roach public function testBritish(): void 71c1010edaSGreg Roach { 72cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 730ecdbde6SGreg Roach $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 740ecdbde6SGreg Roach $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 757338314fSGreg Roach 76cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 770ecdbde6SGreg Roach $census->method('censusPlace')->willReturn('England'); 787338314fSGreg Roach 797338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 807338314fSGreg Roach 815e933c21SGreg Roach self::assertSame('British', $column->generate($individual, $individual)); 827338314fSGreg Roach } 837338314fSGreg Roach 849b802b22SGreg Roach public function testEmigrated(): void 85c1010edaSGreg Roach { 86cd94ca66SGreg Roach $place1 = $this->createMock(Place::class); 870ecdbde6SGreg Roach $place1->method('gedcomName')->willReturn('United States'); 887338314fSGreg Roach 89cd94ca66SGreg Roach $fact1 = $this->createMock(Fact::class); 900ecdbde6SGreg Roach $fact1->method('place')->willReturn($place1); 910ecdbde6SGreg Roach $fact1->method('date')->willReturn(new Date('1855')); 927338314fSGreg Roach 93cd94ca66SGreg Roach $place2 = $this->createMock(Place::class); 940ecdbde6SGreg Roach $place2->method('gedcomName')->willReturn('Australia'); 957338314fSGreg Roach 96cd94ca66SGreg Roach $fact2 = $this->createMock(Fact::class); 970ecdbde6SGreg Roach $fact2->method('place')->willReturn($place2); 980ecdbde6SGreg Roach $fact2->method('date')->willReturn(new Date('1865')); 997338314fSGreg Roach 100cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 1010ecdbde6SGreg Roach $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 1020ecdbde6SGreg Roach $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([ 10352f14e58SGreg Roach $fact1, 10452f14e58SGreg Roach $fact2, 10539ca88baSGreg Roach ])); 1067338314fSGreg Roach 107cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 1080ecdbde6SGreg Roach $census->method('censusPlace')->willReturn('England'); 1090ecdbde6SGreg Roach $census->method('censusDate')->willReturn('01 JUN 1860'); 1107338314fSGreg Roach 1117338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 1127338314fSGreg Roach 1135e933c21SGreg Roach self::assertSame('United States', $column->generate($individual, $individual)); 1147338314fSGreg Roach } 1157338314fSGreg Roach} 116