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