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