1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Census; 21 22use Fisharebest\Webtrees\Family; 23use Fisharebest\Webtrees\Individual; 24use Fisharebest\Webtrees\Place; 25use Fisharebest\Webtrees\TestCase; 26use Illuminate\Support\Collection; 27 28/** 29 * Test harness for the class CensusColumnMotherBirthPlace 30 */ 31class CensusColumnMotherBirthPlaceTest extends TestCase 32{ 33 /** 34 * Get place mock. 35 * 36 * @param string $place Gedcom Place 37 * 38 * @return Place 39 */ 40 private function getPlaceMock(string $place): Place 41 { 42 $placeParts = explode(', ', $place); 43 44 $placeMock = $this->createMock(Place::class); 45 $placeMock->method('gedcomName')->willReturn($place); 46 $placeMock->method('lastParts')->willReturn(new Collection($placeParts)); 47 48 return $placeMock; 49 } 50 51 /** 52 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 53 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 54 * 55 * @return void 56 */ 57 public function testSameCountry(): void 58 { 59 $mother = $this->createMock(Individual::class); 60 $mother->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 61 62 $family = $this->createMock(Family::class); 63 $family->method('wife')->willReturn($mother); 64 65 $individual = $this->createMock(Individual::class); 66 $individual->method('childFamilies')->willReturn(new Collection([$family])); 67 68 $census = $this->createMock(CensusInterface::class); 69 $census->method('censusPlace')->willReturn('England'); 70 71 $column = new CensusColumnMotherBirthPlace($census, '', ''); 72 73 self::assertSame('London', $column->generate($individual, $individual)); 74 } 75 76 /** 77 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 78 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 79 * 80 * @return void 81 */ 82 public function testDifferentCountry(): void 83 { 84 $mother = $this->createMock(Individual::class); 85 $mother->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England')); 86 87 $family = $this->createMock(Family::class); 88 $family->method('wife')->willReturn($mother); 89 90 $individual = $this->createMock(Individual::class); 91 $individual->method('childFamilies')->willReturn(new Collection([$family])); 92 93 $census = $this->createMock(CensusInterface::class); 94 $census->method('censusPlace')->willReturn('Ireland'); 95 96 $column = new CensusColumnMotherBirthPlace($census, '', ''); 97 98 self::assertSame('London, England', $column->generate($individual, $individual)); 99 } 100 101 /** 102 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 103 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 104 * 105 * @return void 106 */ 107 public function testPlaceNoParent(): void 108 { 109 $family = $this->createMock(Family::class); 110 $family->method('wife')->willReturn(null); 111 112 $individual = $this->createMock(Individual::class); 113 $individual->method('childFamilies')->willReturn(new Collection([$family])); 114 115 $census = $this->createMock(CensusInterface::class); 116 $census->method('censusPlace')->willReturn('England'); 117 118 $column = new CensusColumnMotherBirthPlace($census, '', ''); 119 120 self::assertSame('', $column->generate($individual, $individual)); 121 } 122 123 /** 124 * @covers \Fisharebest\Webtrees\Census\CensusColumnMotherBirthPlace 125 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 126 * 127 * @return void 128 */ 129 public function testPlaceNoParentFamily(): void 130 { 131 $individual = $this->createMock(Individual::class); 132 $individual->method('childFamilies')->willReturn(new Collection()); 133 134 $census = $this->createMock(CensusInterface::class); 135 $census->method('censusPlace')->willReturn('England'); 136 137 $column = new CensusColumnMotherBirthPlace($census, '', ''); 138 139 self::assertSame('', $column->generate($individual, $individual)); 140 } 141} 142