xref: /webtrees/tests/app/Census/CensusColumnFatherBirthPlaceTest.php (revision 1062a1429914c995339f502856821457aa975a5a)
1a53db70dSGreg Roach<?php
2a53db70dSGreg Roach
3a53db70dSGreg Roach/**
4a53db70dSGreg Roach * webtrees: online genealogy
5*1062a142SGreg 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 */
243e983931SGreg Roachclass CensusColumnFatherBirthPlaceTest extends \PHPUnit\Framework\TestCase {
25a53db70dSGreg Roach	/**
26a53db70dSGreg Roach	 * Delete mock objects
27a53db70dSGreg Roach	 */
28a53db70dSGreg Roach	public function tearDown() {
29a53db70dSGreg Roach		Mockery::close();
30a53db70dSGreg Roach	}
31a53db70dSGreg Roach
32a53db70dSGreg Roach	/**
3316d0b7f7SRico Sonntag	 * Get place mock.
3416d0b7f7SRico Sonntag	 *
3516d0b7f7SRico Sonntag	 * @param string $place Gedcom Place
3616d0b7f7SRico Sonntag	 *
3716d0b7f7SRico Sonntag	 * @return \Fisharebest\Webtrees\Place
3816d0b7f7SRico Sonntag	 */
398d68cabeSGreg Roach	private function getPlaceMock($place) {
4016d0b7f7SRico Sonntag		$placeParts = explode(', ', $place);
4116d0b7f7SRico Sonntag
4216d0b7f7SRico Sonntag		$placeMock = Mockery::mock('\Fisharebest\Webtrees\Place');
4316d0b7f7SRico Sonntag		$placeMock->shouldReceive('getGedcomName')->andReturn($place);
4416d0b7f7SRico Sonntag		$placeMock->shouldReceive('lastPart')->andReturn(end($placeParts));
4516d0b7f7SRico Sonntag
4616d0b7f7SRico Sonntag		return $placeMock;
4716d0b7f7SRico Sonntag	}
4816d0b7f7SRico Sonntag
4916d0b7f7SRico Sonntag	/**
5015d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
5115d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
52a53db70dSGreg Roach	 */
53a53db70dSGreg Roach	public function testSameCountry() {
54c314ecc9SGreg Roach		$father = Mockery::mock('Fisharebest\Webtrees\Individual');
5516d0b7f7SRico Sonntag		$father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
56a53db70dSGreg Roach
57c314ecc9SGreg Roach		$family = Mockery::mock('Fisharebest\Webtrees\Family');
58a53db70dSGreg Roach		$family->shouldReceive('getHusband')->andReturn($father);
59a53db70dSGreg Roach
60c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
61a53db70dSGreg Roach		$individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
62a53db70dSGreg Roach
63c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
64a53db70dSGreg Roach		$census->shouldReceive('censusPlace')->andReturn('England');
65a53db70dSGreg Roach
66a53db70dSGreg Roach		$column = new CensusColumnFatherBirthPlace($census, '', '');
67a53db70dSGreg Roach
68a53db70dSGreg Roach		$this->assertSame('London', $column->generate($individual));
69a53db70dSGreg Roach	}
70a53db70dSGreg Roach
71a53db70dSGreg Roach	/**
7215d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
7315d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
74a53db70dSGreg Roach	 */
75a53db70dSGreg Roach	public function testDifferentCountry() {
76c314ecc9SGreg Roach		$father = Mockery::mock('Fisharebest\Webtrees\Individual');
7716d0b7f7SRico Sonntag		$father->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England'));
78a53db70dSGreg Roach
79c314ecc9SGreg Roach		$family = Mockery::mock('Fisharebest\Webtrees\Family');
80a53db70dSGreg Roach		$family->shouldReceive('getHusband')->andReturn($father);
81a53db70dSGreg Roach
82c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
83a53db70dSGreg Roach		$individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
84a53db70dSGreg Roach
85c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
86a53db70dSGreg Roach		$census->shouldReceive('censusPlace')->andReturn('Ireland');
87a53db70dSGreg Roach
88a53db70dSGreg Roach		$column = new CensusColumnFatherBirthPlace($census, '', '');
89a53db70dSGreg Roach
90a53db70dSGreg Roach		$this->assertSame('London, England', $column->generate($individual));
91a53db70dSGreg Roach	}
92a53db70dSGreg Roach
93a53db70dSGreg Roach	/**
9415d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
9515d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
96a53db70dSGreg Roach	 */
97a53db70dSGreg Roach	public function testPlaceNoParent() {
98c314ecc9SGreg Roach		$family = Mockery::mock('Fisharebest\Webtrees\Family');
99a53db70dSGreg Roach		$family->shouldReceive('getHusband')->andReturn(null);
100a53db70dSGreg Roach
101c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
102a53db70dSGreg Roach		$individual->shouldReceive('getPrimaryChildFamily')->andReturn($family);
103a53db70dSGreg Roach
104c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
105a53db70dSGreg Roach		$census->shouldReceive('censusPlace')->andReturn('England');
106a53db70dSGreg Roach
107a53db70dSGreg Roach		$column = new CensusColumnFatherBirthPlace($census, '', '');
108a53db70dSGreg Roach
109a53db70dSGreg Roach		$this->assertSame('', $column->generate($individual));
110a53db70dSGreg Roach	}
111a53db70dSGreg Roach
112a53db70dSGreg Roach	/**
11315d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\CensusColumnFatherBirthPlace
11415d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
115a53db70dSGreg Roach	 */
116a53db70dSGreg Roach	public function testPlaceNoParentFamily() {
117c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
118a53db70dSGreg Roach		$individual->shouldReceive('getPrimaryChildFamily')->andReturn(null);
119a53db70dSGreg Roach
120c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
121a53db70dSGreg Roach		$census->shouldReceive('censusPlace')->andReturn('England');
122a53db70dSGreg Roach
123a53db70dSGreg Roach		$column = new CensusColumnFatherBirthPlace($census, '', '');
124a53db70dSGreg Roach
125a53db70dSGreg Roach		$this->assertSame('', $column->generate($individual));
126a53db70dSGreg Roach	}
127a53db70dSGreg Roach}
128