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