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#[CoversClass(CensusColumnConditionFrenchVeuve::class)] 31#[CoversClass(AbstractCensusColumnCondition::class)] 32class CensusColumnConditionFrenchVeuveTest extends TestCase 33{ 34 public function testNoSpouseFamiliesMale(): void 35 { 36 $individual = $this->createMock(Individual::class); 37 $individual->method('sex')->willReturn('M'); 38 $individual->method('spouseFamilies')->willReturn(new Collection()); 39 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 40 41 $census = $this->createMock(CensusInterface::class); 42 $census->method('censusDate')->willReturn('30 JUN 1830'); 43 44 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 45 46 self::assertSame('', $column->generate($individual, $individual)); 47 } 48 49 public function testNoSpouseFamiliesFemale(): void 50 { 51 $individual = $this->createMock(Individual::class); 52 $individual->method('sex')->willReturn('F'); 53 $individual->method('spouseFamilies')->willReturn(new Collection()); 54 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 55 56 $census = $this->createMock(CensusInterface::class); 57 $census->method('censusDate')->willReturn('30 JUN 1830'); 58 59 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 60 61 self::assertSame('', $column->generate($individual, $individual)); 62 } 63 64 public function testNoFamilyFactsMale(): void 65 { 66 $family = $this->createMock(Family::class); 67 $family->method('getMarriageDate')->willReturn(new Date('')); 68 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 69 70 $individual = $this->createMock(Individual::class); 71 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 72 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 73 $individual->method('sex')->willReturn('M'); 74 75 $census = $this->createMock(CensusInterface::class); 76 77 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 78 $census->method('censusDate')->willReturn('30 JUN 1830'); 79 80 self::assertSame('', $column->generate($individual, $individual)); 81 } 82 83 public function testNoFamilyFactsFemale(): void 84 { 85 $family = $this->createMock(Family::class); 86 $family->method('getMarriageDate')->willReturn(new Date('')); 87 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 88 89 $individual = $this->createMock(Individual::class); 90 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 91 $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 92 $individual->method('sex')->willReturn('F'); 93 94 $census = $this->createMock(CensusInterface::class); 95 96 $column = new CensusColumnConditionFrenchVeuve($census, '', ''); 97 $census->method('censusDate')->willReturn('30 JUN 1830'); 98 99 self::assertSame('', $column->generate($individual, $individual)); 100 } 101 102 public function testSpouseDeadMale(): void 103 { 104 $fact = $this->createMock(Fact::class); 105 106 $spouse = $this->createMock(Individual::class); 107 $spouse->method('getDeathDate')->willReturn(new Date('1820')); 108 109 $family = $this->createMock(Family::class); 110 $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 111 $family 112 ->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($this->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 CensusColumnConditionFrenchVeuve($census, '', ''); 128 $census->method('censusDate')->willReturn('30 JUN 1830'); 129 130 self::assertSame('', $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($this->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($this->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 CensusColumnConditionFrenchVeuve($census, '', ''); 159 $census->method('censusDate')->willReturn('30 JUN 1830'); 160 161 self::assertSame('1', $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 CensusColumnConditionFrenchVeuve($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 CensusColumnConditionFrenchVeuve($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 CensusColumnConditionFrenchVeuve($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 CensusColumnConditionFrenchVeuve($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($this->once())->method('getMarriageDate')->willReturn(new Date('')); 246 $family 247 ->expects(self::exactly(2)) 248 ->method('facts') 249 ->with(self::withConsecutive([['MARR'], ['DIV']])) 250 ->willReturn( 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 CensusColumnConditionFrenchVeuve($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($this->once())->method('getMarriageDate')->willReturn(new Date('')); 273 $family 274 ->expects(self::exactly(2)) 275 ->method('facts') 276 ->with(self::withConsecutive([['MARR'], ['DIV']])) 277 ->willReturn( 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 CensusColumnConditionFrenchVeuve($census, '', ''); 289 $census->method('censusDate')->willReturn('30 JUN 1830'); 290 291 self::assertSame('', $column->generate($individual, $individual)); 292 } 293} 294