xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision 73df4c545c87012519818766e1a8eb02272a59b5)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2016 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	 * @covers Fisharebest\Webtrees\Census\CensusColumnNationality
35	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
36	 */
37	public function testPlaceCountry() {
38		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
39		$individual->shouldReceive('getBirthPlace')->andReturn('Australia');
40		$individual->shouldReceive('getFacts')->andReturn(array());
41
42		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
43		$census->shouldReceive('censusPlace')->andReturn('England');
44
45		$column = new CensusColumnNationality($census, '', '');
46
47		$this->assertSame('Australia', $column->generate($individual));
48	}
49
50	/**
51	 * @covers Fisharebest\Webtrees\Census\CensusColumnNationality
52	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
53	 */
54	public function testBritish() {
55		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
56		$individual->shouldReceive('getBirthPlace')->andReturn('London, England');
57		$individual->shouldReceive('getFacts')->andReturn(array());
58
59		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
60		$census->shouldReceive('censusPlace')->andReturn('England');
61
62		$column = new CensusColumnNationality($census, '', '');
63
64		$this->assertSame('British', $column->generate($individual));
65	}
66
67	/**
68	 * @covers Fisharebest\Webtrees\Census\CensusColumnNationality
69	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
70	 */
71	public function testEmigrated() {
72		$place1 = Mockery::mock('Fisharebest\Webtrees\Place');
73		$place1->shouldReceive('getGedcomName')->andReturn('United States');
74
75		$fact1 = Mockery::mock('Fisharebest\Webtrees\Fact');
76		$fact1->shouldReceive('getPlace')->andReturn($place1);
77		$fact1->shouldReceive('getDate')->andReturn(new Date('1855'));
78
79		$place2 = Mockery::mock('Fisharebest\Webtrees\Place');
80		$place2->shouldReceive('getGedcomName')->andReturn('Australia');
81
82		$fact2 = Mockery::mock('Fisharebest\Webtrees\Fact');
83		$fact2->shouldReceive('getPlace')->andReturn($place2);
84		$fact2->shouldReceive('getDate')->andReturn(new Date('1865'));
85
86		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
87		$individual->shouldReceive('getBirthPlace')->andReturn('London, England');
88		$individual->shouldReceive('getFacts')->andReturn(array($fact1, $fact2));
89
90		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
91		$census->shouldReceive('censusPlace')->andReturn('England');
92		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
93
94		$column = new CensusColumnNationality($census, '', '');
95
96		$this->assertSame('United States', $column->generate($individual));
97	}
98}
99