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