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\Family; 21use Fisharebest\Webtrees\Individual; 22use Fisharebest\Webtrees\Place; 23use Mockery; 24 25/** 26 * Test harness for the class CensusColumnMotherBirthPlace 27 */ 28class CensusColumnMotherBirthPlaceTest extends \Fisharebest\Webtrees\TestCase 29{ 30 /** 31 * Delete mock objects 32 * 33 * @return void 34 */ 35 public function tearDown() 36 { 37 Mockery::close(); 38 } 39 40 /** 41 * Get place mock. 42 * 43 * @param string $place Gedcom Place 44 * 45 * @return Place 46 */ 47 private function getPlaceMock($place): Place 48 { 49 $placeParts = explode(', ', $place); 50 51 $placeMock = Mockery::mock(Place::class); 52 $placeMock->shouldReceive('getGedcomName')->andReturn($place); 53 $placeMock->shouldReceive('lastPart')->andReturn(end($placeParts)); 54 55 return $placeMock; 56 } 57 58 /** 59 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 60 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 61 * 62 * @return void 63 */ 64 public function testSameCountry() 65 { 66 $mother = Mockery::mock(Individual::class); 67 $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 68 69 $family = Mockery::mock(Family::class); 70 $family->shouldReceive('getWife')->andReturn($mother); 71 72 $individual = Mockery::mock(Individual::class); 73 $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 74 75 $census = Mockery::mock(CensusInterface::class); 76 $census->shouldReceive('censusPlace')->andReturn('England'); 77 78 $column = new CensusColumnMotherBirthPlace($census, '', ''); 79 80 $this->assertSame('London', $column->generate($individual, $individual)); 81 } 82 83 /** 84 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 85 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 86 * 87 * @return void 88 */ 89 public function testDifferentCountry() 90 { 91 $mother = Mockery::mock(Individual::class); 92 $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 93 94 $family = Mockery::mock(Family::class); 95 $family->shouldReceive('getWife')->andReturn($mother); 96 97 $individual = Mockery::mock(Individual::class); 98 $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 99 100 $census = Mockery::mock(CensusInterface::class); 101 $census->shouldReceive('censusPlace')->andReturn('Ireland'); 102 103 $column = new CensusColumnMotherBirthPlace($census, '', ''); 104 105 $this->assertSame('London, England', $column->generate($individual, $individual)); 106 } 107 108 /** 109 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 110 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 111 * 112 * @return void 113 */ 114 public function testPlaceNoParent() 115 { 116 $family = Mockery::mock(Family::class); 117 $family->shouldReceive('getWife')->andReturn(null); 118 119 $individual = Mockery::mock(Individual::class); 120 $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 121 122 $census = Mockery::mock(CensusInterface::class); 123 $census->shouldReceive('censusPlace')->andReturn('England'); 124 125 $column = new CensusColumnMotherBirthPlace($census, '', ''); 126 127 $this->assertSame('', $column->generate($individual, $individual)); 128 } 129 130 /** 131 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 132 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 133 * 134 * @return void 135 */ 136 public function testPlaceNoParentFamily() 137 { 138 $individual = Mockery::mock(Individual::class); 139 $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null); 140 141 $census = Mockery::mock(CensusInterface::class); 142 $census->shouldReceive('censusPlace')->andReturn('England'); 143 144 $column = new CensusColumnMotherBirthPlace($census, '', ''); 145 146 $this->assertSame('', $column->generate($individual, $individual)); 147 } 148} 149