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