xref: /webtrees/tests/app/Census/CensusColumnBirthPlaceSimpleTest.php (revision 819367e7d215c93f1776f3caa74eb42e78299461)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Census;
19
20use Fisharebest\Webtrees\Individual;
21use Fisharebest\Webtrees\Place;
22
23/**
24 * Test harness for the class CensusColumnBirthPlaceSimple
25 */
26class CensusColumnBirthPlaceSimpleTest extends \Fisharebest\Webtrees\TestCase
27{
28    /**
29     * Get place mock.
30     *
31     * @param string $place Gedcom Place
32     *
33     * @return Place
34     */
35    private function getPlaceMock($place): Place
36    {
37        $placeMock = $this->createMock(Place::class);
38        $placeMock->method('gedcomName')->willReturn($place);
39
40        return $placeMock;
41    }
42
43    /**
44     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
45     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
46     *
47     * @return void
48     */
49    public function testForeignCountry(): void
50    {
51        $individual = $this->createMock(Individual::class);
52        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Westminster, London, England'));
53
54        $census = $this->createMock(CensusInterface::class);
55        $census->method('censusPlace')->willReturn('United States');
56
57        $column = new CensusColumnBirthPlaceSimple($census, '', '');
58
59        $this->assertSame('England', $column->generate($individual, $individual));
60    }
61
62    /**
63     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
64     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
65     *
66     * @return void
67     */
68    public function testJustCountry(): void
69    {
70        $individual = $this->createMock(Individual::class);
71        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('United States'));
72
73        $census = $this->createMock(CensusInterface::class);
74        $census->method('censusPlace')->willReturn('United States');
75
76        $column = new CensusColumnBirthPlaceSimple($census, '', '');
77
78        $this->assertSame('', $column->generate($individual, $individual));
79    }
80
81    /**
82     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
83     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
84     *
85     * @return void
86     */
87    public function testKnownState(): void
88    {
89        $individual = $this->createMock(Individual::class);
90        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Maryland, United States'));
91
92        $census = $this->createMock(CensusInterface::class);
93        $census->method('censusPlace')->willReturn('United States');
94
95        $column = new CensusColumnBirthPlaceSimple($census, '', '');
96
97        $this->assertSame('Maryland', $column->generate($individual, $individual));
98    }
99
100    /**
101     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple
102     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
103     *
104     * @return void
105     */
106    public function testKnownStateAndTown(): void
107    {
108        $individual = $this->createMock(Individual::class);
109        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Miami, Florida, United States'));
110
111        $census = $this->createMock(CensusInterface::class);
112        $census->method('censusPlace')->willReturn('United States');
113
114        $column = new CensusColumnBirthPlaceSimple($census, '', '');
115
116        $this->assertSame('Florida', $column->generate($individual, $individual));
117    }
118}
119