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