17338314fSGreg Roach<?php 27338314fSGreg Roach 37338314fSGreg Roach/** 47338314fSGreg Roach * webtrees: online genealogy 51062a142SGreg Roach * Copyright (C) 2018 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 157338314fSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 167338314fSGreg Roach */ 177338314fSGreg Roachnamespace Fisharebest\Webtrees\Census; 187338314fSGreg Roach 197338314fSGreg Roachuse Fisharebest\Webtrees\Date; 207338314fSGreg Roachuse Mockery; 217338314fSGreg Roach 227338314fSGreg Roach/** 237338314fSGreg Roach * Test harness for the class CensusColumnNationality 247338314fSGreg Roach */ 25c1010edaSGreg Roachclass CensusColumnNationalityTest extends \PHPUnit\Framework\TestCase 26c1010edaSGreg Roach{ 277338314fSGreg Roach /** 287338314fSGreg Roach * Delete mock objects 297338314fSGreg Roach */ 30c1010edaSGreg Roach public function tearDown() 31c1010edaSGreg Roach { 327338314fSGreg Roach Mockery::close(); 337338314fSGreg Roach } 347338314fSGreg Roach 357338314fSGreg Roach /** 3616d0b7f7SRico Sonntag * Get place mock. 3716d0b7f7SRico Sonntag * 3816d0b7f7SRico Sonntag * @param string $place Gedcom Place 3916d0b7f7SRico Sonntag * 4016d0b7f7SRico Sonntag * @return \Fisharebest\Webtrees\Place 4116d0b7f7SRico Sonntag */ 42*8f53f488SRico Sonntag private function getPlaceMock($place): \Fisharebest\Webtrees\Place 43c1010edaSGreg Roach { 4416d0b7f7SRico Sonntag $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place'); 4516d0b7f7SRico Sonntag $placeMock->shouldReceive('getGedcomName')->andReturn($place); 4616d0b7f7SRico Sonntag 4716d0b7f7SRico Sonntag return $placeMock; 4816d0b7f7SRico Sonntag } 4916d0b7f7SRico Sonntag 5016d0b7f7SRico Sonntag /** 5115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 5215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 537338314fSGreg Roach */ 54c1010edaSGreg Roach public function testNoBirthPlace() 55c1010edaSGreg Roach { 5652f14e58SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 5716d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('')); 582a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 5952f14e58SGreg Roach 6052f14e58SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 6152f14e58SGreg Roach $census->shouldReceive('censusPlace')->andReturn('Deutschland'); 6252f14e58SGreg Roach 6352f14e58SGreg Roach $column = new CensusColumnNationality($census, '', ''); 6452f14e58SGreg Roach 65342dcecdSGreg Roach $this->assertSame('Deutsch', $column->generate($individual, $individual)); 6652f14e58SGreg Roach } 6752f14e58SGreg Roach 6852f14e58SGreg Roach /** 6915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 7015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 7152f14e58SGreg Roach */ 72c1010edaSGreg Roach public function testPlaceCountry() 73c1010edaSGreg Roach { 74c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 7516d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia')); 762a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 777338314fSGreg Roach 78c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 797338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 807338314fSGreg Roach 817338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 827338314fSGreg Roach 83342dcecdSGreg Roach $this->assertSame('Australia', $column->generate($individual, $individual)); 847338314fSGreg Roach } 857338314fSGreg Roach 867338314fSGreg Roach /** 8715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 8815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 897338314fSGreg Roach */ 90c1010edaSGreg Roach public function testBritish() 91c1010edaSGreg Roach { 92c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 9316d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 942a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 957338314fSGreg Roach 96c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 977338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 987338314fSGreg Roach 997338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 1007338314fSGreg Roach 101342dcecdSGreg Roach $this->assertSame('British', $column->generate($individual, $individual)); 1027338314fSGreg Roach } 1037338314fSGreg Roach 1047338314fSGreg Roach /** 10515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 10615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 1077338314fSGreg Roach */ 108c1010edaSGreg Roach public function testEmigrated() 109c1010edaSGreg Roach { 110c314ecc9SGreg Roach $place1 = Mockery::mock('Fisharebest\Webtrees\Place'); 1117338314fSGreg Roach $place1->shouldReceive('getGedcomName')->andReturn('United States'); 1127338314fSGreg Roach 113c314ecc9SGreg Roach $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact'); 1147338314fSGreg Roach $fact1->shouldReceive('getPlace')->andReturn($place1); 1157338314fSGreg Roach $fact1->shouldReceive('getDate')->andReturn(new Date('1855')); 1167338314fSGreg Roach 117c314ecc9SGreg Roach $place2 = Mockery::mock('Fisharebest\Webtrees\Place'); 1187338314fSGreg Roach $place2->shouldReceive('getGedcomName')->andReturn('Australia'); 1197338314fSGreg Roach 120c314ecc9SGreg Roach $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact'); 1217338314fSGreg Roach $fact2->shouldReceive('getPlace')->andReturn($place2); 1227338314fSGreg Roach $fact2->shouldReceive('getDate')->andReturn(new Date('1865')); 1237338314fSGreg Roach 124c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 12516d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 1262a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([ 12752f14e58SGreg Roach $fact1, 12852f14e58SGreg Roach $fact2, 12913abd6f3SGreg Roach ]); 1307338314fSGreg Roach 131c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 1327338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 1337338314fSGreg Roach $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 1347338314fSGreg Roach 1357338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 1367338314fSGreg Roach 137342dcecdSGreg Roach $this->assertSame('United States', $column->generate($individual, $individual)); 1387338314fSGreg Roach } 1397338314fSGreg Roach} 140