xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision 081147b95980645ee0f905276120bd50aff10f67)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\Census;
17
18use Fisharebest\Webtrees\Date;
19use Fisharebest\Webtrees\Place;
20use Mockery;
21
22/**
23 * Test harness for the class CensusColumnNationality
24 */
25class CensusColumnNationalityTest extends \Fisharebest\Webtrees\TestCase
26{
27    /**
28     * Delete mock objects
29     *
30     * @return void
31     */
32    public function tearDown()
33    {
34        Mockery::close();
35    }
36
37    /**
38     * Get place mock.
39     *
40     * @param string $place Gedcom Place
41     *
42     * @return Place
43     */
44    private function getPlaceMock($place): Place
45    {
46        $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
47        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
48
49        return $placeMock;
50    }
51
52    /**
53     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
54     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
55     *
56     * @return void
57     */
58    public function testNoBirthPlace()
59    {
60        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
61        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock(''));
62        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
63
64        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
65        $census->shouldReceive('censusPlace')->andReturn('Deutschland');
66
67        $column = new CensusColumnNationality($census, '', '');
68
69        $this->assertSame('Deutsch', $column->generate($individual, $individual));
70    }
71
72    /**
73     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
74     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
75     *
76     * @return void
77     */
78    public function testPlaceCountry()
79    {
80        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
81        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Australia'));
82        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
83
84        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
85        $census->shouldReceive('censusPlace')->andReturn('England');
86
87        $column = new CensusColumnNationality($census, '', '');
88
89        $this->assertSame('Australia', $column->generate($individual, $individual));
90    }
91
92    /**
93     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
94     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
95     *
96     * @return void
97     */
98    public function testBritish()
99    {
100        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
101        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
102        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([]);
103
104        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
105        $census->shouldReceive('censusPlace')->andReturn('England');
106
107        $column = new CensusColumnNationality($census, '', '');
108
109        $this->assertSame('British', $column->generate($individual, $individual));
110    }
111
112    /**
113     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
114     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
115     *
116     * @return void
117     */
118    public function testEmigrated()
119    {
120        $place1 = Mockery::mock('Fisharebest\Webtrees\Place');
121        $place1->shouldReceive('getGedcomName')->andReturn('United States');
122
123        $fact1 = Mockery::mock('Fisharebest\Webtrees\Fact');
124        $fact1->shouldReceive('getPlace')->andReturn($place1);
125        $fact1->shouldReceive('getDate')->andReturn(new Date('1855'));
126
127        $place2 = Mockery::mock('Fisharebest\Webtrees\Place');
128        $place2->shouldReceive('getGedcomName')->andReturn('Australia');
129
130        $fact2 = Mockery::mock('Fisharebest\Webtrees\Fact');
131        $fact2->shouldReceive('getPlace')->andReturn($place2);
132        $fact2->shouldReceive('getDate')->andReturn(new Date('1865'));
133
134        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
135        $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
136        $individual->shouldReceive('getFacts')->with('IMMI|EMIG|NATU', true)->andReturn([
137            $fact1,
138            $fact2,
139        ]);
140
141        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
142        $census->shouldReceive('censusPlace')->andReturn('England');
143        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
144
145        $column = new CensusColumnNationality($census, '', '');
146
147        $this->assertSame('United States', $column->generate($individual, $individual));
148    }
149}
150