xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision 5e933c21f8006e675d1df8bcedc634ee61f4aec2)
17338314fSGreg Roach<?php
23976b470SGreg Roach
37338314fSGreg Roach/**
47338314fSGreg Roach * webtrees: online genealogy
5*5e933c21SGreg Roach * Copyright (C) 2020 webtrees development team
67338314fSGreg Roach * This program is free software: you can redistribute it and/or modify
77338314fSGreg Roach * it under the terms of the GNU General Public License as published by
87338314fSGreg Roach * the Free Software Foundation, either version 3 of the License, or
97338314fSGreg Roach * (at your option) any later version.
107338314fSGreg Roach * This program is distributed in the hope that it will be useful,
117338314fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
127338314fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137338314fSGreg Roach * GNU General Public License for more details.
147338314fSGreg Roach * You should have received a copy of the GNU General Public License
157338314fSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
167338314fSGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
207338314fSGreg Roachnamespace Fisharebest\Webtrees\Census;
217338314fSGreg Roach
227338314fSGreg Roachuse Fisharebest\Webtrees\Date;
23ddf438a5SGreg Roachuse Fisharebest\Webtrees\Fact;
24ddf438a5SGreg Roachuse Fisharebest\Webtrees\Individual;
2552348eb8SGreg Roachuse Fisharebest\Webtrees\Place;
263cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
2739ca88baSGreg Roachuse Illuminate\Support\Collection;
287338314fSGreg Roach
297338314fSGreg Roach/**
307338314fSGreg Roach * Test harness for the class CensusColumnNationality
317338314fSGreg Roach */
323cfcc809SGreg Roachclass CensusColumnNationalityTest extends TestCase
33c1010edaSGreg Roach{
347338314fSGreg Roach    /**
3516d0b7f7SRico Sonntag     * Get place mock.
3616d0b7f7SRico Sonntag     *
3716d0b7f7SRico Sonntag     * @param string $place Gedcom Place
3816d0b7f7SRico Sonntag     *
3952348eb8SGreg Roach     * @return Place
4016d0b7f7SRico Sonntag     */
41*5e933c21SGreg Roach    private function getPlaceMock(string $place): Place
42c1010edaSGreg Roach    {
43*5e933c21SGreg Roach        $placeMock = self::createMock(Place::class);
440ecdbde6SGreg Roach        $placeMock->method('gedcomName')->willReturn($place);
4516d0b7f7SRico Sonntag
4616d0b7f7SRico Sonntag        return $placeMock;
4716d0b7f7SRico Sonntag    }
4816d0b7f7SRico Sonntag
4916d0b7f7SRico Sonntag    /**
5015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
5115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
5252348eb8SGreg Roach     *
5352348eb8SGreg Roach     * @return void
547338314fSGreg Roach     */
559b802b22SGreg Roach    public function testNoBirthPlace(): void
56c1010edaSGreg Roach    {
57*5e933c21SGreg Roach        $individual = self::createMock(Individual::class);
580ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock(''));
590ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
6052f14e58SGreg Roach
61*5e933c21SGreg Roach        $census = self::createMock(CensusInterface::class);
620ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('Deutschland');
6352f14e58SGreg Roach
6452f14e58SGreg Roach        $column = new CensusColumnNationality($census, '', '');
6552f14e58SGreg Roach
66*5e933c21SGreg Roach        self::assertSame('Deutsch', $column->generate($individual, $individual));
6752f14e58SGreg Roach    }
6852f14e58SGreg Roach
6952f14e58SGreg Roach    /**
7015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
7115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
7252348eb8SGreg Roach     *
7352348eb8SGreg Roach     * @return void
7452f14e58SGreg Roach     */
759b802b22SGreg Roach    public function testPlaceCountry(): void
76c1010edaSGreg Roach    {
77*5e933c21SGreg Roach        $individual = self::createMock(Individual::class);
780ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia'));
790ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
807338314fSGreg Roach
81*5e933c21SGreg Roach        $census = self::createMock(CensusInterface::class);
820ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
837338314fSGreg Roach
847338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
857338314fSGreg Roach
86*5e933c21SGreg Roach        self::assertSame('Australia', $column->generate($individual, $individual));
877338314fSGreg Roach    }
887338314fSGreg Roach
897338314fSGreg Roach    /**
9015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
9115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
9252348eb8SGreg Roach     *
9352348eb8SGreg Roach     * @return void
947338314fSGreg Roach     */
959b802b22SGreg Roach    public function testBritish(): void
96c1010edaSGreg Roach    {
97*5e933c21SGreg Roach        $individual = self::createMock(Individual::class);
980ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
990ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
1007338314fSGreg Roach
101*5e933c21SGreg Roach        $census = self::createMock(CensusInterface::class);
1020ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
1037338314fSGreg Roach
1047338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
1057338314fSGreg Roach
106*5e933c21SGreg Roach        self::assertSame('British', $column->generate($individual, $individual));
1077338314fSGreg Roach    }
1087338314fSGreg Roach
1097338314fSGreg Roach    /**
11015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnNationality
11115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
11252348eb8SGreg Roach     *
11352348eb8SGreg Roach     * @return void
1147338314fSGreg Roach     */
1159b802b22SGreg Roach    public function testEmigrated(): void
116c1010edaSGreg Roach    {
117*5e933c21SGreg Roach        $place1 = self::createMock(Place::class);
1180ecdbde6SGreg Roach        $place1->method('gedcomName')->willReturn('United States');
1197338314fSGreg Roach
120*5e933c21SGreg Roach        $fact1 = self::createMock(Fact::class);
1210ecdbde6SGreg Roach        $fact1->method('place')->willReturn($place1);
1220ecdbde6SGreg Roach        $fact1->method('date')->willReturn(new Date('1855'));
1237338314fSGreg Roach
124*5e933c21SGreg Roach        $place2 = self::createMock(Place::class);
1250ecdbde6SGreg Roach        $place2->method('gedcomName')->willReturn('Australia');
1267338314fSGreg Roach
127*5e933c21SGreg Roach        $fact2 = self::createMock(Fact::class);
1280ecdbde6SGreg Roach        $fact2->method('place')->willReturn($place2);
1290ecdbde6SGreg Roach        $fact2->method('date')->willReturn(new Date('1865'));
1307338314fSGreg Roach
131*5e933c21SGreg Roach        $individual = self::createMock(Individual::class);
1320ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
1330ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([
13452f14e58SGreg Roach            $fact1,
13552f14e58SGreg Roach            $fact2,
13639ca88baSGreg Roach        ]));
1377338314fSGreg Roach
138*5e933c21SGreg Roach        $census = self::createMock(CensusInterface::class);
1390ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
1400ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('01 JUN 1860');
1417338314fSGreg Roach
1427338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
1437338314fSGreg Roach
144*5e933c21SGreg Roach        self::assertSame('United States', $column->generate($individual, $individual));
1457338314fSGreg Roach    }
1467338314fSGreg Roach}
147