xref: /webtrees/tests/app/Census/CensusColumnMotherForeignTest.php (revision 67994fb087e1b24564a780e4ae8aeff801733e35)
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 CensusColumnMotherForeign
25 */
26class CensusColumnMotherForeignTest 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        $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
48        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
49
50        return $placeMock;
51    }
52
53    /**
54     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign
55     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
56     *
57     * @return void
58     */
59    public function testSameCountry()
60    {
61        $mother = Mockery::mock('Fisharebest\Webtrees\Individual');
62        $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
63
64        $family = Mockery::mock('Fisharebest\Webtrees\Family');
65        $family->shouldReceive('getWife')->andReturn($mother);
66
67        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
68        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
69
70        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
71        $census->shouldReceive('censusPlace')->andReturn('England');
72
73        $column = new CensusColumnMotherForeign($census, '', '');
74
75        $this->assertSame('', $column->generate($individual, $individual));
76    }
77
78    /**
79     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign
80     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
81     *
82     * @return void
83     */
84    public function testDifferentCountry()
85    {
86        $mother = Mockery::mock('Fisharebest\Webtrees\Individual');
87        $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
88
89        $family = Mockery::mock('Fisharebest\Webtrees\Family');
90        $family->shouldReceive('getWife')->andReturn($mother);
91
92        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
93        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
94
95        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
96        $census->shouldReceive('censusPlace')->andReturn('Ireland');
97
98        $column = new CensusColumnMotherForeign($census, '', '');
99
100        $this->assertSame('Y', $column->generate($individual, $individual));
101    }
102
103    /**
104     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign
105     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
106     *
107     * @return void
108     */
109    public function testPlaceNoParent()
110    {
111        $family = Mockery::mock('Fisharebest\Webtrees\Family');
112        $family->shouldReceive('getWife')->andReturn(null);
113
114        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
115        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
116
117        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
118        $census->shouldReceive('censusPlace')->andReturn('England');
119
120        $column = new CensusColumnMotherForeign($census, '', '');
121
122        $this->assertSame('', $column->generate($individual, $individual));
123    }
124
125    /**
126     * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign
127     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
128     *
129     * @return void
130     */
131    public function testPlaceNoParentFamily()
132    {
133        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
134        $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null);
135
136        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
137        $census->shouldReceive('censusPlace')->andReturn('England');
138
139        $column = new CensusColumnMotherForeign($census, '', '');
140
141        $this->assertSame('', $column->generate($individual, $individual));
142    }
143}
144