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