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