xref: /webtrees/tests/app/Census/CensusColumnAgeMarriedTest.php (revision 00b1984e374faddab4698e73088f0c964e529b65)
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 */
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;
28
29/**
30 * Test harness for the class CensusColumnAgeMarried
31 */
32class CensusColumnAgeMarriedTest extends TestCase
33{
34    /**
35     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
36     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
37     *
38     * @return void
39     */
40    public function testAgeMarried(): void
41    {
42        $fact = $this->createMock(Fact::class);
43        $fact->method('date')->willReturn(new Date('01 DEC 1859'));
44
45        $family = $this->createMock(Family::class);
46        $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact]));
47
48        $individual = $this->createMock(Individual::class);
49        $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840'));
50        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
51
52        $census = $this->createMock(CensusInterface::class);
53        $census->method('censusDate')->willReturn('01 JUN 1860');
54
55        $column = new CensusColumnAgeMarried($census, '', '');
56
57        $this->assertSame('19', $column->generate($individual, $individual));
58    }
59
60    /**
61     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
62     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
63     *
64     * @return void
65     */
66    public function testNoBirthDate(): void
67    {
68        $individual = $this->createMock(Individual::class);
69        $individual->method('getBirthDate')->willReturn(new Date(''));
70        $individual->method('spouseFamilies')->willReturn(new Collection());
71
72        $census = $this->createMock(CensusInterface::class);
73        $census->method('censusDate')->willReturn('01 JUN 1860');
74
75        $column = new CensusColumnAgeMarried($census, '', '');
76
77        $this->assertSame('', $column->generate($individual, $individual));
78    }
79
80    /**
81     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
82     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
83     *
84     * @return void
85     */
86    public function testNoMarriage(): void
87    {
88        $family = $this->createMock(Family::class);
89        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
90
91        $individual = $this->createMock(Individual::class);
92        $individual->method('getBirthDate')->willReturn(new Date(''));
93        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
94
95        $census = $this->createMock(CensusInterface::class);
96        $census->method('censusDate')->willReturn('01 JUN 1860');
97
98        $column = new CensusColumnAgeMarried($census, '', '');
99
100        $this->assertSame('', $column->generate($individual, $individual));
101    }
102
103    /**
104     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
105     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
106     *
107     * @return void
108     */
109    public function testNoSpouseFamily(): void
110    {
111        $individual = $this->createMock(Individual::class);
112        $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840'));
113        $individual->method('spouseFamilies')->willReturn(new Collection());
114
115        $census = $this->createMock(CensusInterface::class);
116        $census->method('censusDate')->willReturn('01 JUN 1860');
117
118        $column = new CensusColumnAgeMarried($census, '', '');
119
120        $this->assertSame('', $column->generate($individual, $individual));
121    }
122}
123