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