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