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