xref: /webtrees/tests/app/Census/CensusColumnChildrenLivingTest.php (revision 3e983931fdde6db78f1490364106d7d46e77dea7)
144f3c149SGreg Roach<?php
244f3c149SGreg Roach
344f3c149SGreg Roach/**
444f3c149SGreg Roach * webtrees: online genealogy
56bdf7674SGreg Roach * Copyright (C) 2017 webtrees development team
644f3c149SGreg Roach * This program is free software: you can redistribute it and/or modify
744f3c149SGreg Roach * it under the terms of the GNU General Public License as published by
844f3c149SGreg Roach * the Free Software Foundation, either version 3 of the License, or
944f3c149SGreg Roach * (at your option) any later version.
1044f3c149SGreg Roach * This program is distributed in the hope that it will be useful,
1144f3c149SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1244f3c149SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1344f3c149SGreg Roach * GNU General Public License for more details.
1444f3c149SGreg Roach * You should have received a copy of the GNU General Public License
1544f3c149SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1644f3c149SGreg Roach */
1744f3c149SGreg Roachnamespace Fisharebest\Webtrees\Census;
1844f3c149SGreg Roach
1944f3c149SGreg Roachuse Fisharebest\Webtrees\Date;
2044f3c149SGreg Roachuse Mockery;
2144f3c149SGreg Roach
2244f3c149SGreg Roach/**
2344f3c149SGreg Roach * Test harness for the class CensusColumnChildrenLiving
2444f3c149SGreg Roach */
25*3e983931SGreg Roachclass CensusColumnChildrenLivingTest extends \PHPUnit\Framework\TestCase {
2644f3c149SGreg Roach	/**
2744f3c149SGreg Roach	 * Delete mock objects
2844f3c149SGreg Roach	 */
2944f3c149SGreg Roach	public function tearDown() {
3044f3c149SGreg Roach		Mockery::close();
3144f3c149SGreg Roach	}
3244f3c149SGreg Roach
3344f3c149SGreg Roach	/**
3415d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
3515d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
3644f3c149SGreg Roach	 */
3744f3c149SGreg Roach	public function testMale() {
38c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
3944f3c149SGreg Roach		$individual->shouldReceive('getSex')->andReturn('M');
4044f3c149SGreg Roach
41c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
4244f3c149SGreg Roach
4344f3c149SGreg Roach		$column = new CensusColumnChildrenLiving($census, '', '');
4444f3c149SGreg Roach
4544f3c149SGreg Roach		$this->assertSame('', $column->generate($individual));
4644f3c149SGreg Roach	}
4744f3c149SGreg Roach
4844f3c149SGreg Roach	/**
4915d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
5015d603e7SGreg Roach	 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
5144f3c149SGreg Roach	 */
5244f3c149SGreg Roach	public function testCountChildren() {
5344f3c149SGreg Roach		// Stillborn
54c314ecc9SGreg Roach		$child1 = Mockery::mock('Fisharebest\Webtrees\Individual');
5544f3c149SGreg Roach		$child1->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
5644f3c149SGreg Roach		$child1->shouldReceive('getDeathDate')->andReturn(new Date('01 FEB 1904'));
5744f3c149SGreg Roach
5844f3c149SGreg Roach		// Died after census
59c314ecc9SGreg Roach		$child2 = Mockery::mock('Fisharebest\Webtrees\Individual');
6044f3c149SGreg Roach		$child2->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
6144f3c149SGreg Roach		$child2->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1912'));
6244f3c149SGreg Roach
6344f3c149SGreg Roach		// Died before census
64c314ecc9SGreg Roach		$child3 = Mockery::mock('Fisharebest\Webtrees\Individual');
6544f3c149SGreg Roach		$child3->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
6644f3c149SGreg Roach		$child3->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1910'));
6744f3c149SGreg Roach
6844f3c149SGreg Roach		// Still living
69c314ecc9SGreg Roach		$child4 = Mockery::mock('Fisharebest\Webtrees\Individual');
7044f3c149SGreg Roach		$child4->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
7144f3c149SGreg Roach		$child4->shouldReceive('getDeathDate')->andReturn(new Date(''));
7244f3c149SGreg Roach
73c314ecc9SGreg Roach		$family = Mockery::mock('Fisharebest\Webtrees\Family');
7413abd6f3SGreg Roach		$family->shouldReceive('getChildren')->andReturn([$child1, $child2, $child3, $child4]);
7544f3c149SGreg Roach
76c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
7744f3c149SGreg Roach		$individual->shouldReceive('getSex')->andReturn('F');
7813abd6f3SGreg Roach		$individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
7944f3c149SGreg Roach
80c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
8144f3c149SGreg Roach		$census->shouldReceive('censusDate')->andReturn('30 MAR 1911');
8244f3c149SGreg Roach
8344f3c149SGreg Roach		$column = new CensusColumnChildrenLiving($census, '', '');
8444f3c149SGreg Roach
8544f3c149SGreg Roach		$this->assertSame('2', $column->generate($individual));
8644f3c149SGreg Roach	}
8744f3c149SGreg Roach}
88