1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Census; 19 20use Fisharebest\Webtrees\Date; 21use Fisharebest\Webtrees\Fact; 22use Fisharebest\Webtrees\Individual; 23use Fisharebest\Webtrees\Place; 24use Illuminate\Support\Collection; 25 26/** 27 * Test harness for the class CensusColumnNationality 28 */ 29class CensusColumnNationalityTest extends \Fisharebest\Webtrees\TestCase 30{ 31 /** 32 * Get place mock. 33 * 34 * @param string $place Gedcom Place 35 * 36 * @return Place 37 */ 38 private function getPlaceMock($place): Place 39 { 40 $placeMock = $this->createMock(Place::class); 41 $placeMock->method('gedcomName')->willReturn($place); 42 43 return $placeMock; 44 } 45 46 /** 47 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 48 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 49 * 50 * @return void 51 */ 52 public function testNoBirthPlace(): void 53 { 54 $individual = $this->createMock(Individual::class); 55 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('')); 56 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 57 58 $census = $this->createMock(CensusInterface::class); 59 $census->method('censusPlace')->willReturn('Deutschland'); 60 61 $column = new CensusColumnNationality($census, '', ''); 62 63 $this->assertSame('Deutsch', $column->generate($individual, $individual)); 64 } 65 66 /** 67 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 68 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 69 * 70 * @return void 71 */ 72 public function testPlaceCountry(): void 73 { 74 $individual = $this->createMock(Individual::class); 75 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia')); 76 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 77 78 $census = $this->createMock(CensusInterface::class); 79 $census->method('censusPlace')->willReturn('England'); 80 81 $column = new CensusColumnNationality($census, '', ''); 82 83 $this->assertSame('Australia', $column->generate($individual, $individual)); 84 } 85 86 /** 87 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 88 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 89 * 90 * @return void 91 */ 92 public function testBritish(): void 93 { 94 $individual = $this->createMock(Individual::class); 95 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 96 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection()); 97 98 $census = $this->createMock(CensusInterface::class); 99 $census->method('censusPlace')->willReturn('England'); 100 101 $column = new CensusColumnNationality($census, '', ''); 102 103 $this->assertSame('British', $column->generate($individual, $individual)); 104 } 105 106 /** 107 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 108 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 109 * 110 * @return void 111 */ 112 public function testEmigrated(): void 113 { 114 $place1 = $this->createMock('Fisharebest\Webtrees\Place'); 115 $place1->method('gedcomName')->willReturn('United States'); 116 117 $fact1 = $this->createMock(Fact::class); 118 $fact1->method('place')->willReturn($place1); 119 $fact1->method('date')->willReturn(new Date('1855')); 120 121 $place2 = $this->createMock('Fisharebest\Webtrees\Place'); 122 $place2->method('gedcomName')->willReturn('Australia'); 123 124 $fact2 = $this->createMock(Fact::class); 125 $fact2->method('place')->willReturn($place2); 126 $fact2->method('date')->willReturn(new Date('1865')); 127 128 $individual = $this->createMock(Individual::class); 129 $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 130 $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([ 131 $fact1, 132 $fact2, 133 ])); 134 135 $census = $this->createMock(CensusInterface::class); 136 $census->method('censusPlace')->willReturn('England'); 137 $census->method('censusDate')->willReturn('01 JUN 1860'); 138 139 $column = new CensusColumnNationality($census, '', ''); 140 141 $this->assertSame('United States', $column->generate($individual, $individual)); 142 } 143} 144