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