xref: /webtrees/tests/app/Census/CensusColumnBirthPlaceTest.php (revision 803193fe6835fa954147d30cdf6ce1a1da6103ff)
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 CensusColumnBirthPlace
25 */
26class CensusColumnBirthPlaceTest 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\CensusColumnBirthPlace
45     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
46     *
47     * @return void
48     */
49    public function testPlaceCountry(): 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('England');
56
57        $column = new CensusColumnBirthPlace($census, '', '');
58
59        $this->assertSame('Westminster, London', $column->generate($individual, $individual));
60    }
61
62    /**
63     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace
64     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
65     *
66     * @return void
67     */
68    public function testPlaceAndCountry(): void
69    {
70        $individual = $this->createMock(Individual::class);
71        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('England'));
72
73        $census = $this->createMock(CensusInterface::class);
74        $census->method('censusPlace')->willReturn('England');
75
76        $column = new CensusColumnBirthPlace($census, '', '');
77
78        $this->assertSame('', $column->generate($individual, $individual));
79    }
80
81    /**
82     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace
83     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
84     *
85     * @return void
86     */
87    public function testDifferentCountry(): void
88    {
89        $individual = $this->createMock(Individual::class);
90        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Paris, France'));
91
92        $census = $this->createMock(CensusInterface::class);
93        $census->method('censusPlace')->willReturn('England');
94
95        $column = new CensusColumnBirthPlace($census, '', '');
96
97        $this->assertSame('Paris, France', $column->generate($individual, $individual));
98    }
99}
100