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