xref: /webtrees/tests/app/Census/CensusColumnYearsMarriedTest.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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;
28use PHPUnit\Framework\Attributes\CoversClass;
29
30#[CoversClass(CensusColumnYearsMarried::class)]
31#[CoversClass(AbstractCensusColumn::class)]
32class CensusColumnYearsMarriedTest extends TestCase
33{
34    public function testNoSpouseFamily(): void
35    {
36        $individual = $this->createMock(Individual::class);
37        $individual->method('spouseFamilies')->willReturn(new Collection());
38
39        $census = $this->createMock(CensusInterface::class);
40        $census->method('censusDate')->willReturn('01 JUN 1860');
41
42        $column = new CensusColumnYearsMarried($census, '', '');
43
44        self::assertSame('', $column->generate($individual, $individual));
45    }
46
47    public function testNoMarriage(): void
48    {
49        $family = $this->createMock(Family::class);
50        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection());
51
52        $individual = $this->createMock(Individual::class);
53        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
54
55        $census = $this->createMock(CensusInterface::class);
56        $census->method('censusDate')->willReturn('01 JUN 1860');
57
58        $column = new CensusColumnYearsMarried($census, '', '');
59
60        self::assertSame('', $column->generate($individual, $individual));
61    }
62
63    public function testUndatedMarriage(): void
64    {
65        $fact = $this->createMock(Fact::class);
66        $fact->method('date')->willReturn(new Date(''));
67
68        $family = $this->createMock(Family::class);
69        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact]));
70
71        $individual = $this->createMock(Individual::class);
72        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
73
74        $census = $this->createMock(CensusInterface::class);
75        $census->method('censusDate')->willReturn('01 JUN 1860');
76
77        $column = new CensusColumnYearsMarried($census, '', '');
78
79        self::assertSame('', $column->generate($individual, $individual));
80    }
81
82    public function testMarriageAfterCensus(): void
83    {
84        $fact = $this->createMock(Fact::class);
85        $fact->method('date')->willReturn(new Date('1861'));
86
87        $family = $this->createMock(Family::class);
88        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact]));
89
90        $individual = $this->createMock(Individual::class);
91        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
92
93        $census = $this->createMock(CensusInterface::class);
94        $census->method('censusDate')->willReturn('01 JUN 1860');
95
96        $column = new CensusColumnYearsMarried($census, '', '');
97
98        self::assertSame('', $column->generate($individual, $individual));
99    }
100
101    public function testMarriageBeforeCensus(): void
102    {
103        $fact = $this->createMock(Fact::class);
104        $fact->method('date')->willReturn(new Date('OCT 1851'));
105
106        $family = $this->createMock(Family::class);
107        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact]));
108
109        $individual = $this->createMock(Individual::class);
110        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
111
112        $census = $this->createMock(CensusInterface::class);
113        $census->method('censusDate')->willReturn('01 JUN 1860');
114
115        $column = new CensusColumnYearsMarried($census, '', '');
116
117        self::assertSame('8', $column->generate($individual, $individual));
118    }
119}
120