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