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