144f3c149SGreg Roach<?php 244f3c149SGreg Roach 344f3c149SGreg Roach/** 444f3c149SGreg Roach * webtrees: online genealogy 51062a142SGreg Roach * Copyright (C) 2018 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 */ 25c1010edaSGreg Roachclass CensusColumnChildrenLivingTest extends \PHPUnit\Framework\TestCase 26c1010edaSGreg Roach{ 2744f3c149SGreg Roach /** 2844f3c149SGreg Roach * Delete mock objects 2944f3c149SGreg Roach */ 30c1010edaSGreg Roach public function tearDown() 31c1010edaSGreg Roach { 3244f3c149SGreg Roach Mockery::close(); 3344f3c149SGreg Roach } 3444f3c149SGreg Roach 3544f3c149SGreg Roach /** 3615d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving 3715d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 3844f3c149SGreg Roach */ 39c1010edaSGreg Roach public function testMale() 40c1010edaSGreg Roach { 41c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 4244f3c149SGreg Roach $individual->shouldReceive('getSex')->andReturn('M'); 4344f3c149SGreg Roach 44c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 4544f3c149SGreg Roach 4644f3c149SGreg Roach $column = new CensusColumnChildrenLiving($census, '', ''); 4744f3c149SGreg Roach 48*342dcecdSGreg Roach $this->assertSame('', $column->generate($individual, $individual)); 4944f3c149SGreg Roach } 5044f3c149SGreg Roach 5144f3c149SGreg Roach /** 5215d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\CensusColumnChildrenLiving 5315d603e7SGreg Roach * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 5444f3c149SGreg Roach */ 55c1010edaSGreg Roach public function testCountChildren() 56c1010edaSGreg Roach { 5744f3c149SGreg Roach // Stillborn 58c314ecc9SGreg Roach $child1 = Mockery::mock('Fisharebest\Webtrees\Individual'); 5944f3c149SGreg Roach $child1->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904')); 6044f3c149SGreg Roach $child1->shouldReceive('getDeathDate')->andReturn(new Date('01 FEB 1904')); 6144f3c149SGreg Roach 6244f3c149SGreg Roach // Died after census 63c314ecc9SGreg Roach $child2 = Mockery::mock('Fisharebest\Webtrees\Individual'); 6444f3c149SGreg Roach $child2->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904')); 6544f3c149SGreg Roach $child2->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1912')); 6644f3c149SGreg Roach 6744f3c149SGreg Roach // Died before census 68c314ecc9SGreg Roach $child3 = Mockery::mock('Fisharebest\Webtrees\Individual'); 6944f3c149SGreg Roach $child3->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904')); 7044f3c149SGreg Roach $child3->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1910')); 7144f3c149SGreg Roach 7244f3c149SGreg Roach // Still living 73c314ecc9SGreg Roach $child4 = Mockery::mock('Fisharebest\Webtrees\Individual'); 7444f3c149SGreg Roach $child4->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904')); 7544f3c149SGreg Roach $child4->shouldReceive('getDeathDate')->andReturn(new Date('')); 7644f3c149SGreg Roach 77c314ecc9SGreg Roach $family = Mockery::mock('Fisharebest\Webtrees\Family'); 78c1010edaSGreg Roach $family->shouldReceive('getChildren')->andReturn([ 79c1010edaSGreg Roach $child1, 80c1010edaSGreg Roach $child2, 81c1010edaSGreg Roach $child3, 82c1010edaSGreg Roach $child4, 83c1010edaSGreg Roach ]); 8444f3c149SGreg Roach 85c314ecc9SGreg Roach $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 8644f3c149SGreg Roach $individual->shouldReceive('getSex')->andReturn('F'); 8713abd6f3SGreg Roach $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 8844f3c149SGreg Roach 89c314ecc9SGreg Roach $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 9044f3c149SGreg Roach $census->shouldReceive('censusDate')->andReturn('30 MAR 1911'); 9144f3c149SGreg Roach 9244f3c149SGreg Roach $column = new CensusColumnChildrenLiving($census, '', ''); 9344f3c149SGreg Roach 94*342dcecdSGreg Roach $this->assertSame('2', $column->generate($individual, $individual)); 9544f3c149SGreg Roach } 9644f3c149SGreg Roach} 97