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 { 42 $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place'); 43 $placeMock->shouldReceive('getGedcomName')->andReturn($place); 44 45 return $placeMock; 46 } 47 48 /** 49 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 50 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 51 */ 52 public function testNoBirthPlace() { 53 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 54 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('')); 55 $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 56 57 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 58 $census->shouldReceive('censusPlace')->andReturn('Deutschland'); 59 60 $column = new CensusColumnNationality($census, '', ''); 61 62 $this->assertSame('Deutsch', $column->generate($individual)); 63 } 64 65 /** 66 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 67 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 68 */ 69 public function testPlaceCountry() { 70 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 71 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia')); 72 $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 73 74 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 75 $census->shouldReceive('censusPlace')->andReturn('England'); 76 77 $column = new CensusColumnNationality($census, '', ''); 78 79 $this->assertSame('Australia', $column->generate($individual)); 80 } 81 82 /** 83 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 84 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 85 */ 86 public function testBritish() { 87 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 88 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 89 $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]); 90 91 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 92 $census->shouldReceive('censusPlace')->andReturn('England'); 93 94 $column = new CensusColumnNationality($census, '', ''); 95 96 $this->assertSame('British', $column->generate($individual)); 97 } 98 99 /** 100 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality 101 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 102 */ 103 public function testEmigrated() { 104 $place1 = Mockery::mock('Fisharebest\Webtrees\Place'); 105 $place1->shouldReceive('getGedcomName')->andReturn('United States'); 106 107 $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact'); 108 $fact1->shouldReceive('getPlace')->andReturn($place1); 109 $fact1->shouldReceive('getDate')->andReturn(new Date('1855')); 110 111 $place2 = Mockery::mock('Fisharebest\Webtrees\Place'); 112 $place2->shouldReceive('getGedcomName')->andReturn('Australia'); 113 114 $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact'); 115 $fact2->shouldReceive('getPlace')->andReturn($place2); 116 $fact2->shouldReceive('getDate')->andReturn(new Date('1865')); 117 118 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 119 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 120 $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([ 121 $fact1, 122 $fact2, 123 ]); 124 125 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 126 $census->shouldReceive('censusPlace')->andReturn('England'); 127 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 128 129 $column = new CensusColumnNationality($census, '', ''); 130 131 $this->assertSame('United States', $column->generate($individual)); 132 } 133} 134