xref: /webtrees/tests/app/Census/CensusColumnMotherBirthPlaceTest.php (revision cd94ca6664a143daa60d394f7b9cad6d42ec1b1d)
1a53db70dSGreg Roach<?php
23976b470SGreg Roach
3a53db70dSGreg Roach/**
4a53db70dSGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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;
27a53db70dSGreg Roach
28a53db70dSGreg Roach/**
29a53db70dSGreg Roach * Test harness for the class CensusColumnMotherBirthPlace
30a53db70dSGreg Roach */
313cfcc809SGreg Roachclass CensusColumnMotherBirthPlaceTest extends TestCase
32c1010edaSGreg Roach{
33a53db70dSGreg Roach    /**
3416d0b7f7SRico Sonntag     * Get place mock.
3516d0b7f7SRico Sonntag     *
3616d0b7f7SRico Sonntag     * @param string $place Gedcom Place
3716d0b7f7SRico Sonntag     *
3852348eb8SGreg Roach     * @return Place
3916d0b7f7SRico Sonntag     */
405e933c21SGreg Roach    private function getPlaceMock(string $place): Place
41c1010edaSGreg Roach    {
4216d0b7f7SRico Sonntag        $placeParts = explode(', ', $place);
4316d0b7f7SRico Sonntag
44*cd94ca66SGreg Roach        $placeMock = $this->createMock(Place::class);
450ecdbde6SGreg Roach        $placeMock->method('gedcomName')->willReturn($place);
460ecdbde6SGreg Roach        $placeMock->method('lastParts')->willReturn(new Collection($placeParts));
4716d0b7f7SRico Sonntag
4816d0b7f7SRico Sonntag        return $placeMock;
4916d0b7f7SRico Sonntag    }
5016d0b7f7SRico Sonntag
5116d0b7f7SRico Sonntag    /**
5215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace
5315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
5452348eb8SGreg Roach     *
5552348eb8SGreg Roach     * @return void
56a53db70dSGreg Roach     */
579b802b22SGreg Roach    public function testSameCountry(): void
58c1010edaSGreg Roach    {
59*cd94ca66SGreg Roach        $mother = $this->createMock(Individual::class);
600ecdbde6SGreg Roach        $mother->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
61a53db70dSGreg Roach
62*cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
630ecdbde6SGreg Roach        $family->method('wife')->willReturn($mother);
64a53db70dSGreg Roach
65*cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
661afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection([$family]));
67a53db70dSGreg Roach
68*cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
690ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
70a53db70dSGreg Roach
71a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
72a53db70dSGreg Roach
735e933c21SGreg Roach        self::assertSame('London', $column->generate($individual, $individual));
74a53db70dSGreg Roach    }
75a53db70dSGreg Roach
76a53db70dSGreg Roach    /**
7715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace
7815d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
7952348eb8SGreg Roach     *
8052348eb8SGreg Roach     * @return void
81a53db70dSGreg Roach     */
829b802b22SGreg Roach    public function testDifferentCountry(): void
83c1010edaSGreg Roach    {
84*cd94ca66SGreg Roach        $mother = $this->createMock(Individual::class);
850ecdbde6SGreg Roach        $mother->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
86a53db70dSGreg Roach
87*cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
880ecdbde6SGreg Roach        $family->method('wife')->willReturn($mother);
89a53db70dSGreg Roach
90*cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
911afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection([$family]));
92a53db70dSGreg Roach
93*cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
940ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('Ireland');
95a53db70dSGreg Roach
96a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
97a53db70dSGreg Roach
985e933c21SGreg Roach        self::assertSame('London, England', $column->generate($individual, $individual));
99a53db70dSGreg Roach    }
100a53db70dSGreg Roach
101a53db70dSGreg Roach    /**
10215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace
10315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
10452348eb8SGreg Roach     *
10552348eb8SGreg Roach     * @return void
106a53db70dSGreg Roach     */
1079b802b22SGreg Roach    public function testPlaceNoParent(): void
108c1010edaSGreg Roach    {
109*cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
1100ecdbde6SGreg Roach        $family->method('wife')->willReturn(null);
111a53db70dSGreg Roach
112*cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1131afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection([$family]));
114a53db70dSGreg Roach
115*cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
1160ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
117a53db70dSGreg Roach
118a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
119a53db70dSGreg Roach
1205e933c21SGreg Roach        self::assertSame('', $column->generate($individual, $individual));
121a53db70dSGreg Roach    }
122a53db70dSGreg Roach
123a53db70dSGreg Roach    /**
12415d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace
12515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
12652348eb8SGreg Roach     *
12752348eb8SGreg Roach     * @return void
128a53db70dSGreg Roach     */
1299b802b22SGreg Roach    public function testPlaceNoParentFamily(): void
130c1010edaSGreg Roach    {
131*cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1321afbbc50SGreg Roach        $individual->method('childFamilies')->willReturn(new Collection());
133a53db70dSGreg Roach
134*cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
1350ecdbde6SGreg Roach        $census->method('censusPlace')->willReturn('England');
136a53db70dSGreg Roach
137a53db70dSGreg Roach        $column = new CensusColumnMotherBirthPlace($census, '', '');
138a53db70dSGreg Roach
1395e933c21SGreg Roach        self::assertSame('', $column->generate($individual, $individual));
140a53db70dSGreg Roach    }
141a53db70dSGreg Roach}
142