xref: /webtrees/tests/app/Census/CensusColumnYearsMarriedTest.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 CensusColumnYearsMarried
23 */
24class CensusColumnYearsMarriedTest 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\CensusColumnYearsMarried
38     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
39     *
40     * @return void
41     */
42    public function testNoSpouseFamily()
43    {
44        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
45        $individual->shouldReceive('getSpouseFamilies')->andReturn([]);
46
47        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
48        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
49
50        $column = new CensusColumnYearsMarried($census, '', '');
51
52        $this->assertSame('', $column->generate($individual, $individual));
53    }
54
55    /**
56     * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried
57     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
58     *
59     * @return void
60     */
61    public function testNoMarriage()
62    {
63        $family = Mockery::mock('Fisharebest\Webtrees\Family');
64        $family->shouldReceive('getFacts')->with('MARR', true)->andReturn([]);
65
66        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
67        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
68
69        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
70        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
71
72        $column = new CensusColumnYearsMarried($census, '', '');
73
74        $this->assertSame('', $column->generate($individual, $individual));
75    }
76
77    /**
78     * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried
79     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
80     *
81     * @return void
82     */
83    public function testUndatedMarriage()
84    {
85        $fact = Mockery::mock('Fisharebest\Webtrees\Fact');
86        $fact->shouldReceive('getDate')->andReturn(new Date(''));
87
88        $family = Mockery::mock('Fisharebest\Webtrees\Family');
89        $family->shouldReceive('getFacts')->with('MARR', true)->andReturn([$fact]);
90
91        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
92        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
93
94        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
95        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
96
97        $column = new CensusColumnYearsMarried($census, '', '');
98
99        $this->assertSame('', $column->generate($individual, $individual));
100    }
101
102    /**
103     * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried
104     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
105     *
106     * @return void
107     */
108    public function testMarriageAfterCensus()
109    {
110        $fact = Mockery::mock('Fisharebest\Webtrees\Fact');
111        $fact->shouldReceive('getDate')->andReturn(new Date('1861'));
112
113        $family = Mockery::mock('Fisharebest\Webtrees\Family');
114        $family->shouldReceive('getFacts')->with('MARR', true)->andReturn([$fact]);
115
116        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
117        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
118
119        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
120        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
121
122        $column = new CensusColumnYearsMarried($census, '', '');
123
124        $this->assertSame('', $column->generate($individual, $individual));
125    }
126
127    /**
128     * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried
129     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
130     *
131     * @return void
132     */
133    public function testMarriageBeforeCensus()
134    {
135        $fact = Mockery::mock('Fisharebest\Webtrees\Fact');
136        $fact->shouldReceive('getDate')->andReturn(new Date('OCT 1851'));
137
138        $family = Mockery::mock('Fisharebest\Webtrees\Family');
139        $family->shouldReceive('getFacts')->with('MARR', true)->andReturn([$fact]);
140
141        $individual = Mockery::mock('Fisharebest\Webtrees\Individual');
142        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
143
144        $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface');
145        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
146
147        $column = new CensusColumnYearsMarried($census, '', '');
148
149        $this->assertSame('8', $column->generate($individual, $individual));
150    }
151}
152