xref: /webtrees/tests/app/Census/CensusColumnNationalityTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
17338314fSGreg Roach<?php
23976b470SGreg Roach
37338314fSGreg Roach/**
47338314fSGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://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;
28*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
297338314fSGreg Roach
30*202c018bSGreg Roach
31*202c018bSGreg Roach#[CoversClass(CensusColumnNationality::class)]
32*202c018bSGreg Roach#[CoversClass(AbstractCensusColumn::class)]
333cfcc809SGreg Roachclass CensusColumnNationalityTest extends TestCase
34c1010edaSGreg Roach{
355e933c21SGreg Roach    private function getPlaceMock(string $place): Place
36c1010edaSGreg Roach    {
37cd94ca66SGreg Roach        $placeMock = $this->createMock(Place::class);
380ecdbde6SGreg Roach        $placeMock->method('gedcomName')->willReturn($place);
3916d0b7f7SRico Sonntag
4016d0b7f7SRico Sonntag        return $placeMock;
4116d0b7f7SRico Sonntag    }
4216d0b7f7SRico Sonntag
439b802b22SGreg Roach    public function testNoBirthPlace(): void
44c1010edaSGreg Roach    {
45cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
460ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock(''));
470ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
4852f14e58SGreg Roach
49cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
500ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('Deutschland');
5152f14e58SGreg Roach
5252f14e58SGreg Roach        $column = new CensusColumnNationality($census, '', '');
5352f14e58SGreg Roach
545e933c21SGreg Roach        self::assertSame('Deutsch', $column->generate($individual, $individual));
5552f14e58SGreg Roach    }
5652f14e58SGreg Roach
579b802b22SGreg Roach    public function testPlaceCountry(): void
58c1010edaSGreg Roach    {
59cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
600ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Australia'));
610ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
627338314fSGreg Roach
63cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
640ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
657338314fSGreg Roach
667338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
677338314fSGreg Roach
685e933c21SGreg Roach        self::assertSame('Australia', $column->generate($individual, $individual));
697338314fSGreg Roach    }
707338314fSGreg Roach
719b802b22SGreg Roach    public function testBritish(): void
72c1010edaSGreg Roach    {
73cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
740ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
750ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection());
767338314fSGreg Roach
77cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
780ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
797338314fSGreg Roach
807338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
817338314fSGreg Roach
825e933c21SGreg Roach        self::assertSame('British', $column->generate($individual, $individual));
837338314fSGreg Roach    }
847338314fSGreg Roach
859b802b22SGreg Roach    public function testEmigrated(): void
86c1010edaSGreg Roach    {
87cd94ca66SGreg Roach        $place1 = $this->createMock(Place::class);
880ecdbde6SGreg Roach        $place1->method('gedcomName')->willReturn('United States');
897338314fSGreg Roach
90cd94ca66SGreg Roach        $fact1 = $this->createMock(Fact::class);
910ecdbde6SGreg Roach        $fact1->method('place')->willReturn($place1);
920ecdbde6SGreg Roach        $fact1->method('date')->willReturn(new Date('1855'));
937338314fSGreg Roach
94cd94ca66SGreg Roach        $place2 = $this->createMock(Place::class);
950ecdbde6SGreg Roach        $place2->method('gedcomName')->willReturn('Australia');
967338314fSGreg Roach
97cd94ca66SGreg Roach        $fact2 = $this->createMock(Fact::class);
980ecdbde6SGreg Roach        $fact2->method('place')->willReturn($place2);
990ecdbde6SGreg Roach        $fact2->method('date')->willReturn(new Date('1865'));
1007338314fSGreg Roach
101cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1020ecdbde6SGreg Roach        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
1030ecdbde6SGreg Roach        $individual->method('facts')->with(['IMMI', 'EMIG', 'NATU'], true)->willReturn(new Collection([
10452f14e58SGreg Roach            $fact1,
10552f14e58SGreg Roach            $fact2,
10639ca88baSGreg Roach        ]));
1077338314fSGreg Roach
108cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
1090ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
1100ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('01 JUN 1860');
1117338314fSGreg Roach
1127338314fSGreg Roach        $column = new CensusColumnNationality($census, '', '');
1137338314fSGreg Roach
1145e933c21SGreg Roach        self::assertSame('United States', $column->generate($individual, $individual));
1157338314fSGreg Roach    }
1167338314fSGreg Roach}
117