xref: /webtrees/tests/app/Census/CensusColumnBirthPlaceSimpleTest.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Census;
20
21use Fisharebest\Webtrees\Individual;
22use Fisharebest\Webtrees\Place;
23
24/**
25 * Test harness for the class CensusColumnBirthPlaceSimple
26 */
27class CensusColumnBirthPlaceSimpleTest extends \Fisharebest\Webtrees\TestCase
28{
29    /**
30     * Get place mock.
31     *
32     * @param string $place Gedcom Place
33     *
34     * @return Place
35     */
36    private function getPlaceMock($place): Place
37    {
38        $placeMock = $this->createMock(Place::class);
39        $placeMock->method('gedcomName')->willReturn($place);
40
41        return $placeMock;
42    }
43
44    /**
45     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
46     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
47     *
48     * @return void
49     */
50    public function testForeignCountry(): void
51    {
52        $individual = $this->createMock(Individual::class);
53        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Westminster, London, England'));
54
55        $census = $this->createMock(CensusInterface::class);
56        $census->method('censusPlace')->willReturn('United States');
57
58        $column = new CensusColumnBirthPlaceSimple($census, '', '');
59
60        $this->assertSame('England', $column->generate($individual, $individual));
61    }
62
63    /**
64     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
65     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
66     *
67     * @return void
68     */
69    public function testJustCountry(): void
70    {
71        $individual = $this->createMock(Individual::class);
72        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('United States'));
73
74        $census = $this->createMock(CensusInterface::class);
75        $census->method('censusPlace')->willReturn('United States');
76
77        $column = new CensusColumnBirthPlaceSimple($census, '', '');
78
79        $this->assertSame('', $column->generate($individual, $individual));
80    }
81
82    /**
83     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
84     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
85     *
86     * @return void
87     */
88    public function testKnownState(): void
89    {
90        $individual = $this->createMock(Individual::class);
91        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Maryland, United States'));
92
93        $census = $this->createMock(CensusInterface::class);
94        $census->method('censusPlace')->willReturn('United States');
95
96        $column = new CensusColumnBirthPlaceSimple($census, '', '');
97
98        $this->assertSame('Maryland', $column->generate($individual, $individual));
99    }
100
101    /**
102     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
103     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
104     *
105     * @return void
106     */
107    public function testKnownStateAndTown(): void
108    {
109        $individual = $this->createMock(Individual::class);
110        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Miami, Florida, United States'));
111
112        $census = $this->createMock(CensusInterface::class);
113        $census->method('censusPlace')->willReturn('United States');
114
115        $column = new CensusColumnBirthPlaceSimple($census, '', '');
116
117        $this->assertSame('Florida', $column->generate($individual, $individual));
118    }
119}
120