xref: /webtrees/tests/app/Census/CensusColumnFatherForeignTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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\Family;
23use Fisharebest\Webtrees\Individual;
24use Fisharebest\Webtrees\Place;
25use Fisharebest\Webtrees\TestCase;
26use Illuminate\Support\Collection;
27use PHPUnit\Framework\Attributes\CoversClass;
28
29
30#[CoversClass(CensusColumnFatherForeign::class)]
31#[CoversClass(AbstractCensusColumn::class)]
32class CensusColumnFatherForeignTest 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    public function testSameCountry(): void
43    {
44        $father = $this->createMock(Individual::class);
45        $father->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
46
47        $family = $this->createMock(Family::class);
48        $family->method('husband')->willReturn($father);
49
50        $individual = $this->createMock(Individual::class);
51        $individual->method('childFamilies')->willReturn(new Collection([$family]));
52
53        $census = $this->createMock(CensusInterface::class);
54        $census->method('censusPlace')->willReturn('England');
55
56        $column = new CensusColumnFatherForeign($census, '', '');
57
58        self::assertSame('', $column->generate($individual, $individual));
59    }
60
61    public function testDifferentCountry(): void
62    {
63        $father = $this->createMock(Individual::class);
64        $father->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
65
66        $family = $this->createMock(Family::class);
67        $family->method('husband')->willReturn($father);
68
69        $individual = $this->createMock(Individual::class);
70        $individual->method('childFamilies')->willReturn(new Collection([$family]));
71
72        $census = $this->createMock(CensusInterface::class);
73        $census->method('censusPlace')->willReturn('Ireland');
74
75        $column = new CensusColumnFatherForeign($census, '', '');
76
77        self::assertSame('Y', $column->generate($individual, $individual));
78    }
79
80    public function testPlaceNoParent(): void
81    {
82        $family = $this->createMock(Family::class);
83        $family->method('husband')->willReturn(null);
84
85        $individual = $this->createMock(Individual::class);
86        $individual->method('childFamilies')->willReturn(new Collection([$family]));
87
88        $census = $this->createMock(CensusInterface::class);
89        $census->method('censusPlace')->willReturn('England');
90
91        $column = new CensusColumnFatherForeign($census, '', '');
92
93        self::assertSame('', $column->generate($individual, $individual));
94    }
95
96    public function testPlaceNoParentFamily(): void
97    {
98        $individual = $this->createMock(Individual::class);
99        $individual->method('childFamilies')->willReturn(new Collection());
100
101        $census = $this->createMock(CensusInterface::class);
102        $census->method('censusPlace')->willReturn('England');
103
104        $column = new CensusColumnFatherForeign($census, '', '');
105
106        self::assertSame('', $column->generate($individual, $individual));
107    }
108}
109