xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision 69fe156391f8cfe766ebbeee448fc4cc7700b11c)
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	 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
35	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
36	 */
37	public function testNoBirthPlace() {
38		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
39		$individual->shouldReceive('getBirthPlace')->andReturn('');
40		$individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
41
42		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
43		$census->shouldReceive('censusPlace')->andReturn('Deutschland');
44
45		$column = new CensusColumnNationality($census, '', '');
46
47		$this->assertSame('Deutsch', $column->generate($individual));
48	}
49
50	/**
51	 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
52	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
53	 */
54	public function testPlaceCountry() {
55		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
56		$individual->shouldReceive('getBirthPlace')->andReturn('Australia');
57		$individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
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('Australia', $column->generate($individual));
65	}
66
67	/**
68	 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
69	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
70	 */
71	public function testBritish() {
72		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
73		$individual->shouldReceive('getBirthPlace')->andReturn('London, England');
74		$individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
75
76		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
77		$census->shouldReceive('censusPlace')->andReturn('England');
78
79		$column = new CensusColumnNationality($census, '', '');
80
81		$this->assertSame('British', $column->generate($individual));
82	}
83
84	/**
85	 * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
86	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
87	 */
88	public function testEmigrated() {
89		$place1 = Mockery::mock('Fisharebest\Webtrees\Place');
90		$place1->shouldReceive('getGedcomName')->andReturn('United States');
91
92		$fact1 = Mockery::mock('Fisharebest\Webtrees\Fact');
93		$fact1->shouldReceive('getPlace')->andReturn($place1);
94		$fact1->shouldReceive('getDate')->andReturn(new Date('1855'));
95
96		$place2 = Mockery::mock('Fisharebest\Webtrees\Place');
97		$place2->shouldReceive('getGedcomName')->andReturn('Australia');
98
99		$fact2 = Mockery::mock('Fisharebest\Webtrees\Fact');
100		$fact2->shouldReceive('getPlace')->andReturn($place2);
101		$fact2->shouldReceive('getDate')->andReturn(new Date('1865'));
102
103		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
104		$individual->shouldReceive('getBirthPlace')->andReturn('London, England');
105		$individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([
106			$fact1,
107			$fact2,
108		]);
109
110		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
111		$census->shouldReceive('censusPlace')->andReturn('England');
112		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
113
114		$column = new CensusColumnNationality($census, '', '');
115
116		$this->assertSame('United States', $column->generate($individual));
117	}
118}
119