1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2022 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\Date; 23use Fisharebest\Webtrees\Fact; 24use Fisharebest\Webtrees\Family; 25use Fisharebest\Webtrees\Individual; 26use Fisharebest\Webtrees\TestCase; 27use Illuminate\Support\Collection; 28 29/** 30 * Test harness for the class CensusColumnConditionUs 31 */ 32class CensusColumnConditionUsTest extends TestCase 33{ 34 /** 35 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 36 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 37 * 38 * @return void 39 */ 40 public function testNoSpouseFamiliesMale(): void 41 { 42 $individual = $this->createMock(Individual::class); 43 $individual->method('sex')->willReturn('M'); 44 $individual->method('spouseFamilies')->willReturn(new Collection()); 45 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 46 47 $census = $this->createMock(CensusInterface::class); 48 $census->method('censusDate')->willReturn('30 JUN 1830'); 49 50 $column = new CensusColumnConditionUs($census, '', ''); 51 52 self::assertSame('S', $column->generate($individual, $individual)); 53 } 54 55 /** 56 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 57 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 58 * 59 * @return void 60 */ 61 public function testNoSpouseFamiliesFemale(): void 62 { 63 $individual = $this->createMock(Individual::class); 64 $individual->method('sex')->willReturn('F'); 65 $individual->method('spouseFamilies')->willReturn(new Collection()); 66 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 67 68 $census = $this->createMock(CensusInterface::class); 69 $census->method('censusDate')->willReturn('30 JUN 1830'); 70 71 $column = new CensusColumnConditionUs($census, '', ''); 72 73 self::assertSame('S', $column->generate($individual, $individual)); 74 } 75 76 /** 77 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 78 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 79 * 80 * @return void 81 */ 82 public function testNoFamilyFactsMale(): void 83 { 84 $family = $this->createMock(Family::class); 85 $family->method('getMarriageDate')->willReturn(new Date('')); 86 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 87 88 $individual = $this->createMock(Individual::class); 89 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 90 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 91 $individual->method('sex')->willReturn('M'); 92 93 $census = $this->createMock(CensusInterface::class); 94 95 $column = new CensusColumnConditionUs($census, '', ''); 96 $census->method('censusDate')->willReturn('30 JUN 1830'); 97 98 self::assertSame('S', $column->generate($individual, $individual)); 99 } 100 101 /** 102 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 103 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 104 * 105 * @return void 106 */ 107 public function testNoFamilyFactsFemale(): void 108 { 109 $family = $this->createMock(Family::class); 110 $family->method('getMarriageDate')->willReturn(new Date('')); 111 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 112 113 $individual = $this->createMock(Individual::class); 114 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 115 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 116 $individual->method('sex')->willReturn('F'); 117 118 $census = $this->createMock(CensusInterface::class); 119 120 $column = new CensusColumnConditionUs($census, '', ''); 121 $census->method('censusDate')->willReturn('30 JUN 1830'); 122 123 self::assertSame('S', $column->generate($individual, $individual)); 124 } 125 126 /** 127 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 128 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 129 * 130 * @return void 131 */ 132 public function testSpouseDeadMale(): void 133 { 134 $fact = $this->createMock(Fact::class); 135 136 $spouse = $this->createMock(Individual::class); 137 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 138 139 $family = $this->createMock(Family::class); 140 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 141 $family->expects(self::exactly(2)) 142 ->method('facts') 143 ->withConsecutive( 144 [['MARR']], 145 [['DIV']] 146 ) 147 ->willReturnOnConsecutiveCalls( 148 new Collection([$fact]), 149 new Collection() 150 ); 151 $family->expects(self::once())->method('spouse')->willReturn($spouse); 152 153 $individual = $this->createMock(Individual::class); 154 $individual->method('sex')->willReturn('M'); 155 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 156 157 $census = $this->createMock(CensusInterface::class); 158 159 $column = new CensusColumnConditionUs($census, '', ''); 160 $census->method('censusDate')->willReturn('30 JUN 1830'); 161 162 self::assertSame('W', $column->generate($individual, $individual)); 163 } 164 165 /** 166 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 167 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 168 * 169 * @return void 170 */ 171 public function testSpouseDeadFemale(): void 172 { 173 $fact = $this->createMock(Fact::class); 174 175 $spouse = $this->createMock(Individual::class); 176 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 177 178 $family = $this->createMock(Family::class); 179 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 180 $family 181 ->expects(self::exactly(2)) 182 ->method('facts') 183 ->withConsecutive( 184 [['MARR']], 185 [['DIV']] 186 ) 187 ->willReturnOnConsecutiveCalls( 188 new Collection([$fact]), 189 new Collection() 190 ); 191 $family->expects(self::once())->method('spouse')->willReturn($spouse); 192 193 $individual = $this->createMock(Individual::class); 194 $individual->method('sex')->willReturn('F'); 195 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 196 197 $census = $this->createMock(CensusInterface::class); 198 199 $column = new CensusColumnConditionUs($census, '', ''); 200 $census->method('censusDate')->willReturn('30 JUN 1830'); 201 202 self::assertSame('W', $column->generate($individual, $individual)); 203 } 204 205 /** 206 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 207 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 208 * 209 * @return void 210 */ 211 public function testNoFamilyUnmarriedMale(): void 212 { 213 $family = $this->createMock(Family::class); 214 $family->method('getMarriageDate')->willReturn(new Date('')); 215 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 216 217 $individual = $this->createMock(Individual::class); 218 $individual->method('sex')->willReturn('M'); 219 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 220 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 221 222 $census = $this->createMock(CensusInterface::class); 223 $census->method('censusDate')->willReturn('30 JUN 1830'); 224 225 $column = new CensusColumnConditionUs($census, '', ''); 226 227 self::assertSame('S', $column->generate($individual, $individual)); 228 } 229 230 /** 231 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 232 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 233 * 234 * @return void 235 */ 236 public function testNoFamilyUnmarriedFemale(): void 237 { 238 $family = $this->createMock(Family::class); 239 $family->method('getMarriageDate')->willReturn(new Date('')); 240 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 241 242 $individual = $this->createMock(Individual::class); 243 $individual->method('sex')->willReturn('F'); 244 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 245 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 246 247 $census = $this->createMock(CensusInterface::class); 248 $census->method('censusDate')->willReturn('30 JUN 1830'); 249 250 $column = new CensusColumnConditionUs($census, '', ''); 251 252 self::assertSame('S', $column->generate($individual, $individual)); 253 } 254 255 /** 256 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 257 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 258 * 259 * @return void 260 */ 261 public function testChildMale(): void 262 { 263 $family = $this->createMock(Family::class); 264 $family->method('getMarriageDate')->willReturn(new Date('')); 265 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 266 267 $individual = $this->createMock(Individual::class); 268 $individual->method('sex')->willReturn('M'); 269 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 270 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 271 272 $census = $this->createMock(CensusInterface::class); 273 $census->method('censusDate')->willReturn('30 JUN 1830'); 274 275 $column = new CensusColumnConditionUs($census, '', ''); 276 277 self::assertSame('S', $column->generate($individual, $individual)); 278 } 279 280 /** 281 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 282 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 283 * 284 * @return void 285 */ 286 public function testChildFemale(): void 287 { 288 $family = $this->createMock(Family::class); 289 $family->method('getMarriageDate')->willReturn(new Date('')); 290 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 291 292 $individual = $this->createMock(Individual::class); 293 $individual->method('sex')->willReturn('F'); 294 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 295 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 296 297 $census = $this->createMock(CensusInterface::class); 298 $census->method('censusDate')->willReturn('30 JUN 1830'); 299 300 $column = new CensusColumnConditionUs($census, '', ''); 301 302 self::assertSame('S', $column->generate($individual, $individual)); 303 } 304 305 /** 306 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 307 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 308 * 309 * @return void 310 */ 311 public function testDivorcedMale(): void 312 { 313 $fact = $this->createMock(Fact::class); 314 315 $family = $this->createMock(Family::class); 316 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 317 $family 318 ->expects(self::exactly(2)) 319 ->method('facts') 320 ->withConsecutive( 321 [['MARR']], 322 [['DIV']] 323 )->willReturnOnConsecutiveCalls( 324 new Collection([$fact]), 325 new Collection([$fact]) 326 ); 327 328 $individual = $this->createMock(Individual::class); 329 $individual->method('sex')->willReturn('M'); 330 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 331 332 $census = $this->createMock(CensusInterface::class); 333 334 $column = new CensusColumnConditionUs($census, '', ''); 335 $census->method('censusDate')->willReturn('30 JUN 1830'); 336 337 self::assertSame('D', $column->generate($individual, $individual)); 338 } 339 340 /** 341 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 342 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 343 * 344 * @return void 345 */ 346 public function testDivorcedFemale(): void 347 { 348 $fact = $this->createMock(Fact::class); 349 350 $family = $this->createMock(Family::class); 351 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 352 $family 353 ->expects(self::exactly(2)) 354 ->method('facts') 355 ->withConsecutive( 356 [['MARR']], 357 [['DIV']] 358 )->willReturnOnConsecutiveCalls( 359 new Collection([$fact]), 360 new Collection([$fact]) 361 ); 362 363 $individual = $this->createMock(Individual::class); 364 $individual->method('sex')->willReturn('F'); 365 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 366 367 $census = $this->createMock(CensusInterface::class); 368 369 $column = new CensusColumnConditionUs($census, '', ''); 370 $census->method('censusDate')->willReturn('30 JUN 1830'); 371 372 self::assertSame('D', $column->generate($individual, $individual)); 373 } 374 375 /** 376 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 377 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 378 * 379 * @return void 380 */ 381 public function testMarriedMale(): void 382 { 383 $fact = $this->createMock(Fact::class); 384 385 $family = $this->createMock(Family::class); 386 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 387 $family 388 ->expects(self::exactly(2)) 389 ->method('facts') 390 ->withConsecutive( 391 [['MARR']], 392 [['DIV']] 393 )->willReturnOnConsecutiveCalls( 394 new Collection([$fact]), 395 new Collection() 396 ); 397 398 $individual = $this->createMock(Individual::class); 399 $individual->method('sex')->willReturn('M'); 400 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 401 402 $census = $this->createMock(CensusInterface::class); 403 404 $column = new CensusColumnConditionUs($census, '', ''); 405 $census->method('censusDate')->willReturn('30 JUN 1830'); 406 407 self::assertSame('M', $column->generate($individual, $individual)); 408 } 409 410 /** 411 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 412 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 413 * 414 * @return void 415 */ 416 public function testMarriedFemale(): void 417 { 418 $fact = $this->createMock(Fact::class); 419 420 $family = $this->createMock(Family::class); 421 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 422 $family 423 ->expects(self::exactly(2)) 424 ->method('facts') 425 ->withConsecutive( 426 [['MARR']], 427 [['DIV']] 428 )->willReturnOnConsecutiveCalls( 429 new Collection([$fact]), 430 new Collection() 431 ); 432 433 $individual = $this->createMock(Individual::class); 434 $individual->method('sex')->willReturn('F'); 435 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 436 437 $census = $this->createMock(CensusInterface::class); 438 439 $column = new CensusColumnConditionUs($census, '', ''); 440 $census->method('censusDate')->willReturn('30 JUN 1830'); 441 442 self::assertSame('M', $column->generate($individual, $individual)); 443 } 444} 445