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