xref: /webtrees/tests/app/Census/CensusColumnAgeMarriedTest.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(CensusColumnAgeMarried::class)]
32#[CoversClass(AbstractCensusColumn::class)]
33class CensusColumnAgeMarriedTest extends TestCase
34{
35    public function testAgeMarried(): void
36    {
37        $fact = $this->createMock(Fact::class);
38        $fact->method('date')->willReturn(new Date('01 DEC 1859'));
39
40        $family = $this->createMock(Family::class);
41        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact]));
42
43        $individual = $this->createMock(Individual::class);
44        $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840'));
45        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
46
47        $census = $this->createMock(CensusInterface::class);
48        $census->method('censusDate')->willReturn('01 JUN 1860');
49
50        $column = new CensusColumnAgeMarried($census, '', '');
51
52        self::assertSame('19', $column->generate($individual, $individual));
53    }
54
55    public function testNoBirthDate(): void
56    {
57        $individual = $this->createMock(Individual::class);
58        $individual->method('getBirthDate')->willReturn(new Date(''));
59        $individual->method('spouseFamilies')->willReturn(new Collection());
60
61        $census = $this->createMock(CensusInterface::class);
62        $census->method('censusDate')->willReturn('01 JUN 1860');
63
64        $column = new CensusColumnAgeMarried($census, '', '');
65
66        self::assertSame('', $column->generate($individual, $individual));
67    }
68
69    public function testNoMarriage(): void
70    {
71        $family = $this->createMock(Family::class);
72        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
73
74        $individual = $this->createMock(Individual::class);
75        $individual->method('getBirthDate')->willReturn(new Date(''));
76        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
77
78        $census = $this->createMock(CensusInterface::class);
79        $census->method('censusDate')->willReturn('01 JUN 1860');
80
81        $column = new CensusColumnAgeMarried($census, '', '');
82
83        self::assertSame('', $column->generate($individual, $individual));
84    }
85
86    public function testNoSpouseFamily(): void
87    {
88        $individual = $this->createMock(Individual::class);
89        $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840'));
90        $individual->method('spouseFamilies')->willReturn(new Collection());
91
92        $census = $this->createMock(CensusInterface::class);
93        $census->method('censusDate')->willReturn('01 JUN 1860');
94
95        $column = new CensusColumnAgeMarried($census, '', '');
96
97        self::assertSame('', $column->generate($individual, $individual));
98    }
99}
100