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