xref: /webtrees/tests/app/Census/CensusColumnChildrenDiedTest.php (revision 13abd6f3a37322f885d85df150e105d27ad81f8d)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2016 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17namespace Fisharebest\Webtrees\Census;
18
19use Fisharebest\Webtrees\Date;
20use Mockery;
21
22/**
23 * Test harness for the class CensusColumnChildrenDied
24 */
25class CensusColumnChildrenDiedTest extends \PHPUnit_Framework_TestCase {
26	/**
27	 * Delete mock objects
28	 */
29	public function tearDown() {
30		Mockery::close();
31	}
32
33	/**
34	 * @covers Fisharebest\Webtrees\Census\CensusColumnChildrenDied
35	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
36	 */
37	public function testMale() {
38		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
39		$individual->shouldReceive('getSex')->andReturn('M');
40
41		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
42
43		$column = new CensusColumnChildrenDied($census, '', '');
44
45		$this->assertSame('', $column->generate($individual));
46	}
47
48	/**
49	 * @covers Fisharebest\Webtrees\Census\CensusColumnChildrenDied
50	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
51	 */
52	public function testCountChildren() {
53		// Stillborn
54		$child1 = Mockery::mock('Fisharebest\Webtrees\Individual');
55		$child1->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
56		$child1->shouldReceive('getDeathDate')->andReturn(new Date('01 FEB 1904'));
57
58		// Died after census
59		$child2 = Mockery::mock('Fisharebest\Webtrees\Individual');
60		$child2->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
61		$child2->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1912'));
62
63		// Died before census
64		$child3 = Mockery::mock('Fisharebest\Webtrees\Individual');
65		$child3->shouldReceive('getBirthDate')->andReturn(new Date('02 FEB 1904'));
66		$child3->shouldReceive('getDeathDate')->andReturn(new Date('20 DEC 1910'));
67
68		// Still living
69		$child4 = Mockery::mock('Fisharebest\Webtrees\Individual');
70		$child4->shouldReceive('getBirthDate')->andReturn(new Date('01 FEB 1904'));
71		$child4->shouldReceive('getDeathDate')->andReturn(new Date(''));
72
73		$family = Mockery::mock('Fisharebest\Webtrees\Family');
74		$family->shouldReceive('getChildren')->andReturn([$child1, $child2, $child3, $child4]);
75
76		$individual = Mockery::mock('Fisharebest\Webtrees\Individual');
77		$individual->shouldReceive('getSex')->andReturn('F');
78		$individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
79
80		$census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
81		$census->shouldReceive('censusDate')->andReturn('30 MAR 1911');
82
83		$column = new CensusColumnChildrenDied($census, '', '');
84
85		$this->assertSame('1', $column->generate($individual));
86	}
87}
88