xref: /webtrees/tests/app/Census/CensusColumnFatherBirthPlaceTest.php (revision e7f56f2af615447ab1a7646851f88b465ace9e04)
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 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Census;
19
20use Fisharebest\Webtrees\Place;
21use Mockery;
22
23/**
24 * Test harness for the class CensusColumnFatherBirthPlace
25 */
26class CensusColumnFatherBirthPlaceTest extends \Fisharebest\Webtrees\TestCase
27{
28    /**
29     * Delete mock objects
30     *
31     * @return void
32     */
33    public function tearDown()
34    {
35        Mockery::close();
36    }
37
38    /**
39     * Get place mock.
40     *
41     * @param string $place Gedcom Place
42     *
43     * @return Place
44     */
45    private function getPlaceMock($place): Place
46    {
47        $placeParts = explode(', ', $place);
48
49        $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
50        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
51        $placeMock->shouldReceive('lastPart')->andReturn(end($placeParts));
52
53        return $placeMock;
54    }
55
56    /**
57     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
58     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
59     *
60     * @return void
61     */
62    public function testSameCountry()
63    {
64        $father = Mockery::mock('Fisharebest\Webtrees\Individual');
65        $father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
66
67        $family = Mockery::mock('Fisharebest\Webtrees\Family');
68        $family->shouldReceive('getHusband')->andReturn($father);
69
70        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
71        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
72
73        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
74        $census->shouldReceive('censusPlace')->andReturn('England');
75
76        $column = new CensusColumnFatherBirthPlace($census, '', '');
77
78        $this->assertSame('London', $column->generate($individual, $individual));
79    }
80
81    /**
82     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
83     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
84     *
85     * @return void
86     */
87    public function testDifferentCountry()
88    {
89        $father = Mockery::mock('Fisharebest\Webtrees\Individual');
90        $father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
91
92        $family = Mockery::mock('Fisharebest\Webtrees\Family');
93        $family->shouldReceive('getHusband')->andReturn($father);
94
95        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
96        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
97
98        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
99        $census->shouldReceive('censusPlace')->andReturn('Ireland');
100
101        $column = new CensusColumnFatherBirthPlace($census, '', '');
102
103        $this->assertSame('London, England', $column->generate($individual, $individual));
104    }
105
106    /**
107     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
108     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
109     *
110     * @return void
111     */
112    public function testPlaceNoParent()
113    {
114        $family = Mockery::mock('Fisharebest\Webtrees\Family');
115        $family->shouldReceive('getHusband')->andReturn(null);
116
117        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
118        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
119
120        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
121        $census->shouldReceive('censusPlace')->andReturn('England');
122
123        $column = new CensusColumnFatherBirthPlace($census, '', '');
124
125        $this->assertSame('', $column->generate($individual, $individual));
126    }
127
128    /**
129     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
130     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
131     *
132     * @return void
133     */
134    public function testPlaceNoParentFamily()
135    {
136        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
137        $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null);
138
139        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
140        $census->shouldReceive('censusPlace')->andReturn('England');
141
142        $column = new CensusColumnFatherBirthPlace($census, '', '');
143
144        $this->assertSame('', $column->generate($individual, $individual));
145    }
146}
147