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