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