17338314fSGreg Roach<?php 27338314fSGreg Roach/** 37338314fSGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 57338314fSGreg Roach * This program is free software: you can redistribute it and/or modify 67338314fSGreg Roach * it under the terms of the GNU General Public License as published by 77338314fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 87338314fSGreg Roach * (at your option) any later version. 97338314fSGreg Roach * This program is distributed in the hope that it will be useful, 107338314fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 117338314fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 127338314fSGreg Roach * GNU General Public License for more details. 137338314fSGreg Roach * You should have received a copy of the GNU General Public License 147338314fSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 157338314fSGreg Roach */ 167338314fSGreg Roachnamespace Fisharebest\Webtrees\Census; 177338314fSGreg Roach 187338314fSGreg Roachuse Fisharebest\Webtrees\Date; 197338314fSGreg Roachuse Mockery; 207338314fSGreg Roach 217338314fSGreg Roach/** 227338314fSGreg Roach * Test harness for the class CensusColumnNationality 237338314fSGreg Roach */ 24*84e2cf4eSGreg Roachclass CensusColumnNationalityTest extends \Fisharebest\Webtrees\TestCase 25c1010edaSGreg Roach{ 267338314fSGreg Roach /** 277338314fSGreg Roach * Delete mock objects 287338314fSGreg Roach */ 29c1010edaSGreg Roach public function tearDown() 30c1010edaSGreg Roach { 317338314fSGreg Roach Mockery::close(); 327338314fSGreg Roach } 337338314fSGreg Roach 347338314fSGreg Roach /** 3516d0b7f7SRico Sonntag * Get place mock. 3616d0b7f7SRico Sonntag * 3716d0b7f7SRico Sonntag * @param string $place Gedcom Place 3816d0b7f7SRico Sonntag * 3916d0b7f7SRico Sonntag * @return \Fisharebest\Webtrees\Place 4016d0b7f7SRico Sonntag */ 418f53f488SRico Sonntag private function getPlaceMock($place): \Fisharebest\Webtrees\Place 42c1010edaSGreg Roach { 4316d0b7f7SRico Sonntag $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place'); 4416d0b7f7SRico Sonntag $placeMock->shouldReceive('getGedcomName')->andReturn($place); 4516d0b7f7SRico Sonntag 4616d0b7f7SRico Sonntag return $placeMock; 4716d0b7f7SRico Sonntag } 4816d0b7f7SRico Sonntag 4916d0b7f7SRico Sonntag /** 5015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 5115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 527338314fSGreg Roach */ 53c1010edaSGreg Roach public function testNoBirthPlace() 54c1010edaSGreg Roach { 5552f14e58SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 5616d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('')); 572a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 5852f14e58SGreg Roach 5952f14e58SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 6052f14e58SGreg Roach $census->shouldReceive('censusPlace')->andReturn('Deutschland'); 6152f14e58SGreg Roach 6252f14e58SGreg Roach $column = new CensusColumnNationality($census, '', ''); 6352f14e58SGreg Roach 64342dcecdSGreg Roach $this->assertSame('Deutsch', $column->generate($individual, $individual)); 6552f14e58SGreg Roach } 6652f14e58SGreg Roach 6752f14e58SGreg Roach /** 6815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 6915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 7052f14e58SGreg Roach */ 71c1010edaSGreg Roach public function testPlaceCountry() 72c1010edaSGreg Roach { 73c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 7416d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia')); 752a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 767338314fSGreg Roach 77c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 787338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 797338314fSGreg Roach 807338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 817338314fSGreg Roach 82342dcecdSGreg Roach $this->assertSame('Australia', $column->generate($individual, $individual)); 837338314fSGreg Roach } 847338314fSGreg Roach 857338314fSGreg Roach /** 8615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 8715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 887338314fSGreg Roach */ 89c1010edaSGreg Roach public function testBritish() 90c1010edaSGreg Roach { 91c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 9216d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 932a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 947338314fSGreg Roach 95c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 967338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 977338314fSGreg Roach 987338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 997338314fSGreg Roach 100342dcecdSGreg Roach $this->assertSame('British', $column->generate($individual, $individual)); 1017338314fSGreg Roach } 1027338314fSGreg Roach 1037338314fSGreg Roach /** 10415d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 10515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 1067338314fSGreg Roach */ 107c1010edaSGreg Roach public function testEmigrated() 108c1010edaSGreg Roach { 109c314ecc9SGreg Roach $place1 = Mockery::mock('Fisharebest\Webtrees\Place'); 1107338314fSGreg Roach $place1->shouldReceive('getGedcomName')->andReturn('United States'); 1117338314fSGreg Roach 112c314ecc9SGreg Roach $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact'); 1137338314fSGreg Roach $fact1->shouldReceive('getPlace')->andReturn($place1); 1147338314fSGreg Roach $fact1->shouldReceive('getDate')->andReturn(new Date('1855')); 1157338314fSGreg Roach 116c314ecc9SGreg Roach $place2 = Mockery::mock('Fisharebest\Webtrees\Place'); 1177338314fSGreg Roach $place2->shouldReceive('getGedcomName')->andReturn('Australia'); 1187338314fSGreg Roach 119c314ecc9SGreg Roach $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact'); 1207338314fSGreg Roach $fact2->shouldReceive('getPlace')->andReturn($place2); 1217338314fSGreg Roach $fact2->shouldReceive('getDate')->andReturn(new Date('1865')); 1227338314fSGreg Roach 123c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 12416d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 1252a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([ 12652f14e58SGreg Roach $fact1, 12752f14e58SGreg Roach $fact2, 12813abd6f3SGreg Roach ]); 1297338314fSGreg Roach 130c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 1317338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 1327338314fSGreg Roach $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 1337338314fSGreg Roach 1347338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 1357338314fSGreg Roach 136342dcecdSGreg Roach $this->assertSame('United States', $column->generate($individual, $individual)); 1377338314fSGreg Roach } 1387338314fSGreg Roach} 139