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