xref: /webtrees/tests/app/Census/CensusColumnAgeMale5YearsTest.php (revision fc747c0fe6ab8c4d4d65bbb60eb220a1c792d7f6)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\Census;
17
18use Fisharebest\Webtrees\Date;
19use Mockery;
20
21/**
22 * Test harness for the class CensusColumnAgeMale5Years5Years
23 */
24class CensusColumnAgeMale5YearsTest extends \Fisharebest\Webtrees\TestCase
25{
26    /**
27     * Delete mock objects
28     *
29     * @return void
30     */
31    public function tearDown()
32    {
33        Mockery::close();
34    }
35
36    /**
37     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
38     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
39     *
40     * @return void
41     */
42    public function testMale()
43    {
44        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
45        $individual->shouldReceive('getSex')->andReturn('M');
46        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
47
48        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
49        $census->shouldReceive('censusDate')->andReturn('30 JUN 1830');
50
51        $column = new CensusColumnAgeMale5Years($census, '', '');
52
53        $this->assertSame('30', $column->generate($individual, $individual));
54    }
55
56    /**
57     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
58     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
59     *
60     * @return void
61     */
62    public function testFemale()
63    {
64        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
65        $individual->shouldReceive('getSex')->andReturn('F');
66
67        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
68
69        $column = new CensusColumnAgeMale5Years($census, '', '');
70
71        $this->assertSame('', $column->generate($individual, $individual));
72    }
73
74    /**
75     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
76     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
77     *
78     * @return void
79     */
80    public function testUnknownSex()
81    {
82        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
83        $individual->shouldReceive('getSex')->andReturn('U');
84        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
85
86        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
87        $census->shouldReceive('censusDate')->andReturn('30 JUN 1830');
88
89        $column = new CensusColumnAgeMale5Years($census, '', '');
90
91        $this->assertSame('30', $column->generate($individual, $individual));
92    }
93
94    /**
95     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
96     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
97     *
98     * @return void
99     */
100    public function testLessThanOneYear()
101    {
102        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
103        $individual->shouldReceive('getSex')->andReturn('M');
104        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
105
106        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
107        $census->shouldReceive('censusDate')->andReturn('30 JUN 1800');
108
109        $column = new CensusColumnAgeMale5Years($census, '', '');
110
111        $this->assertSame('0', $column->generate($individual, $individual));
112    }
113
114    /**
115     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
116     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
117     *
118     * @return void
119     */
120    public function testLessThanFifteenYears()
121    {
122        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
123        $individual->shouldReceive('getSex')->andReturn('M');
124        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
125
126        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
127        $census->shouldReceive('censusDate')->andReturn('30 JUN 1814');
128
129        $column = new CensusColumnAgeMale5Years($census, '', '');
130
131        $this->assertSame('14', $column->generate($individual, $individual));
132    }
133
134    /**
135     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMale5Years
136     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
137     *
138     * @return void
139     */
140    public function testRoundedDownToFiveYears()
141    {
142        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
143        $individual->shouldReceive('getSex')->andReturn('M');
144        $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
145
146        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
147        $census->shouldReceive('censusDate')->andReturn('30 JUN 1844');
148
149        $column = new CensusColumnAgeMale5Years($census, '', '');
150
151        $this->assertSame('40', $column->generate($individual, $individual));
152    }
153}
154