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