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