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