xref: /webtrees/tests/app/Census/CensusColumnChildrenLivingTest.php (revision 819367e7d215c93f1776f3caa74eb42e78299461)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Census;
19
20use Fisharebest\Webtrees\Date;
21use Fisharebest\Webtrees\Family;
22use Fisharebest\Webtrees\Individual;
23use Illuminate\Support\Collection;
24
25/**
26 * Test harness for the class CensusColumnChildrenLiving
27 */
28class CensusColumnChildrenLivingTest extends \Fisharebest\Webtrees\TestCase
29{
30    /**
31     * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
32     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
33     *
34     * @return void
35     */
36    public function testMale(): void
37    {
38        $individual = $this->createMock(Individual::class);
39        $individual->method('sex')->willReturn('M');
40
41        $census = $this->createMock(CensusInterface::class);
42
43        $column = new CensusColumnChildrenLiving($census, '', '');
44
45        $this->assertSame('', $column->generate($individual, $individual));
46    }
47
48    /**
49     * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
50     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
51     *
52     * @return void
53     */
54    public function testCountChildren(): void
55    {
56        // Stillborn
57        $child1 = $this->createMock(Individual::class);
58        $child1->method('getBirthDate')->willReturn(new Date('01 FEB 1904'));
59        $child1->method('getDeathDate')->willReturn(new Date('01 FEB 1904'));
60
61        // Died after census
62        $child2 = $this->createMock(Individual::class);
63        $child2->method('getBirthDate')->willReturn(new Date('02 FEB 1904'));
64        $child2->method('getDeathDate')->willReturn(new Date('20 DEC 1912'));
65
66        // Died before census
67        $child3 = $this->createMock(Individual::class);
68        $child3->method('getBirthDate')->willReturn(new Date('02 FEB 1904'));
69        $child3->method('getDeathDate')->willReturn(new Date('20 DEC 1910'));
70
71        // Still living
72        $child4 = $this->createMock(Individual::class);
73        $child4->method('getBirthDate')->willReturn(new Date('01 FEB 1904'));
74        $child4->method('getDeathDate')->willReturn(new Date(''));
75
76        $family = $this->createMock(Family::class);
77        $family->method('children')->willReturn(new Collection([
78            $child1,
79            $child2,
80            $child3,
81            $child4,
82        ]));
83
84        $individual = $this->createMock(Individual::class);
85        $individual->method('sex')->willReturn('F');
86        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
87
88        $census = $this->createMock(CensusInterface::class);
89        $census->method('censusDate')->willReturn('30 MAR 1911');
90
91        $column = new CensusColumnChildrenLiving($census, '', '');
92
93        $this->assertSame('2', $column->generate($individual, $individual));
94    }
95}
96