xref: /webtrees/tests/app/Census/CensusColumnAgeMarriedTest.php (revision 86c75e30decf65b2ee2190ca2847e42271e795ee)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Census;
19
20use Fisharebest\Webtrees\Date;
21use Fisharebest\Webtrees\Fact;
22use Fisharebest\Webtrees\Family;
23use Fisharebest\Webtrees\Individual;
24use Mockery;
25
26/**
27 * Test harness for the class CensusColumnAgeMarried
28 */
29class CensusColumnAgeMarriedTest extends \Fisharebest\Webtrees\TestCase
30{
31    /**
32     * Delete mock objects
33     *
34     * @return void
35     */
36    public function tearDown()
37    {
38        Mockery::close();
39    }
40
41    /**
42     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
43     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
44     *
45     * @return void
46     */
47    public function testAgeMarried(): void
48    {
49        $fact = Mockery::mock(Fact::class);
50        $fact->shouldReceive('date')->andReturn(new Date('01 DEC 1859'));
51
52        $family = Mockery::mock(Family::class);
53        $family->shouldReceive('facts')->with(['MARR'], true)->andReturn([$fact]);
54
55        $individual = Mockery::mock(Individual::class);
56        $individual->shouldReceive('getBirthDate')->andReturn(new Date('15 MAR 1840'));
57        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
58
59        $census = Mockery::mock(CensusInterface::class);
60        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
61
62        $column = new CensusColumnAgeMarried($census, '', '');
63
64        $this->assertSame('19', $column->generate($individual, $individual));
65    }
66
67    /**
68     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
69     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
70     *
71     * @return void
72     */
73    public function testNoBirthDate(): void
74    {
75        $individual = Mockery::mock(Individual::class);
76        $individual->shouldReceive('getBirthDate')->andReturn(new Date(''));
77        $individual->shouldReceive('getSpouseFamilies')->andReturn([]);
78
79        $census = Mockery::mock(CensusInterface::class);
80        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
81
82        $column = new CensusColumnAgeMarried($census, '', '');
83
84        $this->assertSame('', $column->generate($individual, $individual));
85    }
86
87    /**
88     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
89     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
90     *
91     * @return void
92     */
93    public function testNoMarriage(): void
94    {
95        $family = Mockery::mock(Family::class);
96        $family->shouldReceive('facts')->with(['MARR'])->andReturn([]);
97
98        $individual = Mockery::mock(Individual::class);
99        $individual->shouldReceive('getBirthDate')->andReturn(new Date(''));
100        $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
101
102        $census = Mockery::mock(CensusInterface::class);
103        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
104
105        $column = new CensusColumnAgeMarried($census, '', '');
106
107        $this->assertSame('', $column->generate($individual, $individual));
108    }
109
110    /**
111     * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried
112     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
113     *
114     * @return void
115     */
116    public function testNoSpouseFamily(): void
117    {
118        $individual = Mockery::mock(Individual::class);
119        $individual->shouldReceive('getBirthDate')->andReturn(new Date('15 MAR 1840'));
120        $individual->shouldReceive('getSpouseFamilies')->andReturn([]);
121
122        $census = Mockery::mock(CensusInterface::class);
123        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
124
125        $column = new CensusColumnAgeMarried($census, '', '');
126
127        $this->assertSame('', $column->generate($individual, $individual));
128    }
129}
130