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 CensusColumnMotherForeign 27 */ 28class CensusColumnMotherForeignTest 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 $placeMock = Mockery::mock(Place::class); 50 $placeMock->shouldReceive('getGedcomName')->andReturn($place); 51 52 return $placeMock; 53 } 54 55 /** 56 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign 57 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 58 * 59 * @return void 60 */ 61 public function testSameCountry(): void 62 { 63 $mother = Mockery::mock(Individual::class); 64 $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 65 66 $family = Mockery::mock(Family::class); 67 $family->shouldReceive('getWife')->andReturn($mother); 68 69 $individual = Mockery::mock(Individual::class); 70 $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 71 72 $census = Mockery::mock(CensusInterface::class); 73 $census->shouldReceive('censusPlace')->andReturn('England'); 74 75 $column = new CensusColumnMotherForeign($census, '', ''); 76 77 $this->assertSame('', $column->generate($individual, $individual)); 78 } 79 80 /** 81 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign 82 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 83 * 84 * @return void 85 */ 86 public function testDifferentCountry(): void 87 { 88 $mother = Mockery::mock(Individual::class); 89 $mother->shouldReceive('getBirthPlace')->andReturn($this->getPlaceMock('London, England')); 90 91 $family = Mockery::mock(Family::class); 92 $family->shouldReceive('getWife')->andReturn($mother); 93 94 $individual = Mockery::mock(Individual::class); 95 $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 96 97 $census = Mockery::mock(CensusInterface::class); 98 $census->shouldReceive('censusPlace')->andReturn('Ireland'); 99 100 $column = new CensusColumnMotherForeign($census, '', ''); 101 102 $this->assertSame('Y', $column->generate($individual, $individual)); 103 } 104 105 /** 106 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign 107 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 108 * 109 * @return void 110 */ 111 public function testPlaceNoParent(): void 112 { 113 $family = Mockery::mock(Family::class); 114 $family->shouldReceive('getWife')->andReturn(null); 115 116 $individual = Mockery::mock(Individual::class); 117 $individual->shouldReceive('getPrimaryChildFamily')->andReturn($family); 118 119 $census = Mockery::mock(CensusInterface::class); 120 $census->shouldReceive('censusPlace')->andReturn('England'); 121 122 $column = new CensusColumnMotherForeign($census, '', ''); 123 124 $this->assertSame('', $column->generate($individual, $individual)); 125 } 126 127 /** 128 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherForeign 129 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 130 * 131 * @return void 132 */ 133 public function testPlaceNoParentFamily(): void 134 { 135 $individual = Mockery::mock(Individual::class); 136 $individual->shouldReceive('getPrimaryChildFamily')->andReturn(null); 137 138 $census = Mockery::mock(CensusInterface::class); 139 $census->shouldReceive('censusPlace')->andReturn('England'); 140 141 $column = new CensusColumnMotherForeign($census, '', ''); 142 143 $this->assertSame('', $column->generate($individual, $individual)); 144 } 145} 146