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