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