xref: /webtrees/tests/app/Census/CensusColumnBirthPlaceTest.php (revision 1a218474113038005e50986fff24ebcbd58554ff)
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;
23use Fisharebest\Webtrees\TestCase;
24
25/**
26 * Test harness for the class CensusColumnBirthPlace
27 */
28class CensusColumnBirthPlaceTest extends TestCase
29{
30    /**
31     * Get place mock.
32     *
33     * @param string $place Gedcom Place
34     *
35     * @return Place
36     */
37    private function getPlaceMock($place): Place
38    {
39        $placeMock = $this->createMock(Place::class);
40        $placeMock->method('gedcomName')->willReturn($place);
41
42        return $placeMock;
43    }
44
45    /**
46     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace
47     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
48     *
49     * @return void
50     */
51    public function testPlaceCountry(): void
52    {
53        $individual = $this->createMock(Individual::class);
54        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Westminster, London, England'));
55
56        $census = $this->createMock(CensusInterface::class);
57        $census->method('censusPlace')->willReturn('England');
58
59        $column = new CensusColumnBirthPlace($census, '', '');
60
61        $this->assertSame('Westminster, London', $column->generate($individual, $individual));
62    }
63
64    /**
65     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace
66     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
67     *
68     * @return void
69     */
70    public function testPlaceAndCountry(): void
71    {
72        $individual = $this->createMock(Individual::class);
73        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('England'));
74
75        $census = $this->createMock(CensusInterface::class);
76        $census->method('censusPlace')->willReturn('England');
77
78        $column = new CensusColumnBirthPlace($census, '', '');
79
80        $this->assertSame('', $column->generate($individual, $individual));
81    }
82
83    /**
84     * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace
85     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
86     *
87     * @return void
88     */
89    public function testDifferentCountry(): void
90    {
91        $individual = $this->createMock(Individual::class);
92        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Paris, France'));
93
94        $census = $this->createMock(CensusInterface::class);
95        $census->method('censusPlace')->willReturn('England');
96
97        $column = new CensusColumnBirthPlace($census, '', '');
98
99        $this->assertSame('Paris, France', $column->generate($individual, $individual));
100    }
101}
102