xref: /webtrees/tests/app/Census/CensusColumnFatherBirthPlaceTest.php (revision 8f53f488f13e53e44dc48778e8f51ec9f91352dd)
1a53db70dSGreg Roach<?php
2a53db70dSGreg Roach
3a53db70dSGreg Roach/**
4a53db70dSGreg Roach * webtrees: online genealogy
51062a142SGreg Roach * Copyright (C) 2018 webtrees development team
6a53db70dSGreg Roach * This program is free software: you can redistribute it and/or modify
7a53db70dSGreg Roach * it under the terms of the GNU General Public License as published by
8a53db70dSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a53db70dSGreg Roach * (at your option) any later version.
10a53db70dSGreg Roach * This program is distributed in the hope that it will be useful,
11a53db70dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a53db70dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a53db70dSGreg Roach * GNU General Public License for more details.
14a53db70dSGreg Roach * You should have received a copy of the GNU General Public License
15a53db70dSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a53db70dSGreg Roach */
17a53db70dSGreg Roachnamespace Fisharebest\Webtrees\Census;
18a53db70dSGreg Roach
19a53db70dSGreg Roachuse Mockery;
20a53db70dSGreg Roach
21a53db70dSGreg Roach/**
22a53db70dSGreg Roach * Test harness for the class CensusColumnFatherBirthPlace
23a53db70dSGreg Roach */
24c1010edaSGreg Roachclass CensusColumnFatherBirthPlaceTest extends \PHPUnit\Framework\TestCase
25c1010edaSGreg Roach{
26a53db70dSGreg Roach    /**
27a53db70dSGreg Roach     * Delete mock objects
28a53db70dSGreg Roach     */
29c1010edaSGreg Roach    public function tearDown()
30c1010edaSGreg Roach    {
31a53db70dSGreg Roach        Mockery::close();
32a53db70dSGreg Roach    }
33a53db70dSGreg Roach
34a53db70dSGreg Roach    /**
3516d0b7f7SRico Sonntag     * Get place mock.
3616d0b7f7SRico Sonntag     *
3716d0b7f7SRico Sonntag     * @param string $place Gedcom Place
3816d0b7f7SRico Sonntag     *
3916d0b7f7SRico Sonntag     * @return \Fisharebest\Webtrees\Place
4016d0b7f7SRico Sonntag     */
41*8f53f488SRico Sonntag    private function getPlaceMock($place): \Fisharebest\Webtrees\Place
42c1010edaSGreg Roach    {
4316d0b7f7SRico Sonntag        $placeParts = explode(', ', $place);
4416d0b7f7SRico Sonntag
4516d0b7f7SRico Sonntag        $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
4616d0b7f7SRico Sonntag        $placeMock->shouldReceive('getGedcomName')->andReturn($place);
4716d0b7f7SRico Sonntag        $placeMock->shouldReceive('lastPart')->andReturn(end($placeParts));
4816d0b7f7SRico Sonntag
4916d0b7f7SRico Sonntag        return $placeMock;
5016d0b7f7SRico Sonntag    }
5116d0b7f7SRico Sonntag
5216d0b7f7SRico Sonntag    /**
5315d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
5415d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
55a53db70dSGreg Roach     */
56c1010edaSGreg Roach    public function testSameCountry()
57c1010edaSGreg Roach    {
58c314ecc9SGreg Roach        $father = Mockery::mock('Fisharebest\Webtrees\Individual');
5916d0b7f7SRico Sonntag        $father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
60a53db70dSGreg Roach
61c314ecc9SGreg Roach        $family = Mockery::mock('Fisharebest\Webtrees\Family');
62a53db70dSGreg Roach        $family->shouldReceive('getHusband')->andReturn($father);
63a53db70dSGreg Roach
64c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
65a53db70dSGreg Roach        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
66a53db70dSGreg Roach
67c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
68a53db70dSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('England');
69a53db70dSGreg Roach
70a53db70dSGreg Roach        $column = new CensusColumnFatherBirthPlace($census, '', '');
71a53db70dSGreg Roach
72342dcecdSGreg Roach        $this->assertSame('London', $column->generate($individual, $individual));
73a53db70dSGreg Roach    }
74a53db70dSGreg Roach
75a53db70dSGreg Roach    /**
7615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
7715d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
78a53db70dSGreg Roach     */
79c1010edaSGreg Roach    public function testDifferentCountry()
80c1010edaSGreg Roach    {
81c314ecc9SGreg Roach        $father = Mockery::mock('Fisharebest\Webtrees\Individual');
8216d0b7f7SRico Sonntag        $father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
83a53db70dSGreg Roach
84c314ecc9SGreg Roach        $family = Mockery::mock('Fisharebest\Webtrees\Family');
85a53db70dSGreg Roach        $family->shouldReceive('getHusband')->andReturn($father);
86a53db70dSGreg Roach
87c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
88a53db70dSGreg Roach        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
89a53db70dSGreg Roach
90c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
91a53db70dSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('Ireland');
92a53db70dSGreg Roach
93a53db70dSGreg Roach        $column = new CensusColumnFatherBirthPlace($census, '', '');
94a53db70dSGreg Roach
95342dcecdSGreg Roach        $this->assertSame('London, England', $column->generate($individual, $individual));
96a53db70dSGreg Roach    }
97a53db70dSGreg Roach
98a53db70dSGreg Roach    /**
9915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
10015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
101a53db70dSGreg Roach     */
102c1010edaSGreg Roach    public function testPlaceNoParent()
103c1010edaSGreg Roach    {
104c314ecc9SGreg Roach        $family = Mockery::mock('Fisharebest\Webtrees\Family');
105a53db70dSGreg Roach        $family->shouldReceive('getHusband')->andReturn(null);
106a53db70dSGreg Roach
107c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
108a53db70dSGreg Roach        $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
109a53db70dSGreg Roach
110c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
111a53db70dSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('England');
112a53db70dSGreg Roach
113a53db70dSGreg Roach        $column = new CensusColumnFatherBirthPlace($census, '', '');
114a53db70dSGreg Roach
115342dcecdSGreg Roach        $this->assertSame('', $column->generate($individual, $individual));
116a53db70dSGreg Roach    }
117a53db70dSGreg Roach
118a53db70dSGreg Roach    /**
11915d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
12015d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
121a53db70dSGreg Roach     */
122c1010edaSGreg Roach    public function testPlaceNoParentFamily()
123c1010edaSGreg Roach    {
124c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
125a53db70dSGreg Roach        $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null);
126a53db70dSGreg Roach
127c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
128a53db70dSGreg Roach        $census->shouldReceive('censusPlace')->andReturn('England');
129a53db70dSGreg Roach
130a53db70dSGreg Roach        $column = new CensusColumnFatherBirthPlace($census, '', '');
131a53db70dSGreg Roach
132342dcecdSGreg Roach        $this->assertSame('', $column->generate($individual, $individual));
133a53db70dSGreg Roach    }
134a53db70dSGreg Roach}
135