1da3cb887Sglarwill<?php 2da3cb887Sglarwill 3da3cb887Sglarwill/** 4da3cb887Sglarwill * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6da3cb887Sglarwill * This program is free software: you can redistribute it and/or modify 7da3cb887Sglarwill * it under the terms of the GNU General Public License as published by 8da3cb887Sglarwill * the Free Software Foundation, either version 3 of the License, or 9da3cb887Sglarwill * (at your option) any later version. 10da3cb887Sglarwill * This program is distributed in the hope that it will be useful, 11da3cb887Sglarwill * but WITHOUT ANY WARRANTY; without even the implied warranty of 12da3cb887Sglarwill * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13da3cb887Sglarwill * GNU General Public License for more details. 14da3cb887Sglarwill * You should have received a copy of the GNU General Public License 15da3cb887Sglarwill * along with this program. If not, see <https://www.gnu.org/licenses/>. 16da3cb887Sglarwill */ 17da3cb887Sglarwill 18da3cb887Sglarwilldeclare(strict_types=1); 19da3cb887Sglarwill 20da3cb887Sglarwillnamespace Fisharebest\Webtrees\Census; 21da3cb887Sglarwill 22da3cb887Sglarwilluse Fisharebest\Webtrees\Date; 23da3cb887Sglarwilluse Fisharebest\Webtrees\Fact; 24da3cb887Sglarwilluse Fisharebest\Webtrees\Family; 25da3cb887Sglarwilluse Fisharebest\Webtrees\Individual; 26da3cb887Sglarwilluse Fisharebest\Webtrees\TestCase; 27da3cb887Sglarwilluse Illuminate\Support\Collection; 28*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 29da3cb887Sglarwill 30*202c018bSGreg Roach 31*202c018bSGreg Roach#[CoversClass(CensusColumnConditionCanadaMarriedSingle::class)] 32*202c018bSGreg Roach#[CoversClass(AbstractCensusColumnCondition::class)] 33da3cb887Sglarwillclass CensusColumnConditionCanadaMarriedSingleTest extends TestCase 34da3cb887Sglarwill{ 35da3cb887Sglarwill public function testNoSpouseFamiliesMale(): void 36da3cb887Sglarwill { 37cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 38da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 39da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection()); 40da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 41da3cb887Sglarwill 42cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 43da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 44da3cb887Sglarwill 45da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 46da3cb887Sglarwill 47da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 48da3cb887Sglarwill } 49da3cb887Sglarwill 50da3cb887Sglarwill public function testNoSpouseFamiliesFemale(): void 51da3cb887Sglarwill { 52cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 53da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 54da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection()); 55da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 56da3cb887Sglarwill 57cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 58da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 59da3cb887Sglarwill 60da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 61da3cb887Sglarwill 62da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 63da3cb887Sglarwill } 64da3cb887Sglarwill 65da3cb887Sglarwill public function testNoFamilyFactsMale(): void 66da3cb887Sglarwill { 67cd94ca66SGreg Roach $family = $this->createMock(Family::class); 68da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 69da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 70da3cb887Sglarwill 71cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 72da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 73da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 74da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 75da3cb887Sglarwill 76cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 77da3cb887Sglarwill 78da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 79da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 80da3cb887Sglarwill 81da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 82da3cb887Sglarwill } 83da3cb887Sglarwill 84da3cb887Sglarwill public function testNoFamilyFactsFemale(): void 85da3cb887Sglarwill { 86cd94ca66SGreg Roach $family = $this->createMock(Family::class); 87da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 88da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 89da3cb887Sglarwill 90cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 91da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 92da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 93da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 94da3cb887Sglarwill 95cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 96da3cb887Sglarwill 97da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 98da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 99da3cb887Sglarwill 100da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 101da3cb887Sglarwill } 102da3cb887Sglarwill 103da3cb887Sglarwill public function testSpouseDeadMale(): void 104da3cb887Sglarwill { 105cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 106da3cb887Sglarwill 107cd94ca66SGreg Roach $spouse = $this->createMock(Individual::class); 108da3cb887Sglarwill $spouse->method('getDeathDate')->willReturn(new Date('1820')); 109da3cb887Sglarwill 110cd94ca66SGreg Roach $family = $this->createMock(Family::class); 111da3cb887Sglarwill $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 112da3cb887Sglarwill $family->expects(self::exactly(2)) 113da3cb887Sglarwill ->method('facts') 1149aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 115da3cb887Sglarwill ->willReturnOnConsecutiveCalls( 116da3cb887Sglarwill new Collection([$fact]), 117da3cb887Sglarwill new Collection() 118da3cb887Sglarwill ); 119da3cb887Sglarwill $family->expects(self::once())->method('spouse')->willReturn($spouse); 120da3cb887Sglarwill 121cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 122da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 123da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 124da3cb887Sglarwill 125cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 126da3cb887Sglarwill 127da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 128da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 129da3cb887Sglarwill 130da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 131da3cb887Sglarwill } 132da3cb887Sglarwill 133da3cb887Sglarwill public function testSpouseDeadFemale(): void 134da3cb887Sglarwill { 135cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 136da3cb887Sglarwill 137cd94ca66SGreg Roach $spouse = $this->createMock(Individual::class); 138da3cb887Sglarwill $spouse->method('getDeathDate')->willReturn(new Date('1820')); 139da3cb887Sglarwill 140cd94ca66SGreg Roach $family = $this->createMock(Family::class); 141da3cb887Sglarwill $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 142da3cb887Sglarwill $family 143da3cb887Sglarwill ->expects(self::exactly(2)) 144da3cb887Sglarwill ->method('facts') 1459aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 146da3cb887Sglarwill ->willReturnOnConsecutiveCalls( 147da3cb887Sglarwill new Collection([$fact]), 148da3cb887Sglarwill new Collection() 149da3cb887Sglarwill ); 150da3cb887Sglarwill $family->expects(self::once())->method('spouse')->willReturn($spouse); 151da3cb887Sglarwill 152cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 153da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 154da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 155da3cb887Sglarwill 156cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 157da3cb887Sglarwill 158da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 159da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 160da3cb887Sglarwill 161da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 162da3cb887Sglarwill } 163da3cb887Sglarwill 164da3cb887Sglarwill public function testNoFamilyUnmarriedMale(): void 165da3cb887Sglarwill { 166cd94ca66SGreg Roach $family = $this->createMock(Family::class); 167da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 168da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 169da3cb887Sglarwill 170cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 171da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 172da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 173da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 174da3cb887Sglarwill 175cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 176da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 177da3cb887Sglarwill 178da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 179da3cb887Sglarwill 180da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 181da3cb887Sglarwill } 182da3cb887Sglarwill 183da3cb887Sglarwill public function testNoFamilyUnmarriedFemale(): void 184da3cb887Sglarwill { 185cd94ca66SGreg Roach $family = $this->createMock(Family::class); 186da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 187da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 188da3cb887Sglarwill 189cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 190da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 191da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 192da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 193da3cb887Sglarwill 194cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 195da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 196da3cb887Sglarwill 197da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 198da3cb887Sglarwill 199da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 200da3cb887Sglarwill } 201da3cb887Sglarwill 202da3cb887Sglarwill public function testChildMale(): void 203da3cb887Sglarwill { 204cd94ca66SGreg Roach $family = $this->createMock(Family::class); 205da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 206da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 207da3cb887Sglarwill 208cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 209da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 210da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 211da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 212da3cb887Sglarwill 213cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 214da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 215da3cb887Sglarwill 216da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 217da3cb887Sglarwill 218da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 219da3cb887Sglarwill } 220da3cb887Sglarwill 221da3cb887Sglarwill public function testChildFemale(): void 222da3cb887Sglarwill { 223cd94ca66SGreg Roach $family = $this->createMock(Family::class); 224da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 225da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 226da3cb887Sglarwill 227cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 228da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 229da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 230da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 231da3cb887Sglarwill 232cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 233da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 234da3cb887Sglarwill 235da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 236da3cb887Sglarwill 237da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 238da3cb887Sglarwill } 239da3cb887Sglarwill 240da3cb887Sglarwill public function testDivorcedMale(): void 241da3cb887Sglarwill { 242cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 243da3cb887Sglarwill 244cd94ca66SGreg Roach $family = $this->createMock(Family::class); 245da3cb887Sglarwill $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 246da3cb887Sglarwill $family 247da3cb887Sglarwill ->expects(self::exactly(2)) 248da3cb887Sglarwill ->method('facts') 2499aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 2509aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 251da3cb887Sglarwill new Collection([$fact]), 252da3cb887Sglarwill new Collection([$fact]) 253da3cb887Sglarwill ); 254da3cb887Sglarwill 255cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 256da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 257da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 258da3cb887Sglarwill 259cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 260da3cb887Sglarwill 261da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 262da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 263da3cb887Sglarwill 264da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 265da3cb887Sglarwill } 266da3cb887Sglarwill 267da3cb887Sglarwill public function testDivorcedFemale(): void 268da3cb887Sglarwill { 269cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 270da3cb887Sglarwill 271cd94ca66SGreg Roach $family = $this->createMock(Family::class); 272da3cb887Sglarwill $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 273da3cb887Sglarwill $family 274da3cb887Sglarwill ->expects(self::exactly(2)) 275da3cb887Sglarwill ->method('facts') 2769aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 2779aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 278da3cb887Sglarwill new Collection([$fact]), 279da3cb887Sglarwill new Collection([$fact]) 280da3cb887Sglarwill ); 281da3cb887Sglarwill 282cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 283da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 284da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 285da3cb887Sglarwill 286cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 287da3cb887Sglarwill 288da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 289da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 290da3cb887Sglarwill 291da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 292da3cb887Sglarwill } 293da3cb887Sglarwill 294da3cb887Sglarwill public function testMarriedMale(): void 295da3cb887Sglarwill { 296cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 297da3cb887Sglarwill 298cd94ca66SGreg Roach $family = $this->createMock(Family::class); 299da3cb887Sglarwill $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 300da3cb887Sglarwill $family 301da3cb887Sglarwill ->expects(self::exactly(2)) 302da3cb887Sglarwill ->method('facts') 3039aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 3049aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 305da3cb887Sglarwill new Collection([$fact]), 306da3cb887Sglarwill new Collection() 307da3cb887Sglarwill ); 308da3cb887Sglarwill 309cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 310da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 311da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 312da3cb887Sglarwill 313cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 314da3cb887Sglarwill 315da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 316da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 317da3cb887Sglarwill 318da3cb887Sglarwill self::assertSame('M', $column->generate($individual, $individual)); 319da3cb887Sglarwill } 320da3cb887Sglarwill 321da3cb887Sglarwill public function testMarriedFemale(): void 322da3cb887Sglarwill { 323cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 324da3cb887Sglarwill 325cd94ca66SGreg Roach $family = $this->createMock(Family::class); 326da3cb887Sglarwill $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 327da3cb887Sglarwill $family 328da3cb887Sglarwill ->expects(self::exactly(2)) 329da3cb887Sglarwill ->method('facts') 3309aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 3319aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 332da3cb887Sglarwill new Collection([$fact]), 333da3cb887Sglarwill new Collection() 334da3cb887Sglarwill ); 335da3cb887Sglarwill 336cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 337da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 338da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 339da3cb887Sglarwill 340cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 341da3cb887Sglarwill 342da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 343da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 344da3cb887Sglarwill 345da3cb887Sglarwill self::assertSame('M', $column->generate($individual, $individual)); 346da3cb887Sglarwill } 347da3cb887Sglarwill} 348