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