1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Census; 19 20use Fisharebest\Webtrees\Individual; 21use Fisharebest\Webtrees\Place; 22use Mockery; 23 24/** 25 * Test harness for the class CensusColumnBirthPlaceSimple 26 */ 27class CensusColumnBirthPlaceSimpleTest extends \Fisharebest\Webtrees\TestCase 28{ 29 /** 30 * Delete mock objects 31 * 32 * @return void 33 */ 34 public function tearDown() 35 { 36 Mockery::close(); 37 } 38 39 /** 40 * Get place mock. 41 * 42 * @param string $place Gedcom Place 43 * 44 * @return Place 45 */ 46 private function getPlaceMock($place): Place 47 { 48 $placeMock = Mockery::mock(Place::class); 49 $placeMock->shouldReceive('gedcomName')->andReturn($place); 50 51 return $placeMock; 52 } 53 54 /** 55 * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 56 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 57 * 58 * @return void 59 */ 60 public function testForeignCountry(): void 61 { 62 $individual = Mockery::mock(Individual::class); 63 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Westminster, London, England')); 64 65 $census = Mockery::mock(CensusInterface::class); 66 $census->shouldReceive('censusPlace')->andReturn('United States'); 67 68 $column = new CensusColumnBirthPlaceSimple($census, '', ''); 69 70 $this->assertSame('England', $column->generate($individual, $individual)); 71 } 72 73 /** 74 * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 75 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 76 * 77 * @return void 78 */ 79 public function testJustCountry(): void 80 { 81 $individual = Mockery::mock(Individual::class); 82 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('United States')); 83 84 $census = Mockery::mock(CensusInterface::class); 85 $census->shouldReceive('censusPlace')->andReturn('United States'); 86 87 $column = new CensusColumnBirthPlaceSimple($census, '', ''); 88 89 $this->assertSame('', $column->generate($individual, $individual)); 90 } 91 92 /** 93 * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 94 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 95 * 96 * @return void 97 */ 98 public function testKnownState(): void 99 { 100 $individual = Mockery::mock(Individual::class); 101 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Maryland, United States')); 102 103 $census = Mockery::mock(CensusInterface::class); 104 $census->shouldReceive('censusPlace')->andReturn('United States'); 105 106 $column = new CensusColumnBirthPlaceSimple($census, '', ''); 107 108 $this->assertSame('Maryland', $column->generate($individual, $individual)); 109 } 110 111 /** 112 * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlaceSimple 113 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 114 * 115 * @return void 116 */ 117 public function testKnownStateAndTown(): void 118 { 119 $individual = Mockery::mock(Individual::class); 120 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Miami, Florida, United States')); 121 122 $census = Mockery::mock(CensusInterface::class); 123 $census->shouldReceive('censusPlace')->andReturn('United States'); 124 125 $column = new CensusColumnBirthPlaceSimple($census, '', ''); 126 127 $this->assertSame('Florida', $column->generate($individual, $individual)); 128 } 129} 130