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