xref: /webtrees/tests/app/Census/CensusColumnAgeMarriedTest.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Census;
20
21use Fisharebest\Webtrees\Date;
22use Fisharebest\Webtrees\Fact;
23use Fisharebest\Webtrees\Family;
24use Fisharebest\Webtrees\Individual;
25use Illuminate\Support\Collection;
26
27/**
28 * Test harness for the class CensusColumnAgeMarried
29 */
30class CensusColumnAgeMarriedTest extends \Fisharebest\Webtrees\TestCase
31{
32    /**
33     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
34     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
35     *
36     * @return void
37     */
38    public function testAgeMarried(): void
39    {
40        $fact = $this->createMock(Fact::class);
41        $fact->method('date')->willReturn(new Date('01 DEC 1859'));
42
43        $family = $this->createMock(Family::class);
44        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact]));
45
46        $individual = $this->createMock(Individual::class);
47        $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840'));
48        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
49
50        $census = $this->createMock(CensusInterface::class);
51        $census->method('censusDate')->willReturn('01 JUN 1860');
52
53        $column = new CensusColumnAgeMarried($census, '', '');
54
55        $this->assertSame('19', $column->generate($individual, $individual));
56    }
57
58    /**
59     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
60     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
61     *
62     * @return void
63     */
64    public function testNoBirthDate(): void
65    {
66        $individual = $this->createMock(Individual::class);
67        $individual->method('getBirthDate')->willReturn(new Date(''));
68        $individual->method('spouseFamilies')->willReturn(new Collection());
69
70        $census = $this->createMock(CensusInterface::class);
71        $census->method('censusDate')->willReturn('01 JUN 1860');
72
73        $column = new CensusColumnAgeMarried($census, '', '');
74
75        $this->assertSame('', $column->generate($individual, $individual));
76    }
77
78    /**
79     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
80     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
81     *
82     * @return void
83     */
84    public function testNoMarriage(): void
85    {
86        $family = $this->createMock(Family::class);
87        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
88
89        $individual = $this->createMock(Individual::class);
90        $individual->method('getBirthDate')->willReturn(new Date(''));
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 CensusColumnAgeMarried($census, '', '');
97
98        $this->assertSame('', $column->generate($individual, $individual));
99    }
100
101    /**
102     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
103     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
104     *
105     * @return void
106     */
107    public function testNoSpouseFamily(): void
108    {
109        $individual = $this->createMock(Individual::class);
110        $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840'));
111        $individual->method('spouseFamilies')->willReturn(new Collection());
112
113        $census = $this->createMock(CensusInterface::class);
114        $census->method('censusDate')->willReturn('01 JUN 1860');
115
116        $column = new CensusColumnAgeMarried($census, '', '');
117
118        $this->assertSame('', $column->generate($individual, $individual));
119    }
120}
121