xref: /webtrees/tests/app/Census/CensusColumnChildrenLivingTest.php (revision c314ecc9a18e5e740a1c0fcb7379ef541f969dc5)
144f3c149SGreg Roach<?php
244f3c149SGreg Roach
344f3c149SGreg Roach/**
444f3c149SGreg Roach * webtrees: online genealogy
544f3c149SGreg Roach * Copyright (C) 2015 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;
2088cd6753SGreg Roachuse Fisharebest\Webtrees\Family;
2144f3c149SGreg Roachuse Fisharebest\Webtrees\Individual;
2244f3c149SGreg Roachuse Mockery;
2344f3c149SGreg Roach
2444f3c149SGreg Roach/**
2544f3c149SGreg Roach * Test harness for the class CensusColumnChildrenLiving
2644f3c149SGreg Roach */
2744f3c149SGreg Roachclass CensusColumnChildrenLivingTest extends \PHPUnit_Framework_TestCase {
2844f3c149SGreg Roach	/**
2944f3c149SGreg Roach	 * Delete mock objects
3044f3c149SGreg Roach	 */
3144f3c149SGreg Roach	public function tearDown() {
3244f3c149SGreg Roach		Mockery::close();
3344f3c149SGreg Roach	}
3444f3c149SGreg Roach
3544f3c149SGreg Roach	/**
3644f3c149SGreg Roach	 * @covers Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
3744f3c149SGreg Roach	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
3844f3c149SGreg Roach	 */
3944f3c149SGreg Roach	public function testMale() {
40*c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
4144f3c149SGreg Roach		$individual->shouldReceive('getSex')->andReturn('M');
4244f3c149SGreg Roach
43*c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
4444f3c149SGreg Roach
4544f3c149SGreg Roach		$column = new CensusColumnChildrenLiving($census, '', '');
4644f3c149SGreg Roach
4744f3c149SGreg Roach		$this->assertSame('', $column->generate($individual));
4844f3c149SGreg Roach	}
4944f3c149SGreg Roach
5044f3c149SGreg Roach	/**
5144f3c149SGreg Roach	 * @covers Fisharebest\Webtrees\Census\CensusColumnChildrenLiving
5244f3c149SGreg Roach	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
5344f3c149SGreg Roach	 */
5444f3c149SGreg Roach	public function testCountChildren() {
5544f3c149SGreg Roach		// Stillborn
56*c314ecc9SGreg Roach		$child1 = Mockery::mock('Fisharebest\Webtrees\Individual');
5744f3c149SGreg Roach		$child1->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
5844f3c149SGreg Roach		$child1->shouldReceive('getDeathDate')->andReturn(new Date('01 FEB 1904'));
5944f3c149SGreg Roach
6044f3c149SGreg Roach		// Died after census
61*c314ecc9SGreg Roach		$child2 = Mockery::mock('Fisharebest\Webtrees\Individual');
6244f3c149SGreg Roach		$child2->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
6344f3c149SGreg Roach		$child2->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1912'));
6444f3c149SGreg Roach
6544f3c149SGreg Roach		// Died before census
66*c314ecc9SGreg Roach		$child3 = Mockery::mock('Fisharebest\Webtrees\Individual');
6744f3c149SGreg Roach		$child3->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
6844f3c149SGreg Roach		$child3->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1910'));
6944f3c149SGreg Roach
7044f3c149SGreg Roach		// Still living
71*c314ecc9SGreg Roach		$child4 = Mockery::mock('Fisharebest\Webtrees\Individual');
7244f3c149SGreg Roach		$child4->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
7344f3c149SGreg Roach		$child4->shouldReceive('getDeathDate')->andReturn(new Date(''));
7444f3c149SGreg Roach
75*c314ecc9SGreg Roach		$family = Mockery::mock('Fisharebest\Webtrees\Family');
76e2052359SGreg Roach		$family->shouldReceive('getChildren')->andReturn(array($child1, $child2, $child3, $child4));
7744f3c149SGreg Roach
78*c314ecc9SGreg Roach		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
7944f3c149SGreg Roach		$individual->shouldReceive('getSex')->andReturn('F');
80e2052359SGreg Roach		$individual->shouldReceive('getSpouseFamilies')->andReturn(array($family));
8144f3c149SGreg Roach
82*c314ecc9SGreg Roach		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
8344f3c149SGreg Roach		$census->shouldReceive('censusDate')->andReturn('30 MAR 1911');
8444f3c149SGreg Roach
8544f3c149SGreg Roach		$column = new CensusColumnChildrenLiving($census, '', '');
8644f3c149SGreg Roach
8744f3c149SGreg Roach		$this->assertSame('2', $column->generate($individual));
8844f3c149SGreg Roach	}
8944f3c149SGreg Roach}
90