xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision be2b3f4df0e459b29aadff26be27e15c8ee9b3b4)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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 <https://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    private function getPlaceMock(string $place): Place
35    {
36        $placeMock = $this->createMock(Place::class);
37        $placeMock->method('gedcomName')->willReturn($place);
38
39        return $placeMock;
40    }
41
42    /**
43     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
44     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
45     */
46    public function testNoBirthPlace(): void
47    {
48        $individual = $this->createMock(Individual::class);
49        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock(''));
50        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
51
52        $census = $this->createMock(CensusInterface::class);
53        $census->method('censusPlace')->willReturn('Deutschland');
54
55        $column = new CensusColumnNationality($census, '', '');
56
57        self::assertSame('Deutsch', $column->generate($individual, $individual));
58    }
59
60    /**
61     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
62     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
63     */
64    public function testPlaceCountry(): void
65    {
66        $individual = $this->createMock(Individual::class);
67        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia'));
68        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
69
70        $census = $this->createMock(CensusInterface::class);
71        $census->method('censusPlace')->willReturn('England');
72
73        $column = new CensusColumnNationality($census, '', '');
74
75        self::assertSame('Australia', $column->generate($individual, $individual));
76    }
77
78    /**
79     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
80     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
81     */
82    public function testBritish(): void
83    {
84        $individual = $this->createMock(Individual::class);
85        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
86        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
87
88        $census = $this->createMock(CensusInterface::class);
89        $census->method('censusPlace')->willReturn('England');
90
91        $column = new CensusColumnNationality($census, '', '');
92
93        self::assertSame('British', $column->generate($individual, $individual));
94    }
95
96    /**
97     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
98     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
99     */
100    public function testEmigrated(): void
101    {
102        $place1 = $this->createMock(Place::class);
103        $place1->method('gedcomName')->willReturn('United States');
104
105        $fact1 = $this->createMock(Fact::class);
106        $fact1->method('place')->willReturn($place1);
107        $fact1->method('date')->willReturn(new Date('1855'));
108
109        $place2 = $this->createMock(Place::class);
110        $place2->method('gedcomName')->willReturn('Australia');
111
112        $fact2 = $this->createMock(Fact::class);
113        $fact2->method('place')->willReturn($place2);
114        $fact2->method('date')->willReturn(new Date('1865'));
115
116        $individual = $this->createMock(Individual::class);
117        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
118        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([
119            $fact1,
120            $fact2,
121        ]));
122
123        $census = $this->createMock(CensusInterface::class);
124        $census->method('censusPlace')->willReturn('England');
125        $census->method('censusDate')->willReturn('01 JUN 1860');
126
127        $column = new CensusColumnNationality($census, '', '');
128
129        self::assertSame('United States', $column->generate($individual, $individual));
130    }
131}
132