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 CensusColumnBirthPlace 26 */ 27class CensusColumnBirthPlaceTest 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\CensusColumnBirthPlace 56 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 57 * 58 * @return void 59 */ 60 public function testPlaceCountry(): 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('England'); 67 68 $column = new CensusColumnBirthPlace($census, '', ''); 69 70 $this->assertSame('Westminster, London', $column->generate($individual, $individual)); 71 } 72 73 /** 74 * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace 75 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 76 * 77 * @return void 78 */ 79 public function testPlaceAndCountry(): void 80 { 81 $individual = Mockery::mock(Individual::class); 82 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('England')); 83 84 $census = Mockery::mock(CensusInterface::class); 85 $census->shouldReceive('censusPlace')->andReturn('England'); 86 87 $column = new CensusColumnBirthPlace($census, '', ''); 88 89 $this->assertSame('', $column->generate($individual, $individual)); 90 } 91 92 /** 93 * @covers \Fisharebest\Webtrees\Census\CensusColumnBirthPlace 94 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 95 * 96 * @return void 97 */ 98 public function testDifferentCountry(): void 99 { 100 $individual = Mockery::mock(Individual::class); 101 $individual->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('Paris, France')); 102 103 $census = Mockery::mock(CensusInterface::class); 104 $census->shouldReceive('censusPlace')->andReturn('England'); 105 106 $column = new CensusColumnBirthPlace($census, '', ''); 107 108 $this->assertSame('Paris, France', $column->generate($individual, $individual)); 109 } 110} 111