xref: /webtrees/tests/app/Census/CensusColumnChildrenLivingTest.php (revision 84e2cf4e2b1803b300330f631d304db1a3c443dd)
144f3c149SGreg Roach<?php
244f3c149SGreg Roach/**
344f3c149SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 webtrees development team
544f3c149SGreg Roach * This program is free software: you can redistribute it and/or modify
644f3c149SGreg Roach * it under the terms of the GNU General Public License as published by
744f3c149SGreg Roach * the Free Software Foundation, either version 3 of the License, or
844f3c149SGreg Roach * (at your option) any later version.
944f3c149SGreg Roach * This program is distributed in the hope that it will be useful,
1044f3c149SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1144f3c149SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1244f3c149SGreg Roach * GNU General Public License for more details.
1344f3c149SGreg Roach * You should have received a copy of the GNU General Public License
1444f3c149SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1544f3c149SGreg Roach */
1644f3c149SGreg Roachnamespace Fisharebest\Webtrees\Census;
1744f3c149SGreg Roach
1844f3c149SGreg Roachuse Fisharebest\Webtrees\Date;
1944f3c149SGreg Roachuse Mockery;
2044f3c149SGreg Roach
2144f3c149SGreg Roach/**
2244f3c149SGreg Roach * Test harness for the class CensusColumnChildrenLiving
2344f3c149SGreg Roach */
24*84e2cf4eSGreg Roachclass CensusColumnChildrenLivingTest extends \Fisharebest\Webtrees\TestCase
25c1010edaSGreg Roach{
2644f3c149SGreg Roach    /**
2744f3c149SGreg Roach     * Delete mock objects
2844f3c149SGreg Roach     */
29c1010edaSGreg Roach    public function tearDown()
30c1010edaSGreg Roach    {
3144f3c149SGreg Roach        Mockery::close();
3244f3c149SGreg Roach    }
3344f3c149SGreg Roach
3444f3c149SGreg Roach    /**
3515d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
3615d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
3744f3c149SGreg Roach     */
38c1010edaSGreg Roach    public function testMale()
39c1010edaSGreg Roach    {
40c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
4144f3c149SGreg Roach        $individual->shouldReceive('getSex')->andReturn('M');
4244f3c149SGreg Roach
43c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
4444f3c149SGreg Roach
4544f3c149SGreg Roach        $column = new CensusColumnChildrenLiving($census, '', '');
4644f3c149SGreg Roach
47342dcecdSGreg Roach        $this->assertSame('', $column->generate($individual, $individual));
4844f3c149SGreg Roach    }
4944f3c149SGreg Roach
5044f3c149SGreg Roach    /**
5115d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
5215d603e7SGreg Roach     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
5344f3c149SGreg Roach     */
54c1010edaSGreg Roach    public function testCountChildren()
55c1010edaSGreg Roach    {
5644f3c149SGreg Roach        // Stillborn
57c314ecc9SGreg Roach        $child1 = Mockery::mock('Fisharebest\Webtrees\Individual');
5844f3c149SGreg Roach        $child1->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
5944f3c149SGreg Roach        $child1->shouldReceive('getDeathDate')->andReturn(new Date('01 FEB 1904'));
6044f3c149SGreg Roach
6144f3c149SGreg Roach        // Died after census
62c314ecc9SGreg Roach        $child2 = Mockery::mock('Fisharebest\Webtrees\Individual');
6344f3c149SGreg Roach        $child2->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
6444f3c149SGreg Roach        $child2->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1912'));
6544f3c149SGreg Roach
6644f3c149SGreg Roach        // Died before census
67c314ecc9SGreg Roach        $child3 = Mockery::mock('Fisharebest\Webtrees\Individual');
6844f3c149SGreg Roach        $child3->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
6944f3c149SGreg Roach        $child3->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1910'));
7044f3c149SGreg Roach
7144f3c149SGreg Roach        // Still living
72c314ecc9SGreg Roach        $child4 = Mockery::mock('Fisharebest\Webtrees\Individual');
7344f3c149SGreg Roach        $child4->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
7444f3c149SGreg Roach        $child4->shouldReceive('getDeathDate')->andReturn(new Date(''));
7544f3c149SGreg Roach
76c314ecc9SGreg Roach        $family = Mockery::mock('Fisharebest\Webtrees\Family');
77c1010edaSGreg Roach        $family->shouldReceive('getChildren')->andReturn([
78c1010edaSGreg Roach            $child1,
79c1010edaSGreg Roach            $child2,
80c1010edaSGreg Roach            $child3,
81c1010edaSGreg Roach            $child4,
82c1010edaSGreg Roach        ]);
8344f3c149SGreg Roach
84c314ecc9SGreg Roach        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
8544f3c149SGreg Roach        $individual->shouldReceive('getSex')->andReturn('F');
8613abd6f3SGreg Roach        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
8744f3c149SGreg Roach
88c314ecc9SGreg Roach        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
8944f3c149SGreg Roach        $census->shouldReceive('censusDate')->andReturn('30 MAR 1911');
9044f3c149SGreg Roach
9144f3c149SGreg Roach        $column = new CensusColumnChildrenLiving($census, '', '');
9244f3c149SGreg Roach
93342dcecdSGreg Roach        $this->assertSame('2', $column->generate($individual, $individual));
9444f3c149SGreg Roach    }
9544f3c149SGreg Roach}
96