1a53db70dSGreg Roach<?php 2a53db70dSGreg Roach/** 3a53db70dSGreg Roach * webtrees: online genealogy 4*8fcd0d32SGreg Roach * Copyright (C) 2019 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 */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 18a53db70dSGreg Roachnamespace Fisharebest\Webtrees\Census; 19a53db70dSGreg Roach 20ddf438a5SGreg Roachuse Fisharebest\Webtrees\Family; 21ddf438a5SGreg Roachuse Fisharebest\Webtrees\Individual; 2252348eb8SGreg Roachuse Fisharebest\Webtrees\Place; 23a53db70dSGreg Roachuse Mockery; 24a53db70dSGreg Roach 25a53db70dSGreg Roach/** 26a53db70dSGreg Roach * Test harness for the class CensusColumnMotherBirthPlace 27a53db70dSGreg Roach */ 2884e2cf4eSGreg Roachclass CensusColumnMotherBirthPlaceTest extends \Fisharebest\Webtrees\TestCase 29c1010edaSGreg Roach{ 30a53db70dSGreg Roach /** 31a53db70dSGreg Roach * Delete mock objects 3252348eb8SGreg Roach * 3352348eb8SGreg Roach * @return void 34a53db70dSGreg Roach */ 35c1010edaSGreg Roach public function tearDown() 36c1010edaSGreg Roach { 37a53db70dSGreg Roach Mockery::close(); 38a53db70dSGreg Roach } 39a53db70dSGreg Roach 40a53db70dSGreg Roach /** 4116d0b7f7SRico Sonntag * Get place mock. 4216d0b7f7SRico Sonntag * 4316d0b7f7SRico Sonntag * @param string $place Gedcom Place 4416d0b7f7SRico Sonntag * 4552348eb8SGreg Roach * @return Place 4616d0b7f7SRico Sonntag */ 4752348eb8SGreg Roach private function getPlaceMock($place): Place 48c1010edaSGreg Roach { 4916d0b7f7SRico Sonntag $placeParts = explode(', ', $place); 5016d0b7f7SRico Sonntag 51ddf438a5SGreg Roach $placeMock = Mockery::mock(Place::class); 5216d0b7f7SRico Sonntag $placeMock->shouldReceive('getGedcomName')->andReturn($place); 5316d0b7f7SRico Sonntag $placeMock->shouldReceive('lastPart')->andReturn(end($placeParts)); 5416d0b7f7SRico Sonntag 5516d0b7f7SRico Sonntag return $placeMock; 5616d0b7f7SRico Sonntag } 5716d0b7f7SRico Sonntag 5816d0b7f7SRico Sonntag /** 5915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 6015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 6152348eb8SGreg Roach * 6252348eb8SGreg Roach * @return void 63a53db70dSGreg Roach */ 64c1010edaSGreg Roach public function testSameCountry() 65c1010edaSGreg Roach { 66ddf438a5SGreg Roach $mother = Mockery::mock(Individual::class); 6716d0b7f7SRico Sonntag $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 68a53db70dSGreg Roach 69ddf438a5SGreg Roach $family = Mockery::mock(Family::class); 70a53db70dSGreg Roach $family->shouldReceive('getWife')->andReturn($mother); 71a53db70dSGreg Roach 72ddf438a5SGreg Roach $individual = Mockery::mock(Individual::class); 73a53db70dSGreg Roach $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 74a53db70dSGreg Roach 75ddf438a5SGreg Roach $census = Mockery::mock(CensusInterface::class); 76a53db70dSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 77a53db70dSGreg Roach 78a53db70dSGreg Roach $column = new CensusColumnMotherBirthPlace($census, '', ''); 79a53db70dSGreg Roach 80342dcecdSGreg Roach $this->assertSame('London', $column->generate($individual, $individual)); 81a53db70dSGreg Roach } 82a53db70dSGreg Roach 83a53db70dSGreg Roach /** 8415d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 8515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 8652348eb8SGreg Roach * 8752348eb8SGreg Roach * @return void 88a53db70dSGreg Roach */ 89c1010edaSGreg Roach public function testDifferentCountry() 90c1010edaSGreg Roach { 91ddf438a5SGreg Roach $mother = Mockery::mock(Individual::class); 9216d0b7f7SRico Sonntag $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 93a53db70dSGreg Roach 94ddf438a5SGreg Roach $family = Mockery::mock(Family::class); 95a53db70dSGreg Roach $family->shouldReceive('getWife')->andReturn($mother); 96a53db70dSGreg Roach 97ddf438a5SGreg Roach $individual = Mockery::mock(Individual::class); 98a53db70dSGreg Roach $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 99a53db70dSGreg Roach 100ddf438a5SGreg Roach $census = Mockery::mock(CensusInterface::class); 101a53db70dSGreg Roach $census->shouldReceive('censusPlace')->andReturn('Ireland'); 102a53db70dSGreg Roach 103a53db70dSGreg Roach $column = new CensusColumnMotherBirthPlace($census, '', ''); 104a53db70dSGreg Roach 105342dcecdSGreg Roach $this->assertSame('London, England', $column->generate($individual, $individual)); 106a53db70dSGreg Roach } 107a53db70dSGreg Roach 108a53db70dSGreg Roach /** 10915d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 11015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 11152348eb8SGreg Roach * 11252348eb8SGreg Roach * @return void 113a53db70dSGreg Roach */ 114c1010edaSGreg Roach public function testPlaceNoParent() 115c1010edaSGreg Roach { 116ddf438a5SGreg Roach $family = Mockery::mock(Family::class); 117a53db70dSGreg Roach $family->shouldReceive('getWife')->andReturn(null); 118a53db70dSGreg Roach 119ddf438a5SGreg Roach $individual = Mockery::mock(Individual::class); 120a53db70dSGreg Roach $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 121a53db70dSGreg Roach 122ddf438a5SGreg Roach $census = Mockery::mock(CensusInterface::class); 123a53db70dSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 124a53db70dSGreg Roach 125a53db70dSGreg Roach $column = new CensusColumnMotherBirthPlace($census, '', ''); 126a53db70dSGreg Roach 127342dcecdSGreg Roach $this->assertSame('', $column->generate($individual, $individual)); 128a53db70dSGreg Roach } 129a53db70dSGreg Roach 130a53db70dSGreg Roach /** 13115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 13215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 13352348eb8SGreg Roach * 13452348eb8SGreg Roach * @return void 135a53db70dSGreg Roach */ 136c1010edaSGreg Roach public function testPlaceNoParentFamily() 137c1010edaSGreg Roach { 138ddf438a5SGreg Roach $individual = Mockery::mock(Individual::class); 139a53db70dSGreg Roach $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null); 140a53db70dSGreg Roach 141ddf438a5SGreg Roach $census = Mockery::mock(CensusInterface::class); 142a53db70dSGreg Roach $census->shouldReceive('censusPlace')->andReturn('England'); 143a53db70dSGreg Roach 144a53db70dSGreg Roach $column = new CensusColumnMotherBirthPlace($census, '', ''); 145a53db70dSGreg Roach 146342dcecdSGreg Roach $this->assertSame('', $column->generate($individual, $individual)); 147a53db70dSGreg Roach } 148a53db70dSGreg Roach} 149