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; 28202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 29da3cb887Sglarwill 30202c018bSGreg Roach#[CoversClass(CensusColumnConditionCanadaMarriedSingle::class)] 31202c018bSGreg Roach#[CoversClass(AbstractCensusColumnCondition::class)] 32da3cb887Sglarwillclass CensusColumnConditionCanadaMarriedSingleTest extends TestCase 33da3cb887Sglarwill{ 34da3cb887Sglarwill public function testNoSpouseFamiliesMale(): void 35da3cb887Sglarwill { 36cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 37da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 38da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection()); 39da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 40da3cb887Sglarwill 41cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 42da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 43da3cb887Sglarwill 44da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 45da3cb887Sglarwill 46da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 47da3cb887Sglarwill } 48da3cb887Sglarwill 49da3cb887Sglarwill public function testNoSpouseFamiliesFemale(): void 50da3cb887Sglarwill { 51cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 52da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 53da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection()); 54da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 55da3cb887Sglarwill 56cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 57da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 58da3cb887Sglarwill 59da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 60da3cb887Sglarwill 61da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 62da3cb887Sglarwill } 63da3cb887Sglarwill 64da3cb887Sglarwill public function testNoFamilyFactsMale(): void 65da3cb887Sglarwill { 66cd94ca66SGreg Roach $family = $this->createMock(Family::class); 67da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 68da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 69da3cb887Sglarwill 70cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 71da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 72da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 73da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 74da3cb887Sglarwill 75cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 76da3cb887Sglarwill 77da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 78da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 79da3cb887Sglarwill 80da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 81da3cb887Sglarwill } 82da3cb887Sglarwill 83da3cb887Sglarwill public function testNoFamilyFactsFemale(): void 84da3cb887Sglarwill { 85cd94ca66SGreg Roach $family = $this->createMock(Family::class); 86da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 87da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 88da3cb887Sglarwill 89cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 90da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 91da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 92da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 93da3cb887Sglarwill 94cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 95da3cb887Sglarwill 96da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 97da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 98da3cb887Sglarwill 99da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 100da3cb887Sglarwill } 101da3cb887Sglarwill 102da3cb887Sglarwill public function testSpouseDeadMale(): void 103da3cb887Sglarwill { 104cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 105da3cb887Sglarwill 106cd94ca66SGreg Roach $spouse = $this->createMock(Individual::class); 107da3cb887Sglarwill $spouse->method('getDeathDate')->willReturn(new Date('1820')); 108da3cb887Sglarwill 109cd94ca66SGreg Roach $family = $this->createMock(Family::class); 110*00ef1d3aSGreg Roach $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 111da3cb887Sglarwill $family->expects(self::exactly(2)) 112da3cb887Sglarwill ->method('facts') 1139aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 114da3cb887Sglarwill ->willReturnOnConsecutiveCalls( 115da3cb887Sglarwill new Collection([$fact]), 116da3cb887Sglarwill new Collection() 117da3cb887Sglarwill ); 118*00ef1d3aSGreg Roach $family->expects($this->once())->method('spouse')->willReturn($spouse); 119da3cb887Sglarwill 120cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 121da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 122da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 123da3cb887Sglarwill 124cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 125da3cb887Sglarwill 126da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 127da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 128da3cb887Sglarwill 129da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 130da3cb887Sglarwill } 131da3cb887Sglarwill 132da3cb887Sglarwill public function testSpouseDeadFemale(): void 133da3cb887Sglarwill { 134cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 135da3cb887Sglarwill 136cd94ca66SGreg Roach $spouse = $this->createMock(Individual::class); 137da3cb887Sglarwill $spouse->method('getDeathDate')->willReturn(new Date('1820')); 138da3cb887Sglarwill 139cd94ca66SGreg Roach $family = $this->createMock(Family::class); 140*00ef1d3aSGreg Roach $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 141da3cb887Sglarwill $family 142da3cb887Sglarwill ->expects(self::exactly(2)) 143da3cb887Sglarwill ->method('facts') 1449aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 145da3cb887Sglarwill ->willReturnOnConsecutiveCalls( 146da3cb887Sglarwill new Collection([$fact]), 147da3cb887Sglarwill new Collection() 148da3cb887Sglarwill ); 149*00ef1d3aSGreg Roach $family->expects($this->once())->method('spouse')->willReturn($spouse); 150da3cb887Sglarwill 151cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 152da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 153da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 154da3cb887Sglarwill 155cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 156da3cb887Sglarwill 157da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 158da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 159da3cb887Sglarwill 160da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 161da3cb887Sglarwill } 162da3cb887Sglarwill 163da3cb887Sglarwill public function testNoFamilyUnmarriedMale(): void 164da3cb887Sglarwill { 165cd94ca66SGreg Roach $family = $this->createMock(Family::class); 166da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 167da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 168da3cb887Sglarwill 169cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 170da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 171da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 172da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 173da3cb887Sglarwill 174cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 175da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 176da3cb887Sglarwill 177da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 178da3cb887Sglarwill 179da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 180da3cb887Sglarwill } 181da3cb887Sglarwill 182da3cb887Sglarwill public function testNoFamilyUnmarriedFemale(): void 183da3cb887Sglarwill { 184cd94ca66SGreg Roach $family = $this->createMock(Family::class); 185da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 186da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 187da3cb887Sglarwill 188cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 189da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 190da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 191da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 192da3cb887Sglarwill 193cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 194da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 195da3cb887Sglarwill 196da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 197da3cb887Sglarwill 198da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 199da3cb887Sglarwill } 200da3cb887Sglarwill 201da3cb887Sglarwill public function testChildMale(): void 202da3cb887Sglarwill { 203cd94ca66SGreg Roach $family = $this->createMock(Family::class); 204da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 205da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 206da3cb887Sglarwill 207cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 208da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 209da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 210da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 211da3cb887Sglarwill 212cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 213da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 214da3cb887Sglarwill 215da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 216da3cb887Sglarwill 217da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 218da3cb887Sglarwill } 219da3cb887Sglarwill 220da3cb887Sglarwill public function testChildFemale(): void 221da3cb887Sglarwill { 222cd94ca66SGreg Roach $family = $this->createMock(Family::class); 223da3cb887Sglarwill $family->method('getMarriageDate')->willReturn(new Date('')); 224da3cb887Sglarwill $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 225da3cb887Sglarwill 226cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 227da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 228da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 229da3cb887Sglarwill $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 230da3cb887Sglarwill 231cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 232da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 233da3cb887Sglarwill 234da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 235da3cb887Sglarwill 236da3cb887Sglarwill self::assertSame('S', $column->generate($individual, $individual)); 237da3cb887Sglarwill } 238da3cb887Sglarwill 239da3cb887Sglarwill public function testDivorcedMale(): void 240da3cb887Sglarwill { 241cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 242da3cb887Sglarwill 243cd94ca66SGreg Roach $family = $this->createMock(Family::class); 244*00ef1d3aSGreg Roach $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 245da3cb887Sglarwill $family 246da3cb887Sglarwill ->expects(self::exactly(2)) 247da3cb887Sglarwill ->method('facts') 2489aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 2499aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 250da3cb887Sglarwill new Collection([$fact]), 251da3cb887Sglarwill new Collection([$fact]) 252da3cb887Sglarwill ); 253da3cb887Sglarwill 254cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 255da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 256da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 257da3cb887Sglarwill 258cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 259da3cb887Sglarwill 260da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 261da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 262da3cb887Sglarwill 263da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 264da3cb887Sglarwill } 265da3cb887Sglarwill 266da3cb887Sglarwill public function testDivorcedFemale(): void 267da3cb887Sglarwill { 268cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 269da3cb887Sglarwill 270cd94ca66SGreg Roach $family = $this->createMock(Family::class); 271*00ef1d3aSGreg Roach $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 272da3cb887Sglarwill $family 273da3cb887Sglarwill ->expects(self::exactly(2)) 274da3cb887Sglarwill ->method('facts') 2759aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 2769aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 277da3cb887Sglarwill new Collection([$fact]), 278da3cb887Sglarwill new Collection([$fact]) 279da3cb887Sglarwill ); 280da3cb887Sglarwill 281cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 282da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 283da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 284da3cb887Sglarwill 285cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 286da3cb887Sglarwill 287da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 288da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 289da3cb887Sglarwill 290da3cb887Sglarwill self::assertSame('', $column->generate($individual, $individual)); 291da3cb887Sglarwill } 292da3cb887Sglarwill 293da3cb887Sglarwill public function testMarriedMale(): void 294da3cb887Sglarwill { 295cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 296da3cb887Sglarwill 297cd94ca66SGreg Roach $family = $this->createMock(Family::class); 298*00ef1d3aSGreg Roach $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 299da3cb887Sglarwill $family 300da3cb887Sglarwill ->expects(self::exactly(2)) 301da3cb887Sglarwill ->method('facts') 3029aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 3039aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 304da3cb887Sglarwill new Collection([$fact]), 305da3cb887Sglarwill new Collection() 306da3cb887Sglarwill ); 307da3cb887Sglarwill 308cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 309da3cb887Sglarwill $individual->method('sex')->willReturn('M'); 310da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 311da3cb887Sglarwill 312cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 313da3cb887Sglarwill 314da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 315da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 316da3cb887Sglarwill 317da3cb887Sglarwill self::assertSame('M', $column->generate($individual, $individual)); 318da3cb887Sglarwill } 319da3cb887Sglarwill 320da3cb887Sglarwill public function testMarriedFemale(): void 321da3cb887Sglarwill { 322cd94ca66SGreg Roach $fact = $this->createMock(Fact::class); 323da3cb887Sglarwill 324cd94ca66SGreg Roach $family = $this->createMock(Family::class); 325*00ef1d3aSGreg Roach $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date('')); 326da3cb887Sglarwill $family 327da3cb887Sglarwill ->expects(self::exactly(2)) 328da3cb887Sglarwill ->method('facts') 3299aef375dSGreg Roach ->with(self::withConsecutive([['MARR'], ['DIV']])) 3309aef375dSGreg Roach ->willReturnOnConsecutiveCalls( 331da3cb887Sglarwill new Collection([$fact]), 332da3cb887Sglarwill new Collection() 333da3cb887Sglarwill ); 334da3cb887Sglarwill 335cd94ca66SGreg Roach $individual = $this->createMock(Individual::class); 336da3cb887Sglarwill $individual->method('sex')->willReturn('F'); 337da3cb887Sglarwill $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 338da3cb887Sglarwill 339cd94ca66SGreg Roach $census = $this->createMock(CensusInterface::class); 340da3cb887Sglarwill 341da3cb887Sglarwill $column = new CensusColumnConditionCanadaMarriedSingle($census, '', ''); 342da3cb887Sglarwill $census->method('censusDate')->willReturn('30 JUN 1830'); 343da3cb887Sglarwill 344da3cb887Sglarwill self::assertSame('M', $column->generate($individual, $individual)); 345da3cb887Sglarwill } 346da3cb887Sglarwill} 347