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