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