17338314fSGreg Roach<?php 27338314fSGreg Roach 37338314fSGreg Roach/** 47338314fSGreg Roach * webtrees: online genealogy 56bdf7674SGreg Roach * Copyright (C) 2017 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 */ 25*3e983931SGreg Roachclass CensusColumnNationalityTest extends \PHPUnit\Framework\TestCase { 267338314fSGreg Roach /** 277338314fSGreg Roach * Delete mock objects 287338314fSGreg Roach */ 297338314fSGreg Roach public function tearDown() { 307338314fSGreg Roach Mockery::close(); 317338314fSGreg Roach } 327338314fSGreg Roach 337338314fSGreg Roach /** 3416d0b7f7SRico Sonntag * Get place mock. 3516d0b7f7SRico Sonntag * 3616d0b7f7SRico Sonntag * @param string $place Gedcom Place 3716d0b7f7SRico Sonntag * 3816d0b7f7SRico Sonntag * @return \Fisharebest\Webtrees\Place 3916d0b7f7SRico Sonntag */ 408d68cabeSGreg Roach private function getPlaceMock($place) { 4116d0b7f7SRico Sonntag $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place'); 4216d0b7f7SRico Sonntag $placeMock->shouldReceive('getGedcomName')->andReturn($place); 4316d0b7f7SRico Sonntag 4416d0b7f7SRico Sonntag return $placeMock; 4516d0b7f7SRico Sonntag } 4616d0b7f7SRico Sonntag 4716d0b7f7SRico Sonntag /** 4815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 4915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 507338314fSGreg Roach */ 5152f14e58SGreg Roach public function testNoBirthPlace() { 5252f14e58SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 5316d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('')); 542a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 5552f14e58SGreg Roach 5652f14e58SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 5752f14e58SGreg Roach $census->shouldReceive('censusPlace')->andReturn('Deutschland'); 5852f14e58SGreg Roach 5952f14e58SGreg Roach $column = new CensusColumnNationality($census, '', ''); 6052f14e58SGreg Roach 6152f14e58SGreg Roach $this->assertSame('Deutsch', $column->generate($individual)); 6252f14e58SGreg Roach } 6352f14e58SGreg Roach 6452f14e58SGreg Roach /** 6515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 6615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 6752f14e58SGreg Roach */ 687338314fSGreg Roach public function testPlaceCountry() { 69c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 7016d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia')); 712a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 727338314fSGreg Roach 73c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 747338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 757338314fSGreg Roach 767338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 777338314fSGreg Roach 787338314fSGreg Roach $this->assertSame('Australia', $column->generate($individual)); 797338314fSGreg Roach } 807338314fSGreg Roach 817338314fSGreg Roach /** 8215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 8315d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 847338314fSGreg Roach */ 857338314fSGreg Roach public function testBritish() { 86c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 8716d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 882a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 897338314fSGreg Roach 90c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 917338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 927338314fSGreg Roach 937338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 947338314fSGreg Roach 957338314fSGreg Roach $this->assertSame('British', $column->generate($individual)); 967338314fSGreg Roach } 977338314fSGreg Roach 987338314fSGreg Roach /** 9915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 10015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 1017338314fSGreg Roach */ 1027338314fSGreg Roach public function testEmigrated() { 103c314ecc9SGreg Roach $place1 = Mockery::mock('Fisharebest\Webtrees\Place'); 1047338314fSGreg Roach $place1->shouldReceive('getGedcomName')->andReturn('United States'); 1057338314fSGreg Roach 106c314ecc9SGreg Roach $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact'); 1077338314fSGreg Roach $fact1->shouldReceive('getPlace')->andReturn($place1); 1087338314fSGreg Roach $fact1->shouldReceive('getDate')->andReturn(new Date('1855')); 1097338314fSGreg Roach 110c314ecc9SGreg Roach $place2 = Mockery::mock('Fisharebest\Webtrees\Place'); 1117338314fSGreg Roach $place2->shouldReceive('getGedcomName')->andReturn('Australia'); 1127338314fSGreg Roach 113c314ecc9SGreg Roach $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact'); 1147338314fSGreg Roach $fact2->shouldReceive('getPlace')->andReturn($place2); 1157338314fSGreg Roach $fact2->shouldReceive('getDate')->andReturn(new Date('1865')); 1167338314fSGreg Roach 117c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 11816d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 1192a6fda60SGreg Roach $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([ 12052f14e58SGreg Roach $fact1, 12152f14e58SGreg Roach $fact2, 12213abd6f3SGreg Roach ]); 1237338314fSGreg Roach 124c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 1257338314fSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 1267338314fSGreg Roach $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 1277338314fSGreg Roach 1287338314fSGreg Roach $column = new CensusColumnNationality($census, '', ''); 1297338314fSGreg Roach 1307338314fSGreg Roach $this->assertSame('United States', $column->generate($individual)); 1317338314fSGreg Roach } 1327338314fSGreg Roach} 133