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