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