xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision a45f98897789fc9ff88705eb09ae5f037bf49c10)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2018 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    /**
28     * Delete mock objects
29     */
30    public function tearDown()
31    {
32        Mockery::close();
33    }
34
35    /**
36     * Get place mock.
37     *
38     * @param string $place Gedcom Place
39     *
40     * @return \Fisharebest\Webtrees\Place
41     */
42    private function getPlaceMock($place)
43    {
44        $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
45        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
46
47        return $placeMock;
48    }
49
50    /**
51     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
52     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
53     */
54    public function testNoBirthPlace()
55    {
56        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
57        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock(''));
58        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
59
60        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
61        $census->shouldReceive('censusPlace')->andReturn('Deutschland');
62
63        $column = new CensusColumnNationality($census, '', '');
64
65        $this->assertSame('Deutsch', $column->generate($individual, $individual));
66    }
67
68    /**
69     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
70     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
71     */
72    public function testPlaceCountry()
73    {
74        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
75        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia'));
76        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
77
78        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
79        $census->shouldReceive('censusPlace')->andReturn('England');
80
81        $column = new CensusColumnNationality($census, '', '');
82
83        $this->assertSame('Australia', $column->generate($individual, $individual));
84    }
85
86    /**
87     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
88     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
89     */
90    public function testBritish()
91    {
92        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
93        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
94        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
95
96        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
97        $census->shouldReceive('censusPlace')->andReturn('England');
98
99        $column = new CensusColumnNationality($census, '', '');
100
101        $this->assertSame('British', $column->generate($individual, $individual));
102    }
103
104    /**
105     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
106     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
107     */
108    public function testEmigrated()
109    {
110        $place1 = Mockery::mock('Fisharebest\Webtrees\Place');
111        $place1->shouldReceive('getGedcomName')->andReturn('United States');
112
113        $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact');
114        $fact1->shouldReceive('getPlace')->andReturn($place1);
115        $fact1->shouldReceive('getDate')->andReturn(new Date('1855'));
116
117        $place2 = Mockery::mock('Fisharebest\Webtrees\Place');
118        $place2->shouldReceive('getGedcomName')->andReturn('Australia');
119
120        $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact');
121        $fact2->shouldReceive('getPlace')->andReturn($place2);
122        $fact2->shouldReceive('getDate')->andReturn(new Date('1865'));
123
124        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
125        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
126        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([
127            $fact1,
128            $fact2,
129        ]);
130
131        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
132        $census->shouldReceive('censusPlace')->andReturn('England');
133        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
134
135        $column = new CensusColumnNationality($census, '', '');
136
137        $this->assertSame('United States', $column->generate($individual, $individual));
138    }
139}
140