181d1be7aSGreg Roach<?php 23976b470SGreg Roach 381d1be7aSGreg Roach/** 481d1be7aSGreg Roach * webtrees: online genealogy 55e933c21SGreg Roach * Copyright (C) 2020 webtrees development team 681d1be7aSGreg Roach * This program is free software: you can redistribute it and/or modify 781d1be7aSGreg Roach * it under the terms of the GNU General Public License as published by 881d1be7aSGreg Roach * the Free Software Foundation, either version 3 of the License, or 981d1be7aSGreg Roach * (at your option) any later version. 1081d1be7aSGreg Roach * This program is distributed in the hope that it will be useful, 1181d1be7aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1281d1be7aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1381d1be7aSGreg Roach * GNU General Public License for more details. 1481d1be7aSGreg Roach * You should have received a copy of the GNU General Public License 1581d1be7aSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1681d1be7aSGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2081d1be7aSGreg Roachnamespace Fisharebest\Webtrees\Census; 2181d1be7aSGreg Roach 2281d1be7aSGreg Roachuse Fisharebest\Webtrees\Date; 23ddf438a5SGreg Roachuse Fisharebest\Webtrees\Fact; 24ddf438a5SGreg Roachuse Fisharebest\Webtrees\Family; 25ddf438a5SGreg Roachuse Fisharebest\Webtrees\Individual; 263cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase; 2739ca88baSGreg Roachuse Illuminate\Support\Collection; 2881d1be7aSGreg Roach 2981d1be7aSGreg Roach/** 3081d1be7aSGreg Roach * Test harness for the class CensusColumnConditionUs 3181d1be7aSGreg Roach */ 323cfcc809SGreg Roachclass CensusColumnConditionUsTest extends TestCase 33c1010edaSGreg Roach{ 3481d1be7aSGreg Roach /** 3515d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 3615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 3752348eb8SGreg Roach * 3852348eb8SGreg Roach * @return void 3981d1be7aSGreg Roach */ 409b802b22SGreg Roach public function testNoSpouseFamiliesMale(): void 41c1010edaSGreg Roach { 425e933c21SGreg Roach $individual = self::createMock(Individual::class); 430ecdbde6SGreg Roach $individual->method('sex')->willReturn('M'); 440ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection()); 450ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 4681d1be7aSGreg Roach 475e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 480ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 4981d1be7aSGreg Roach 5081d1be7aSGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 5181d1be7aSGreg Roach 525e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 5381d1be7aSGreg Roach } 5481d1be7aSGreg Roach 5581d1be7aSGreg Roach /** 5615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 5715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 5852348eb8SGreg Roach * 5952348eb8SGreg Roach * @return void 6081d1be7aSGreg Roach */ 619b802b22SGreg Roach public function testNoSpouseFamiliesFemale(): void 62c1010edaSGreg Roach { 635e933c21SGreg Roach $individual = self::createMock(Individual::class); 640ecdbde6SGreg Roach $individual->method('sex')->willReturn('F'); 650ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection()); 660ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 6700225b98SGreg Roach 685e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 690ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 7000225b98SGreg Roach 7100225b98SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 7200225b98SGreg Roach 735e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 7400225b98SGreg Roach } 7500225b98SGreg Roach 7600225b98SGreg Roach /** 7715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 7815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 7952348eb8SGreg Roach * 8052348eb8SGreg Roach * @return void 8100225b98SGreg Roach */ 829b802b22SGreg Roach public function testNoFamilyFactsMale(): void 83c1010edaSGreg Roach { 845e933c21SGreg Roach $family = self::createMock(Family::class); 850ecdbde6SGreg Roach $family->method('getMarriageDate')->willReturn(new Date('')); 860ecdbde6SGreg Roach $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 8781d1be7aSGreg Roach 885e933c21SGreg Roach $individual = self::createMock(Individual::class); 890ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 900ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 910ecdbde6SGreg Roach $individual->method('sex')->willReturn('M'); 9281d1be7aSGreg Roach 935e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 9481d1be7aSGreg Roach 9581d1be7aSGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 960ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 9781d1be7aSGreg Roach 985e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 9981d1be7aSGreg Roach } 10081d1be7aSGreg Roach 10181d1be7aSGreg Roach /** 10215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 10315d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 10452348eb8SGreg Roach * 10552348eb8SGreg Roach * @return void 10681d1be7aSGreg Roach */ 1079b802b22SGreg Roach public function testNoFamilyFactsFemale(): void 108c1010edaSGreg Roach { 1095e933c21SGreg Roach $family = self::createMock(Family::class); 1100ecdbde6SGreg Roach $family->method('getMarriageDate')->willReturn(new Date('')); 1110ecdbde6SGreg Roach $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 11281d1be7aSGreg Roach 1135e933c21SGreg Roach $individual = self::createMock(Individual::class); 1140ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 1150ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 1160ecdbde6SGreg Roach $individual->method('sex')->willReturn('F'); 11781d1be7aSGreg Roach 1185e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 11981d1be7aSGreg Roach 12081d1be7aSGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 1210ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 12281d1be7aSGreg Roach 1235e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 12400225b98SGreg Roach } 12500225b98SGreg Roach 12600225b98SGreg Roach /** 12715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 12815d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 12952348eb8SGreg Roach * 13052348eb8SGreg Roach * @return void 13100225b98SGreg Roach */ 1329b802b22SGreg Roach public function testSpouseDeadMale(): void 133c1010edaSGreg Roach { 1345e933c21SGreg Roach $fact = self::createMock(Fact::class); 1352a6fda60SGreg Roach 1365e933c21SGreg Roach $spouse = self::createMock(Individual::class); 1370ecdbde6SGreg Roach $spouse->method('getDeathDate')->willReturn(new Date('1820')); 138e76c0cf0SGreg Roach 1395e933c21SGreg Roach $family = self::createMock(Family::class); 140109b3e30SGreg Roach $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 141109b3e30SGreg Roach $family->expects(self::exactly(2)) 142109b3e30SGreg Roach ->method('facts') 143109b3e30SGreg Roach ->withConsecutive( 144109b3e30SGreg Roach [['MARR']], 145*2e84ab20SGreg Roach [['DIV']] 146*2e84ab20SGreg Roach ) 147109b3e30SGreg Roach ->willReturnOnConsecutiveCalls( 148109b3e30SGreg Roach new Collection([$fact]), 149109b3e30SGreg Roach new Collection() 150109b3e30SGreg Roach ); 151109b3e30SGreg Roach $family->expects(self::once())->method('spouse')->willReturn($spouse); 152e76c0cf0SGreg Roach 1535e933c21SGreg Roach $individual = self::createMock(Individual::class); 1540ecdbde6SGreg Roach $individual->method('sex')->willReturn('M'); 1550ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 156e76c0cf0SGreg Roach 1575e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 158e76c0cf0SGreg Roach 159e76c0cf0SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 1600ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 161e76c0cf0SGreg Roach 1625e933c21SGreg Roach self::assertSame('W', $column->generate($individual, $individual)); 163e76c0cf0SGreg Roach } 164e76c0cf0SGreg Roach 165e76c0cf0SGreg Roach /** 16615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 16715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 16852348eb8SGreg Roach * 16952348eb8SGreg Roach * @return void 170e76c0cf0SGreg Roach */ 1719b802b22SGreg Roach public function testSpouseDeadFemale(): void 172c1010edaSGreg Roach { 1735e933c21SGreg Roach $fact = self::createMock(Fact::class); 1742a6fda60SGreg Roach 1755e933c21SGreg Roach $spouse = self::createMock(Individual::class); 1760ecdbde6SGreg Roach $spouse->method('getDeathDate')->willReturn(new Date('1820')); 177e76c0cf0SGreg Roach 1785e933c21SGreg Roach $family = self::createMock(Family::class); 179109b3e30SGreg Roach $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 180109b3e30SGreg Roach $family 181109b3e30SGreg Roach ->expects(self::exactly(2)) 182109b3e30SGreg Roach ->method('facts') 183109b3e30SGreg Roach ->withConsecutive( 184109b3e30SGreg Roach [['MARR']], 185109b3e30SGreg Roach [['DIV']] 186109b3e30SGreg Roach ) 187109b3e30SGreg Roach ->willReturnOnConsecutiveCalls( 188109b3e30SGreg Roach new Collection([$fact]), 189109b3e30SGreg Roach new Collection() 190109b3e30SGreg Roach ); 191109b3e30SGreg Roach $family->expects(self::once())->method('spouse')->willReturn($spouse); 192e76c0cf0SGreg Roach 1935e933c21SGreg Roach $individual = self::createMock(Individual::class); 1940ecdbde6SGreg Roach $individual->method('sex')->willReturn('F'); 1950ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 196e76c0cf0SGreg Roach 1975e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 198e76c0cf0SGreg Roach 199e76c0cf0SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 2000ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 201e76c0cf0SGreg Roach 2025e933c21SGreg Roach self::assertSame('W', $column->generate($individual, $individual)); 203e76c0cf0SGreg Roach } 204e76c0cf0SGreg Roach 205e76c0cf0SGreg Roach /** 20615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 20715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 20852348eb8SGreg Roach * 20952348eb8SGreg Roach * @return void 210e76c0cf0SGreg Roach */ 2119b802b22SGreg Roach public function testNoFamilyUnmarriedMale(): void 212c1010edaSGreg Roach { 2135e933c21SGreg Roach $family = self::createMock(Family::class); 2140ecdbde6SGreg Roach $family->method('getMarriageDate')->willReturn(new Date('')); 2150ecdbde6SGreg Roach $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 21600225b98SGreg Roach 2175e933c21SGreg Roach $individual = self::createMock(Individual::class); 2180ecdbde6SGreg Roach $individual->method('sex')->willReturn('M'); 2190ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 2200ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 22100225b98SGreg Roach 2225e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 2230ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 22400225b98SGreg Roach 22500225b98SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 22600225b98SGreg Roach 2275e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 22881d1be7aSGreg Roach } 22981d1be7aSGreg Roach 23081d1be7aSGreg Roach /** 23115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 23215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 23352348eb8SGreg Roach * 23452348eb8SGreg Roach * @return void 23581d1be7aSGreg Roach */ 2369b802b22SGreg Roach public function testNoFamilyUnmarriedFemale(): void 237c1010edaSGreg Roach { 2385e933c21SGreg Roach $family = self::createMock(Family::class); 2390ecdbde6SGreg Roach $family->method('getMarriageDate')->willReturn(new Date('')); 2400ecdbde6SGreg Roach $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 24100225b98SGreg Roach 2425e933c21SGreg Roach $individual = self::createMock(Individual::class); 2430ecdbde6SGreg Roach $individual->method('sex')->willReturn('F'); 2440ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 2450ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800')); 24600225b98SGreg Roach 2475e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 2480ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 24900225b98SGreg Roach 25000225b98SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 25100225b98SGreg Roach 2525e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 25300225b98SGreg Roach } 25400225b98SGreg Roach 25500225b98SGreg Roach /** 25615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 25715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 25852348eb8SGreg Roach * 25952348eb8SGreg Roach * @return void 26000225b98SGreg Roach */ 2619b802b22SGreg Roach public function testChildMale(): void 262c1010edaSGreg Roach { 2635e933c21SGreg Roach $family = self::createMock(Family::class); 2640ecdbde6SGreg Roach $family->method('getMarriageDate')->willReturn(new Date('')); 2650ecdbde6SGreg Roach $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 26600225b98SGreg Roach 2675e933c21SGreg Roach $individual = self::createMock(Individual::class); 2680ecdbde6SGreg Roach $individual->method('sex')->willReturn('M'); 2690ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 2700ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 27100225b98SGreg Roach 2725e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 2730ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 27400225b98SGreg Roach 27500225b98SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 27600225b98SGreg Roach 2775e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 27800225b98SGreg Roach } 27900225b98SGreg Roach 28000225b98SGreg Roach /** 28115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 28215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 28352348eb8SGreg Roach * 28452348eb8SGreg Roach * @return void 28500225b98SGreg Roach */ 2869b802b22SGreg Roach public function testChildFemale(): void 287c1010edaSGreg Roach { 2885e933c21SGreg Roach $family = self::createMock(Family::class); 2890ecdbde6SGreg Roach $family->method('getMarriageDate')->willReturn(new Date('')); 2900ecdbde6SGreg Roach $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 29100225b98SGreg Roach 2925e933c21SGreg Roach $individual = self::createMock(Individual::class); 2930ecdbde6SGreg Roach $individual->method('sex')->willReturn('F'); 2940ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 2950ecdbde6SGreg Roach $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820')); 29600225b98SGreg Roach 2975e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 2980ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 29900225b98SGreg Roach 30000225b98SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 30100225b98SGreg Roach 3025e933c21SGreg Roach self::assertSame('S', $column->generate($individual, $individual)); 30300225b98SGreg Roach } 30400225b98SGreg Roach 30500225b98SGreg Roach /** 30615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 30715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 30852348eb8SGreg Roach * 30952348eb8SGreg Roach * @return void 31000225b98SGreg Roach */ 3119b802b22SGreg Roach public function testDivorcedMale(): void 312c1010edaSGreg Roach { 3135e933c21SGreg Roach $fact = self::createMock(Fact::class); 31481d1be7aSGreg Roach 3155e933c21SGreg Roach $family = self::createMock(Family::class); 316109b3e30SGreg Roach $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 317109b3e30SGreg Roach $family 318109b3e30SGreg Roach ->expects(self::exactly(2)) 319109b3e30SGreg Roach ->method('facts') 320109b3e30SGreg Roach ->withConsecutive( 321109b3e30SGreg Roach [['MARR']], 322109b3e30SGreg Roach [['DIV']] 323109b3e30SGreg Roach )->willReturnOnConsecutiveCalls( 324109b3e30SGreg Roach new Collection([$fact]), 325109b3e30SGreg Roach new Collection([$fact]) 326109b3e30SGreg Roach ); 32781d1be7aSGreg Roach 3285e933c21SGreg Roach $individual = self::createMock(Individual::class); 3290ecdbde6SGreg Roach $individual->method('sex')->willReturn('M'); 3300ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 33100225b98SGreg Roach 3325e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 33300225b98SGreg Roach 33400225b98SGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 3350ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 33600225b98SGreg Roach 3375e933c21SGreg Roach self::assertSame('D', $column->generate($individual, $individual)); 33800225b98SGreg Roach } 33900225b98SGreg Roach 34000225b98SGreg Roach /** 34115d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs 34215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 34352348eb8SGreg Roach * 34452348eb8SGreg Roach * @return void 34500225b98SGreg Roach */ 3469b802b22SGreg Roach public function testDivorcedFemale(): void 347c1010edaSGreg Roach { 3485e933c21SGreg Roach $fact = self::createMock(Fact::class); 34900225b98SGreg Roach 3505e933c21SGreg Roach $family = self::createMock(Family::class); 351109b3e30SGreg Roach $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date('')); 352109b3e30SGreg Roach $family 353109b3e30SGreg Roach ->expects(self::exactly(2)) 354109b3e30SGreg Roach ->method('facts') 355109b3e30SGreg Roach ->withConsecutive( 356109b3e30SGreg Roach [['MARR']], 357109b3e30SGreg Roach [['DIV']] 358109b3e30SGreg Roach )->willReturnOnConsecutiveCalls( 359109b3e30SGreg Roach new Collection([$fact]), 360109b3e30SGreg Roach new Collection([$fact]) 361109b3e30SGreg Roach ); 36200225b98SGreg Roach 3635e933c21SGreg Roach $individual = self::createMock(Individual::class); 3640ecdbde6SGreg Roach $individual->method('sex')->willReturn('F'); 3650ecdbde6SGreg Roach $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 36681d1be7aSGreg Roach 3675e933c21SGreg Roach $census = self::createMock(CensusInterface::class); 36881d1be7aSGreg Roach 36981d1be7aSGreg Roach $column = new CensusColumnConditionUs($census, '', ''); 3700ecdbde6SGreg Roach $census->method('censusDate')->willReturn('30 JUN 1830'); 37181d1be7aSGreg Roach 3725e933c21SGreg Roach self::assertSame('D', $column->generate($individual, $individual)); 37381d1be7aSGreg Roach } 37481d1be7aSGreg Roach} 375