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