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