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 CensusColumnConditionFrenchVeuve 31 */ 32class CensusColumnConditionFrenchVeuveTest extends TestCase 33{ 34 /** 35 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 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 CensusColumnConditionFrenchVeuve($census, '', ''); 51 52 self::assertSame('', $column->generate($individual, $individual)); 53 } 54 55 /** 56 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 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 CensusColumnConditionFrenchVeuve($census, '', ''); 72 73 self::assertSame('', $column->generate($individual, $individual)); 74 } 75 76 /** 77 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 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 CensusColumnConditionFrenchVeuve($census, '', ''); 96 $census->method('censusDate')->willReturn('30 JUN 1830'); 97 98 self::assertSame('', $column->generate($individual, $individual)); 99 } 100 101 /** 102 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 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 CensusColumnConditionFrenchVeuve($census, '', ''); 121 $census->method('censusDate')->willReturn('30 JUN 1830'); 122 123 self::assertSame('', $column->generate($individual, $individual)); 124 } 125 126 /** 127 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 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 142 ->expects(self::exactly(2)) 143 ->method('facts') 144 ->withConsecutive( 145 [['MARR']], 146 [['DIV']] 147 ) 148 ->willReturnOnConsecutiveCalls( 149 new Collection([$fact]), 150 new Collection() 151 ); 152 $family->expects(self::once())->method('spouse')->willReturn($spouse); 153 154 $individual = $this->createMock(Individual::class); 155 $individual->method('sex')->willReturn('M'); 156 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 157 158 $census = $this->createMock(CensusInterface::class); 159 160 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 161 $census->method('censusDate')->willReturn('30 JUN 1830'); 162 163 self::assertSame('', $column->generate($individual, $individual)); 164 } 165 166 /** 167 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 168 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 169 * 170 * @return void 171 */ 172 public function testSpouseDeadFemale(): void 173 { 174 $fact = $this->createMock(Fact::class); 175 176 $spouse = $this->createMock(Individual::class); 177 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 178 179 $family = $this->createMock(Family::class); 180 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 181 $family 182 ->expects(self::exactly(2)) 183 ->method('facts') 184 ->withConsecutive( 185 [['MARR']], 186 [['DIV']] 187 ) 188 ->willReturnOnConsecutiveCalls( 189 new Collection([$fact]), 190 new Collection() 191 ); 192 $family->expects(self::once())->method('spouse')->willReturn($spouse); 193 194 $individual = $this->createMock(Individual::class); 195 $individual->method('sex')->willReturn('F'); 196 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 197 198 $census = $this->createMock(CensusInterface::class); 199 200 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 201 $census->method('censusDate')->willReturn('30 JUN 1830'); 202 203 self::assertSame('1', $column->generate($individual, $individual)); 204 } 205 206 /** 207 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 208 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 209 * 210 * @return void 211 */ 212 public function testNoFamilyUnmarriedMale(): void 213 { 214 $family = $this->createMock(Family::class); 215 $family->method('getMarriageDate')->willReturn(new Date('')); 216 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 217 218 $individual = $this->createMock(Individual::class); 219 $individual->method('sex')->willReturn('M'); 220 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 221 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 222 223 $census = $this->createMock(CensusInterface::class); 224 $census->method('censusDate')->willReturn('30 JUN 1830'); 225 226 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 227 228 self::assertSame('', $column->generate($individual, $individual)); 229 } 230 231 /** 232 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 233 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 234 * 235 * @return void 236 */ 237 public function testNoFamilyUnmarriedFemale(): void 238 { 239 $family = $this->createMock(Family::class); 240 $family->method('getMarriageDate')->willReturn(new Date('')); 241 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 242 243 $individual = $this->createMock(Individual::class); 244 $individual->method('sex')->willReturn('F'); 245 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 246 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 247 248 $census = $this->createMock(CensusInterface::class); 249 $census->method('censusDate')->willReturn('30 JUN 1830'); 250 251 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 252 253 self::assertSame('', $column->generate($individual, $individual)); 254 } 255 256 /** 257 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 258 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 259 * 260 * @return void 261 */ 262 public function testChildMale(): void 263 { 264 $family = $this->createMock(Family::class); 265 $family->method('getMarriageDate')->willReturn(new Date('')); 266 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 267 268 $individual = $this->createMock(Individual::class); 269 $individual->method('sex')->willReturn('M'); 270 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 271 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 272 273 $census = $this->createMock(CensusInterface::class); 274 $census->method('censusDate')->willReturn('30 JUN 1830'); 275 276 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 277 278 self::assertSame('', $column->generate($individual, $individual)); 279 } 280 281 /** 282 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 283 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 284 * 285 * @return void 286 */ 287 public function testChildFemale(): void 288 { 289 $family = $this->createMock(Family::class); 290 $family->method('getMarriageDate')->willReturn(new Date('')); 291 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 292 293 $individual = $this->createMock(Individual::class); 294 $individual->method('sex')->willReturn('F'); 295 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 296 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 297 298 $census = $this->createMock(CensusInterface::class); 299 $census->method('censusDate')->willReturn('30 JUN 1830'); 300 301 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 302 303 self::assertSame('', $column->generate($individual, $individual)); 304 } 305 306 /** 307 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 308 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 309 * 310 * @return void 311 */ 312 public function testDivorcedMale(): void 313 { 314 $fact = $this->createMock(Fact::class); 315 316 $family = $this->createMock(Family::class); 317 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 318 $family 319 ->expects(self::exactly(2)) 320 ->method('facts') 321 ->withConsecutive( 322 [['MARR']], 323 [['DIV']] 324 ) 325 ->willReturn( 326 new Collection([$fact]), 327 new Collection([$fact]) 328 ); 329 330 $individual = $this->createMock(Individual::class); 331 $individual->method('sex')->willReturn('M'); 332 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 333 334 $census = $this->createMock(CensusInterface::class); 335 336 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 337 $census->method('censusDate')->willReturn('30 JUN 1830'); 338 339 self::assertSame('', $column->generate($individual, $individual)); 340 } 341 342 /** 343 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionFrenchVeuve 344 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 345 * 346 * @return void 347 */ 348 public function testDivorcedFemale(): void 349 { 350 $fact = $this->createMock(Fact::class); 351 352 $family = $this->createMock(Family::class); 353 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 354 $family 355 ->expects(self::exactly(2)) 356 ->method('facts') 357 ->withConsecutive( 358 [['MARR']], 359 [['DIV']] 360 ) 361 ->willReturn( 362 new Collection([$fact]), 363 new Collection([$fact]) 364 ); 365 366 $individual = $this->createMock(Individual::class); 367 $individual->method('sex')->willReturn('F'); 368 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 369 370 $census = $this->createMock(CensusInterface::class); 371 372 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 373 $census->method('censusDate')->willReturn('30 JUN 1830'); 374 375 self::assertSame('', $column->generate($individual, $individual)); 376 } 377} 378