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\Date; 22use Fisharebest\Webtrees\Fact; 23use Fisharebest\Webtrees\Family; 24use Fisharebest\Webtrees\Individual; 25use Fisharebest\Webtrees\TestCase; 26use Illuminate\Support\Collection; 27 28/** 29 * Test harness for the class CensusColumnConditionDanish 30 */ 31class CensusColumnConditionDanishTest extends TestCase 32{ 33 /** 34 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 35 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 36 * 37 * @return void 38 */ 39 public function testNoSpouseFamiliesMale(): void 40 { 41 $individual = $this->createMock(Individual::class); 42 $individual->method('sex')->willReturn('M'); 43 $individual->method('spouseFamilies')->willReturn(new Collection()); 44 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 45 46 $census = $this->createMock(CensusInterface::class); 47 $census->method('censusDate')->willReturn('30 JUN 1830'); 48 49 $column = new CensusColumnConditionDanish($census, '', ''); 50 51 $this->assertSame('Ugift', $column->generate($individual, $individual)); 52 } 53 54 /** 55 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 56 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 57 * 58 * @return void 59 */ 60 public function testNoSpouseFamiliesFemale(): void 61 { 62 $individual = $this->createMock(Individual::class); 63 $individual->method('sex')->willReturn('F'); 64 $individual->method('spouseFamilies')->willReturn(new Collection()); 65 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 66 67 $census = $this->createMock(CensusInterface::class); 68 $census->method('censusDate')->willReturn('30 JUN 1830'); 69 70 $column = new CensusColumnConditionDanish($census, '', ''); 71 72 $this->assertSame('Ugift', $column->generate($individual, $individual)); 73 } 74 75 /** 76 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 77 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 78 * 79 * @return void 80 */ 81 public function testNoFamilyFactsMale(): void 82 { 83 $family = $this->createMock(Family::class); 84 $family->method('getMarriageDate')->willReturn(new Date('')); 85 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 86 87 $individual = $this->createMock(Individual::class); 88 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 89 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 90 $individual->method('sex')->willReturn('M'); 91 92 $census = $this->createMock(CensusInterface::class); 93 94 $column = new CensusColumnConditionDanish($census, '', ''); 95 $census->method('censusDate')->willReturn('30 JUN 1830'); 96 97 $this->assertSame('Ugift', $column->generate($individual, $individual)); 98 } 99 100 /** 101 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 102 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 103 * 104 * @return void 105 */ 106 public function testNoFamilyFactsFemale(): void 107 { 108 $family = $this->createMock(Family::class); 109 $family->method('getMarriageDate')->willReturn(new Date('')); 110 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 111 112 $individual = $this->createMock(Individual::class); 113 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 114 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 115 $individual->method('sex')->willReturn('F'); 116 117 $census = $this->createMock(CensusInterface::class); 118 119 $column = new CensusColumnConditionDanish($census, '', ''); 120 $census->method('censusDate')->willReturn('30 JUN 1830'); 121 122 $this->assertSame('Ugift', $column->generate($individual, $individual)); 123 } 124 125 /** 126 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 127 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 128 * 129 * @return void 130 */ 131 public function testSpouseDeadMale(): void 132 { 133 $fact = $this->createMock(Fact::class); 134 135 $spouse = $this->createMock(Individual::class); 136 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 137 138 $family = $this->createMock(Family::class); 139 $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date('')); 140 $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 141 $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection()); 142 $family->expects($this->at(3))->method('spouse')->willReturn($spouse); 143 144 $individual = $this->createMock(Individual::class); 145 $individual->method('sex')->willReturn('M'); 146 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 147 148 $census = $this->createMock(CensusInterface::class); 149 150 $column = new CensusColumnConditionDanish($census, '', ''); 151 $census->method('censusDate')->willReturn('30 JUN 1830'); 152 153 $this->assertSame('Gift', $column->generate($individual, $individual)); 154 } 155 156 /** 157 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 158 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 159 * 160 * @return void 161 */ 162 public function testSpouseDeadFemale(): void 163 { 164 $fact = $this->createMock(Fact::class); 165 166 $spouse = $this->createMock(Individual::class); 167 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 168 169 $family = $this->createMock(Family::class); 170 $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date('')); 171 $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 172 $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection()); 173 $family->expects($this->at(3))->method('spouse')->willReturn($spouse); 174 175 $individual = $this->createMock(Individual::class); 176 $individual->method('sex')->willReturn('F'); 177 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 178 179 $census = $this->createMock(CensusInterface::class); 180 181 $column = new CensusColumnConditionDanish($census, '', ''); 182 $census->method('censusDate')->willReturn('30 JUN 1830'); 183 184 $this->assertSame('Gift', $column->generate($individual, $individual)); 185 } 186 187 /** 188 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 189 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 190 * 191 * @return void 192 */ 193 public function testNoFamilyUnmarriedMale(): void 194 { 195 $family = $this->createMock(Family::class); 196 $family->method('getMarriageDate')->willReturn(new Date('')); 197 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 198 199 $individual = $this->createMock(Individual::class); 200 $individual->method('sex')->willReturn('M'); 201 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 202 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 203 204 $census = $this->createMock(CensusInterface::class); 205 $census->method('censusDate')->willReturn('30 JUN 1830'); 206 207 $column = new CensusColumnConditionDanish($census, '', ''); 208 209 $this->assertSame('Ugift', $column->generate($individual, $individual)); 210 } 211 212 /** 213 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 214 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 215 * 216 * @return void 217 */ 218 public function testNoFamilyUnmarriedFemale(): void 219 { 220 $family = $this->createMock(Family::class); 221 $family->method('getMarriageDate')->willReturn(new Date('')); 222 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 223 224 $individual = $this->createMock(Individual::class); 225 $individual->method('sex')->willReturn('F'); 226 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 227 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 228 229 $census = $this->createMock(CensusInterface::class); 230 $census->method('censusDate')->willReturn('30 JUN 1830'); 231 232 $column = new CensusColumnConditionDanish($census, '', ''); 233 234 $this->assertSame('Ugift', $column->generate($individual, $individual)); 235 } 236 237 /** 238 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 239 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 240 * 241 * @return void 242 */ 243 public function testChildMale(): void 244 { 245 $family = $this->createMock(Family::class); 246 $family->method('getMarriageDate')->willReturn(new Date('')); 247 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 248 249 $individual = $this->createMock(Individual::class); 250 $individual->method('sex')->willReturn('M'); 251 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 252 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 253 254 $census = $this->createMock(CensusInterface::class); 255 $census->method('censusDate')->willReturn('30 JUN 1830'); 256 257 $column = new CensusColumnConditionDanish($census, '', ''); 258 259 $this->assertSame('', $column->generate($individual, $individual)); 260 } 261 262 /** 263 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 264 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 265 * 266 * @return void 267 */ 268 public function testChildFemale(): void 269 { 270 $family = $this->createMock(Family::class); 271 $family->method('getMarriageDate')->willReturn(new Date('')); 272 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 273 274 $individual = $this->createMock(Individual::class); 275 $individual->method('sex')->willReturn('F'); 276 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 277 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 278 279 $census = $this->createMock(CensusInterface::class); 280 $census->method('censusDate')->willReturn('30 JUN 1830'); 281 282 $column = new CensusColumnConditionDanish($census, '', ''); 283 284 $this->assertSame('', $column->generate($individual, $individual)); 285 } 286 287 /** 288 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 289 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 290 * 291 * @return void 292 */ 293 public function testDivorcedMale(): void 294 { 295 $fact = $this->createMock(Fact::class); 296 297 $family = $this->createMock(Family::class); 298 $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date('')); 299 $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 300 $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection([$fact])); 301 302 $individual = $this->createMock(Individual::class); 303 $individual->method('sex')->willReturn('M'); 304 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 305 306 $census = $this->createMock(CensusInterface::class); 307 308 $column = new CensusColumnConditionDanish($census, '', ''); 309 $census->method('censusDate')->willReturn('30 JUN 1830'); 310 311 $this->assertSame('Skilt', $column->generate($individual, $individual)); 312 } 313 314 /** 315 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionDanish 316 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 317 * 318 * @return void 319 */ 320 public function testDivorcedFemale(): void 321 { 322 $fact = $this->createMock(Fact::class); 323 324 $family = $this->createMock(Family::class); 325 $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date('')); 326 $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 327 $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection([$fact])); 328 329 $individual = $this->createMock(Individual::class); 330 $individual->method('sex')->willReturn('F'); 331 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 332 333 $census = $this->createMock(CensusInterface::class); 334 335 $column = new CensusColumnConditionDanish($census, '', ''); 336 $census->method('censusDate')->willReturn('30 JUN 1830'); 337 338 $this->assertSame('Skilt', $column->generate($individual, $individual)); 339 } 340} 341