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