xref: /webtrees/tests/app/Census/CensusColumnChildrenLivingTest.php (revision 1270d2767576ed4a83917769b0ee3613e3b010bf)
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\Family;
24use Fisharebest\Webtrees\Individual;
25use Fisharebest\Webtrees\TestCase;
26use Illuminate\Support\Collection;
27use PHPUnit\Framework\Attributes\CoversClass;
28
29#[CoversClass(CensusColumnChildrenLiving::class)]
30#[CoversClass(AbstractCensusColumn::class)]
31class CensusColumnChildrenLivingTest extends TestCase
32{
33    public function testMale(): void
34    {
35        $individual = $this->createMock(Individual::class);
36        $individual->method('sex')->willReturn('M');
37        $individual->method('spouseFamilies')->willReturn(new Collection([]));
38
39        $census = $this->createMock(CensusInterface::class);
40
41        $column = new CensusColumnChildrenLiving($census, '', '');
42
43        self::assertSame('', $column->generate($individual, $individual));
44    }
45
46    public function testCountChildren(): void
47    {
48        // Stillborn
49        $child1 = $this->createMock(Individual::class);
50        $child1->method('getBirthDate')->willReturn(new Date('01 FEB 1904'));
51        $child1->method('getDeathDate')->willReturn(new Date('01 FEB 1904'));
52
53        // Died after census
54        $child2 = $this->createMock(Individual::class);
55        $child2->method('getBirthDate')->willReturn(new Date('02 FEB 1904'));
56        $child2->method('getDeathDate')->willReturn(new Date('20 DEC 1912'));
57
58        // Died before census
59        $child3 = $this->createMock(Individual::class);
60        $child3->method('getBirthDate')->willReturn(new Date('02 FEB 1904'));
61        $child3->method('getDeathDate')->willReturn(new Date('20 DEC 1910'));
62
63        // Still living
64        $child4 = $this->createMock(Individual::class);
65        $child4->method('getBirthDate')->willReturn(new Date('01 FEB 1904'));
66        $child4->method('getDeathDate')->willReturn(new Date(''));
67
68        $family = $this->createMock(Family::class);
69        $family->method('children')->willReturn(new Collection([
70            $child1,
71            $child2,
72            $child3,
73            $child4,
74        ]));
75
76        $individual = $this->createMock(Individual::class);
77        $individual->method('sex')->willReturn('F');
78        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
79
80        $census = $this->createMock(CensusInterface::class);
81        $census->method('censusDate')->willReturn('30 MAR 1911');
82
83        $column = new CensusColumnChildrenLiving($census, '', '');
84
85        self::assertSame('2', $column->generate($individual, $individual));
86    }
87}
88