xref: /webtrees/tests/app/Census/CensusColumnMotherBirthPlaceTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
1a53db70dSGreg Roach<?php
23976b470SGreg Roach
3a53db70dSGreg Roach/**
4a53db70dSGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6a53db70dSGreg Roach * This program is free software: you can redistribute it and/or modify
7a53db70dSGreg Roach * it under the terms of the GNU General Public License as published by
8a53db70dSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a53db70dSGreg Roach * (at your option) any later version.
10a53db70dSGreg Roach * This program is distributed in the hope that it will be useful,
11a53db70dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a53db70dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a53db70dSGreg Roach * GNU General Public License for more details.
14a53db70dSGreg 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/>.
16a53db70dSGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
20a53db70dSGreg Roachnamespace Fisharebest\Webtrees\Census;
21a53db70dSGreg Roach
22ddf438a5SGreg Roachuse Fisharebest\Webtrees\Family;
23ddf438a5SGreg Roachuse Fisharebest\Webtrees\Individual;
2452348eb8SGreg Roachuse Fisharebest\Webtrees\Place;
253cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
26392561bbSGreg Roachuse Illuminate\Support\Collection;
27*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
28a53db70dSGreg Roach
29*202c018bSGreg Roach#[CoversClass(CensusColumnMotherBirthPlace::class)]
30*202c018bSGreg Roach#[CoversClass(AbstractCensusColumn::class)]
313cfcc809SGreg Roachclass CensusColumnMotherBirthPlaceTest extends TestCase
32c1010edaSGreg Roach{
335e933c21SGreg Roach    private function getPlaceMock(string $place): Place
34c1010edaSGreg Roach    {
3516d0b7f7SRico Sonntag        $placeParts = explode(', ', $place);
3616d0b7f7SRico Sonntag
37cd94ca66SGreg Roach        $placeMock = $this->createMock(Place::class);
380ecdbde6SGreg Roach        $placeMock->method('gedcomName')->willReturn($place);
390ecdbde6SGreg Roach        $placeMock->method('lastParts')->willReturn(new Collection($placeParts));
4016d0b7f7SRico Sonntag
4116d0b7f7SRico Sonntag        return $placeMock;
4216d0b7f7SRico Sonntag    }
4316d0b7f7SRico Sonntag
449b802b22SGreg Roach    public function testSameCountry(): void
45c1010edaSGreg Roach    {
46cd94ca66SGreg Roach        $mother = $this->createMock(Individual::class);
470ecdbde6SGreg Roach        $mother->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
48a53db70dSGreg Roach
49cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
500ecdbde6SGreg Roach        $family->method('wife')->willReturn($mother);
51a53db70dSGreg Roach
52cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
531afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection([$family]));
54a53db70dSGreg Roach
55cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
560ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
57a53db70dSGreg Roach
58a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
59a53db70dSGreg Roach
605e933c21SGreg Roach        self::assertSame('London', $column->generate($individual, $individual));
61a53db70dSGreg Roach    }
62a53db70dSGreg Roach
639b802b22SGreg Roach    public function testDifferentCountry(): void
64c1010edaSGreg Roach    {
65cd94ca66SGreg Roach        $mother = $this->createMock(Individual::class);
660ecdbde6SGreg Roach        $mother->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
67a53db70dSGreg Roach
68cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
690ecdbde6SGreg Roach        $family->method('wife')->willReturn($mother);
70a53db70dSGreg Roach
71cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
721afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection([$family]));
73a53db70dSGreg Roach
74cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
750ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('Ireland');
76a53db70dSGreg Roach
77a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
78a53db70dSGreg Roach
795e933c21SGreg Roach        self::assertSame('London, England', $column->generate($individual, $individual));
80a53db70dSGreg Roach    }
81a53db70dSGreg Roach
829b802b22SGreg Roach    public function testPlaceNoParent(): void
83c1010edaSGreg Roach    {
84cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
850ecdbde6SGreg Roach        $family->method('wife')->willReturn(null);
86a53db70dSGreg Roach
87cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
881afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection([$family]));
89a53db70dSGreg Roach
90cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
910ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
92a53db70dSGreg Roach
93a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
94a53db70dSGreg Roach
955e933c21SGreg Roach        self::assertSame('', $column->generate($individual, $individual));
96a53db70dSGreg Roach    }
97a53db70dSGreg Roach
989b802b22SGreg Roach    public function testPlaceNoParentFamily(): void
99c1010edaSGreg Roach    {
100cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1011afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection());
102a53db70dSGreg Roach
103cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
1040ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
105a53db70dSGreg Roach
106a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
107a53db70dSGreg Roach
1085e933c21SGreg Roach        self::assertSame('', $column->generate($individual, $individual));
109a53db70dSGreg Roach    }
110a53db70dSGreg Roach}
111