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