xref: /webtrees/tests/app/Census/CensusColumnConditionUsTest.php (revision 00ef1d3af59aba99c1ae5c92c7e655525c97797b)
181d1be7aSGreg Roach<?php
23976b470SGreg Roach
381d1be7aSGreg Roach/**
481d1be7aSGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://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;
28202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
2981d1be7aSGreg Roach
30202c018bSGreg Roach#[CoversClass(CensusColumnConditionUs::class)]
31202c018bSGreg Roach#[CoversClass(AbstractCensusColumnCondition::class)]
323cfcc809SGreg Roachclass CensusColumnConditionUsTest extends TestCase
33c1010edaSGreg Roach{
349b802b22SGreg Roach    public function testNoSpouseFamiliesMale(): void
35c1010edaSGreg Roach    {
36cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
370ecdbde6SGreg Roach        $individual->method('sex')->willReturn('M');
380ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection());
390ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
4081d1be7aSGreg Roach
41cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
420ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
4381d1be7aSGreg Roach
4481d1be7aSGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
4581d1be7aSGreg Roach
465e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
4781d1be7aSGreg Roach    }
4881d1be7aSGreg Roach
499b802b22SGreg Roach    public function testNoSpouseFamiliesFemale(): void
50c1010edaSGreg Roach    {
51cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
520ecdbde6SGreg Roach        $individual->method('sex')->willReturn('F');
530ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection());
540ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
5500225b98SGreg Roach
56cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
570ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
5800225b98SGreg Roach
5900225b98SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
6000225b98SGreg Roach
615e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
6200225b98SGreg Roach    }
6300225b98SGreg Roach
649b802b22SGreg Roach    public function testNoFamilyFactsMale(): void
65c1010edaSGreg Roach    {
66cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
670ecdbde6SGreg Roach        $family->method('getMarriageDate')->willReturn(new Date(''));
680ecdbde6SGreg Roach        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
6981d1be7aSGreg Roach
70cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
710ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
720ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
730ecdbde6SGreg Roach        $individual->method('sex')->willReturn('M');
7481d1be7aSGreg Roach
75cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
7681d1be7aSGreg Roach
7781d1be7aSGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
780ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
7981d1be7aSGreg Roach
805e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
8181d1be7aSGreg Roach    }
8281d1be7aSGreg Roach
839b802b22SGreg Roach    public function testNoFamilyFactsFemale(): void
84c1010edaSGreg Roach    {
85cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
860ecdbde6SGreg Roach        $family->method('getMarriageDate')->willReturn(new Date(''));
870ecdbde6SGreg Roach        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
8881d1be7aSGreg Roach
89cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
900ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
910ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
920ecdbde6SGreg Roach        $individual->method('sex')->willReturn('F');
9381d1be7aSGreg Roach
94cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
9581d1be7aSGreg Roach
9681d1be7aSGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
970ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
9881d1be7aSGreg Roach
995e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
10000225b98SGreg Roach    }
10100225b98SGreg Roach
1029b802b22SGreg Roach    public function testSpouseDeadMale(): void
103c1010edaSGreg Roach    {
104cd94ca66SGreg Roach        $fact = $this->createMock(Fact::class);
1052a6fda60SGreg Roach
106cd94ca66SGreg Roach        $spouse = $this->createMock(Individual::class);
1070ecdbde6SGreg Roach        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
108e76c0cf0SGreg Roach
109cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
110*00ef1d3aSGreg Roach        $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date(''));
111109b3e30SGreg Roach        $family->expects(self::exactly(2))
112109b3e30SGreg Roach            ->method('facts')
1139aef375dSGreg Roach            ->with(self::withConsecutive([['MARR'], ['DIV']]))
114109b3e30SGreg Roach            ->willReturnOnConsecutiveCalls(
115109b3e30SGreg Roach                new Collection([$fact]),
116109b3e30SGreg Roach                new Collection()
117109b3e30SGreg Roach            );
118*00ef1d3aSGreg Roach        $family->expects($this->once())->method('spouse')->willReturn($spouse);
119e76c0cf0SGreg Roach
120cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1210ecdbde6SGreg Roach        $individual->method('sex')->willReturn('M');
1220ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
123e76c0cf0SGreg Roach
124cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
125e76c0cf0SGreg Roach
126e76c0cf0SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
1270ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
128e76c0cf0SGreg Roach
1295e933c21SGreg Roach        self::assertSame('W', $column->generate($individual, $individual));
130e76c0cf0SGreg Roach    }
131e76c0cf0SGreg Roach
1329b802b22SGreg Roach    public function testSpouseDeadFemale(): void
133c1010edaSGreg Roach    {
134cd94ca66SGreg Roach        $fact = $this->createMock(Fact::class);
1352a6fda60SGreg Roach
136cd94ca66SGreg Roach        $spouse = $this->createMock(Individual::class);
1370ecdbde6SGreg Roach        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
138e76c0cf0SGreg Roach
139cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
140*00ef1d3aSGreg Roach        $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date(''));
141109b3e30SGreg Roach        $family
142109b3e30SGreg Roach            ->expects(self::exactly(2))
143109b3e30SGreg Roach            ->method('facts')
1449aef375dSGreg Roach            ->with(self::withConsecutive([['MARR'], ['DIV']]))
145109b3e30SGreg Roach            ->willReturnOnConsecutiveCalls(
146109b3e30SGreg Roach                new Collection([$fact]),
147109b3e30SGreg Roach                new Collection()
148109b3e30SGreg Roach            );
149*00ef1d3aSGreg Roach        $family->expects($this->once())->method('spouse')->willReturn($spouse);
150e76c0cf0SGreg Roach
151cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1520ecdbde6SGreg Roach        $individual->method('sex')->willReturn('F');
1530ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
154e76c0cf0SGreg Roach
155cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
156e76c0cf0SGreg Roach
157e76c0cf0SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
1580ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
159e76c0cf0SGreg Roach
1605e933c21SGreg Roach        self::assertSame('W', $column->generate($individual, $individual));
161e76c0cf0SGreg Roach    }
162e76c0cf0SGreg Roach
1639b802b22SGreg Roach    public function testNoFamilyUnmarriedMale(): void
164c1010edaSGreg Roach    {
165cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
1660ecdbde6SGreg Roach        $family->method('getMarriageDate')->willReturn(new Date(''));
1670ecdbde6SGreg Roach        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
16800225b98SGreg Roach
169cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1700ecdbde6SGreg Roach        $individual->method('sex')->willReturn('M');
1710ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
1720ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
17300225b98SGreg Roach
174cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
1750ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
17600225b98SGreg Roach
17700225b98SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
17800225b98SGreg Roach
1795e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
18081d1be7aSGreg Roach    }
18181d1be7aSGreg Roach
1829b802b22SGreg Roach    public function testNoFamilyUnmarriedFemale(): void
183c1010edaSGreg Roach    {
184cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
1850ecdbde6SGreg Roach        $family->method('getMarriageDate')->willReturn(new Date(''));
1860ecdbde6SGreg Roach        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
18700225b98SGreg Roach
188cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
1890ecdbde6SGreg Roach        $individual->method('sex')->willReturn('F');
1900ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
1910ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
19200225b98SGreg Roach
193cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
1940ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
19500225b98SGreg Roach
19600225b98SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
19700225b98SGreg Roach
1985e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
19900225b98SGreg Roach    }
20000225b98SGreg Roach
2019b802b22SGreg Roach    public function testChildMale(): void
202c1010edaSGreg Roach    {
203cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
2040ecdbde6SGreg Roach        $family->method('getMarriageDate')->willReturn(new Date(''));
2050ecdbde6SGreg Roach        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
20600225b98SGreg Roach
207cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
2080ecdbde6SGreg Roach        $individual->method('sex')->willReturn('M');
2090ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
2100ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
21100225b98SGreg Roach
212cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
2130ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
21400225b98SGreg Roach
21500225b98SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
21600225b98SGreg Roach
2175e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
21800225b98SGreg Roach    }
21900225b98SGreg Roach
2209b802b22SGreg Roach    public function testChildFemale(): void
221c1010edaSGreg Roach    {
222cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
2230ecdbde6SGreg Roach        $family->method('getMarriageDate')->willReturn(new Date(''));
2240ecdbde6SGreg Roach        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
22500225b98SGreg Roach
226cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
2270ecdbde6SGreg Roach        $individual->method('sex')->willReturn('F');
2280ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
2290ecdbde6SGreg Roach        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
23000225b98SGreg Roach
231cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
2320ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
23300225b98SGreg Roach
23400225b98SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
23500225b98SGreg Roach
2365e933c21SGreg Roach        self::assertSame('S', $column->generate($individual, $individual));
23700225b98SGreg Roach    }
23800225b98SGreg Roach
2399b802b22SGreg Roach    public function testDivorcedMale(): void
240c1010edaSGreg Roach    {
241cd94ca66SGreg Roach        $fact = $this->createMock(Fact::class);
24281d1be7aSGreg Roach
243cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
244*00ef1d3aSGreg Roach        $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date(''));
245109b3e30SGreg Roach        $family
246109b3e30SGreg Roach            ->expects(self::exactly(2))
247109b3e30SGreg Roach            ->method('facts')
2489aef375dSGreg Roach            ->with(self::withConsecutive([['MARR'], ['DIV']]))
2499aef375dSGreg Roach            ->willReturnOnConsecutiveCalls(
250109b3e30SGreg Roach                new Collection([$fact]),
251109b3e30SGreg Roach                new Collection([$fact])
252109b3e30SGreg Roach            );
25381d1be7aSGreg Roach
254cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
2550ecdbde6SGreg Roach        $individual->method('sex')->willReturn('M');
2560ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
25700225b98SGreg Roach
258cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
25900225b98SGreg Roach
26000225b98SGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
2610ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
26200225b98SGreg Roach
2635e933c21SGreg Roach        self::assertSame('D', $column->generate($individual, $individual));
26400225b98SGreg Roach    }
26500225b98SGreg Roach
2669b802b22SGreg Roach    public function testDivorcedFemale(): void
267c1010edaSGreg Roach    {
268cd94ca66SGreg Roach        $fact = $this->createMock(Fact::class);
26900225b98SGreg Roach
270cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
271*00ef1d3aSGreg Roach        $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date(''));
272109b3e30SGreg Roach        $family
273109b3e30SGreg Roach            ->expects(self::exactly(2))
274109b3e30SGreg Roach            ->method('facts')
2759aef375dSGreg Roach            ->with(self::withConsecutive([['MARR'], ['DIV']]))
2769aef375dSGreg Roach            ->willReturnOnConsecutiveCalls(
277109b3e30SGreg Roach                new Collection([$fact]),
278109b3e30SGreg Roach                new Collection([$fact])
279109b3e30SGreg Roach            );
28000225b98SGreg Roach
281cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
2820ecdbde6SGreg Roach        $individual->method('sex')->willReturn('F');
2830ecdbde6SGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
28481d1be7aSGreg Roach
285cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
28681d1be7aSGreg Roach
28781d1be7aSGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
2880ecdbde6SGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
28981d1be7aSGreg Roach
2905e933c21SGreg Roach        self::assertSame('D', $column->generate($individual, $individual));
29181d1be7aSGreg Roach    }
292b72623feSGreg Roach
293b72623feSGreg Roach    public function testMarriedMale(): void
294b72623feSGreg Roach    {
295cd94ca66SGreg Roach        $fact = $this->createMock(Fact::class);
296b72623feSGreg Roach
297cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
298*00ef1d3aSGreg Roach        $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date(''));
299b72623feSGreg Roach        $family
300b72623feSGreg Roach            ->expects(self::exactly(2))
301b72623feSGreg Roach            ->method('facts')
3029aef375dSGreg Roach            ->with(self::withConsecutive([['MARR'], ['DIV']]))
3039aef375dSGreg Roach            ->willReturnOnConsecutiveCalls(
304b72623feSGreg Roach                new Collection([$fact]),
305b72623feSGreg Roach                new Collection()
306b72623feSGreg Roach            );
307b72623feSGreg Roach
308cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
309b72623feSGreg Roach        $individual->method('sex')->willReturn('M');
310b72623feSGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
311b72623feSGreg Roach
312cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
313b72623feSGreg Roach
314b72623feSGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
315b72623feSGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
316b72623feSGreg Roach
317b72623feSGreg Roach        self::assertSame('M', $column->generate($individual, $individual));
318b72623feSGreg Roach    }
319b72623feSGreg Roach
320b72623feSGreg Roach    public function testMarriedFemale(): void
321b72623feSGreg Roach    {
322cd94ca66SGreg Roach        $fact = $this->createMock(Fact::class);
323b72623feSGreg Roach
324cd94ca66SGreg Roach        $family = $this->createMock(Family::class);
325*00ef1d3aSGreg Roach        $family->expects($this->once())->method('getMarriageDate')->willReturn(new Date(''));
326b72623feSGreg Roach        $family
327b72623feSGreg Roach            ->expects(self::exactly(2))
328b72623feSGreg Roach            ->method('facts')
3299aef375dSGreg Roach            ->with(self::withConsecutive([['MARR'], ['DIV']]))
3309aef375dSGreg Roach            ->willReturnOnConsecutiveCalls(
331b72623feSGreg Roach                new Collection([$fact]),
332b72623feSGreg Roach                new Collection()
333b72623feSGreg Roach            );
334b72623feSGreg Roach
335cd94ca66SGreg Roach        $individual = $this->createMock(Individual::class);
336b72623feSGreg Roach        $individual->method('sex')->willReturn('F');
337b72623feSGreg Roach        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
338b72623feSGreg Roach
339cd94ca66SGreg Roach        $census = $this->createMock(CensusInterface::class);
340b72623feSGreg Roach
341b72623feSGreg Roach        $column = new CensusColumnConditionUs($census, '', '');
342b72623feSGreg Roach        $census->method('censusDate')->willReturn('30 JUN 1830');
343b72623feSGreg Roach
344b72623feSGreg Roach        self::assertSame('M', $column->generate($individual, $individual));
345b72623feSGreg Roach    }
34681d1be7aSGreg Roach}
347