xref: /webtrees/tests/app/Census/CensusColumnChildrenDiedTest.php (revision 2917771c25c65897723561cdcefe19f90d29a925)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://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;
27
28/**
29 * Test harness for the class CensusColumnChildrenDied
30 */
31class CensusColumnChildrenDiedTest extends TestCase
32{
33    /**
34     * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenDied
35     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
36     *
37     * @return void
38     */
39    public function testMale(): void
40    {
41        $individual = $this->createMock(Individual::class);
42        $individual->method('sex')->willReturn('M');
43
44        $census = $this->createMock(CensusInterface::class);
45
46        $column = new CensusColumnChildrenDied($census, '', '');
47
48        $this->assertSame('', $column->generate($individual, $individual));
49    }
50
51    /**
52     * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenDied
53     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
54     *
55     * @return void
56     */
57    public function testCountChildren(): void
58    {
59        // Stillborn
60        $child1 = $this->createMock(Individual::class);
61        $child1->method('getBirthDate')->willReturn(new Date('01 FEB 1904'));
62        $child1->method('getDeathDate')->willReturn(new Date('01 FEB 1904'));
63
64        // Died after census
65        $child2 = $this->createMock(Individual::class);
66        $child2->method('getBirthDate')->willReturn(new Date('02 FEB 1904'));
67        $child2->method('getDeathDate')->willReturn(new Date('20 DEC 1912'));
68
69        // Died before census
70        $child3 = $this->createMock(Individual::class);
71        $child3->method('getBirthDate')->willReturn(new Date('02 FEB 1904'));
72        $child3->method('getDeathDate')->willReturn(new Date('20 DEC 1910'));
73
74        // Still living
75        $child4 = $this->createMock(Individual::class);
76        $child4->method('getBirthDate')->willReturn(new Date('01 FEB 1904'));
77        $child4->method('getDeathDate')->willReturn(new Date(''));
78
79        $family = $this->createMock(Family::class);
80        $family->method('children')->willReturn(new Collection([$child1, $child2, $child3, $child4]));
81
82        $individual = $this->createMock(Individual::class);
83        $individual->method('sex')->willReturn('F');
84        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
85
86        $census = $this->createMock(CensusInterface::class);
87        $census->method('censusDate')->willReturn('30 MAR 1911');
88
89        $column = new CensusColumnChildrenDied($census, '', '');
90
91        $this->assertSame('1', $column->generate($individual, $individual));
92    }
93}
94