1a4500ed5SGreg Roach<?php 2a4500ed5SGreg Roach 3a4500ed5SGreg Roach/** 4a4500ed5SGreg Roach * webtrees: online genealogy 51062a142SGreg Roach * Copyright (C) 2018 webtrees development team 6a4500ed5SGreg Roach * This program is free software: you can redistribute it and/or modify 7a4500ed5SGreg Roach * it under the terms of the GNU General Public License as published by 8a4500ed5SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a4500ed5SGreg Roach * (at your option) any later version. 10a4500ed5SGreg Roach * This program is distributed in the hope that it will be useful, 11a4500ed5SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a4500ed5SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a4500ed5SGreg Roach * GNU General Public License for more details. 14a4500ed5SGreg Roach * You should have received a copy of the GNU General Public License 15a4500ed5SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16a4500ed5SGreg Roach */ 17a4500ed5SGreg Roachnamespace Fisharebest\Webtrees\Census; 18a4500ed5SGreg Roach 19a4500ed5SGreg Roachuse Mockery; 20a4500ed5SGreg Roach 21a4500ed5SGreg Roach/** 22a4500ed5SGreg Roach * Test harness for the class CensusColumnBirthPlaceSimple 23a4500ed5SGreg Roach */ 24c1010edaSGreg Roachclass CensusColumnBirthPlaceSimpleTest extends \PHPUnit\Framework\TestCase 25c1010edaSGreg Roach{ 26a4500ed5SGreg Roach /** 27a4500ed5SGreg Roach * Delete mock objects 28a4500ed5SGreg Roach */ 29c1010edaSGreg Roach public function tearDown() 30c1010edaSGreg Roach { 31a4500ed5SGreg Roach Mockery::close(); 32a4500ed5SGreg Roach } 33a4500ed5SGreg Roach 34a4500ed5SGreg 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 $placeMock = Mockery::mock('\Fisharebest\Webtrees\Place'); 4416d0b7f7SRico Sonntag $placeMock->shouldReceive('getGedcomName')->andReturn($place); 4516d0b7f7SRico Sonntag 4616d0b7f7SRico Sonntag return $placeMock; 4716d0b7f7SRico Sonntag } 4816d0b7f7SRico Sonntag 4916d0b7f7SRico Sonntag /** 5015d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 5115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 52a4500ed5SGreg Roach */ 53c1010edaSGreg Roach public function testForeignCountry() 54c1010edaSGreg Roach { 55c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 5616d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Westminster, London, England')); 57a4500ed5SGreg Roach 58c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 59a4500ed5SGreg Roach $census->shouldReceive('censusPlace')->andReturn('United States'); 60a4500ed5SGreg Roach 61a4500ed5SGreg Roach $column = new CensusColumnBirthPlaceSimple($census, '', ''); 62a4500ed5SGreg Roach 63342dcecdSGreg Roach $this->assertSame('England', $column->generate($individual, $individual)); 64a4500ed5SGreg Roach } 65a4500ed5SGreg Roach 66a4500ed5SGreg Roach /** 6715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 6815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 69a4500ed5SGreg Roach */ 70c1010edaSGreg Roach public function testJustCountry() 71c1010edaSGreg Roach { 72c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 7316d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('United States')); 74a4500ed5SGreg Roach 75c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 76a4500ed5SGreg Roach $census->shouldReceive('censusPlace')->andReturn('United States'); 77a4500ed5SGreg Roach 78a4500ed5SGreg Roach $column = new CensusColumnBirthPlaceSimple($census, '', ''); 79a4500ed5SGreg Roach 80342dcecdSGreg Roach $this->assertSame('', $column->generate($individual, $individual)); 81a4500ed5SGreg Roach } 82a4500ed5SGreg Roach 83a4500ed5SGreg Roach /** 8415d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 8515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 86a4500ed5SGreg Roach */ 87c1010edaSGreg Roach public function testKnownState() 88c1010edaSGreg Roach { 89c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 9016d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Maryland, United States')); 91a4500ed5SGreg Roach 92c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 93a4500ed5SGreg Roach $census->shouldReceive('censusPlace')->andReturn('United States'); 94a4500ed5SGreg Roach 95a4500ed5SGreg Roach $column = new CensusColumnBirthPlaceSimple($census, '', ''); 96a4500ed5SGreg Roach 97342dcecdSGreg Roach $this->assertSame('Maryland', $column->generate($individual, $individual)); 98a4500ed5SGreg Roach } 99a4500ed5SGreg Roach 100a4500ed5SGreg Roach /** 10115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 10215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 103a4500ed5SGreg Roach */ 104c1010edaSGreg Roach public function testKnownStateAndTown() 105c1010edaSGreg Roach { 106c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 10716d0b7f7SRico Sonntag $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Miami, Florida, United States')); 108a4500ed5SGreg Roach 109c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 110a4500ed5SGreg Roach $census->shouldReceive('censusPlace')->andReturn('United States'); 111a4500ed5SGreg Roach 112a4500ed5SGreg Roach $column = new CensusColumnBirthPlaceSimple($census, '', ''); 113a4500ed5SGreg Roach 114342dcecdSGreg Roach $this->assertSame('Florida', $column->generate($individual, $individual)); 115a4500ed5SGreg Roach } 116a4500ed5SGreg Roach} 117