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(CensusColumnConditionFrenchVeuve::class)] 32#[CoversClass(AbstractCensusColumnCondition::class)] 33class CensusColumnConditionFrenchVeuveTest 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 CensusColumnConditionFrenchVeuve($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 CensusColumnConditionFrenchVeuve($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 CensusColumnConditionFrenchVeuve($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 CensusColumnConditionFrenchVeuve($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 113 ->expects(self::exactly(2)) 114 ->method('facts') 115 ->with(self::withConsecutive([['MARR'], ['DIV']])) 116 ->willReturnOnConsecutiveCalls( 117 new Collection([$fact]), 118 new Collection() 119 ); 120 $family->expects(self::once())->method('spouse')->willReturn($spouse); 121 122 $individual = $this->createMock(Individual::class); 123 $individual->method('sex')->willReturn('M'); 124 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 125 126 $census = $this->createMock(CensusInterface::class); 127 128 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 129 $census->method('censusDate')->willReturn('30 JUN 1830'); 130 131 self::assertSame('', $column->generate($individual, $individual)); 132 } 133 134 public function testSpouseDeadFemale(): void 135 { 136 $fact = $this->createMock(Fact::class); 137 138 $spouse = $this->createMock(Individual::class); 139 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 140 141 $family = $this->createMock(Family::class); 142 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 143 $family 144 ->expects(self::exactly(2)) 145 ->method('facts') 146 ->with(self::withConsecutive([['MARR'], ['DIV']])) 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('F'); 155 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 156 157 $census = $this->createMock(CensusInterface::class); 158 159 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 160 $census->method('censusDate')->willReturn('30 JUN 1830'); 161 162 self::assertSame('1', $column->generate($individual, $individual)); 163 } 164 165 public function testNoFamilyUnmarriedMale(): void 166 { 167 $family = $this->createMock(Family::class); 168 $family->method('getMarriageDate')->willReturn(new Date('')); 169 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 170 171 $individual = $this->createMock(Individual::class); 172 $individual->method('sex')->willReturn('M'); 173 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 174 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 175 176 $census = $this->createMock(CensusInterface::class); 177 $census->method('censusDate')->willReturn('30 JUN 1830'); 178 179 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 180 181 self::assertSame('', $column->generate($individual, $individual)); 182 } 183 184 public function testNoFamilyUnmarriedFemale(): void 185 { 186 $family = $this->createMock(Family::class); 187 $family->method('getMarriageDate')->willReturn(new Date('')); 188 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 189 190 $individual = $this->createMock(Individual::class); 191 $individual->method('sex')->willReturn('F'); 192 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 193 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 194 195 $census = $this->createMock(CensusInterface::class); 196 $census->method('censusDate')->willReturn('30 JUN 1830'); 197 198 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 199 200 self::assertSame('', $column->generate($individual, $individual)); 201 } 202 203 public function testChildMale(): void 204 { 205 $family = $this->createMock(Family::class); 206 $family->method('getMarriageDate')->willReturn(new Date('')); 207 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 208 209 $individual = $this->createMock(Individual::class); 210 $individual->method('sex')->willReturn('M'); 211 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 212 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 213 214 $census = $this->createMock(CensusInterface::class); 215 $census->method('censusDate')->willReturn('30 JUN 1830'); 216 217 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 218 219 self::assertSame('', $column->generate($individual, $individual)); 220 } 221 222 public function testChildFemale(): void 223 { 224 $family = $this->createMock(Family::class); 225 $family->method('getMarriageDate')->willReturn(new Date('')); 226 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 227 228 $individual = $this->createMock(Individual::class); 229 $individual->method('sex')->willReturn('F'); 230 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 231 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 232 233 $census = $this->createMock(CensusInterface::class); 234 $census->method('censusDate')->willReturn('30 JUN 1830'); 235 236 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 237 238 self::assertSame('', $column->generate($individual, $individual)); 239 } 240 241 public function testDivorcedMale(): void 242 { 243 $fact = $this->createMock(Fact::class); 244 245 $family = $this->createMock(Family::class); 246 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 247 $family 248 ->expects(self::exactly(2)) 249 ->method('facts') 250 ->with(self::withConsecutive([['MARR'], ['DIV']])) 251 ->willReturn( 252 new Collection([$fact]), 253 new Collection([$fact]) 254 ); 255 256 $individual = $this->createMock(Individual::class); 257 $individual->method('sex')->willReturn('M'); 258 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 259 260 $census = $this->createMock(CensusInterface::class); 261 262 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 263 $census->method('censusDate')->willReturn('30 JUN 1830'); 264 265 self::assertSame('', $column->generate($individual, $individual)); 266 } 267 268 public function testDivorcedFemale(): void 269 { 270 $fact = $this->createMock(Fact::class); 271 272 $family = $this->createMock(Family::class); 273 $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 274 $family 275 ->expects(self::exactly(2)) 276 ->method('facts') 277 ->with(self::withConsecutive([['MARR'], ['DIV']])) 278 ->willReturn( 279 new Collection([$fact]), 280 new Collection([$fact]) 281 ); 282 283 $individual = $this->createMock(Individual::class); 284 $individual->method('sex')->willReturn('F'); 285 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 286 287 $census = $this->createMock(CensusInterface::class); 288 289 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 290 $census->method('censusDate')->willReturn('30 JUN 1830'); 291 292 self::assertSame('', $column->generate($individual, $individual)); 293 } 294} 295