xref: /webtrees/tests/app/Census/CensusColumnMarriedWithinYearTest.php (revision 1b860509f2032c67fc289dfb8ccba11726fbd18a)
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 CensusColumnMarriedWithinYear
29 */
30class CensusColumnMarriedWithinYearTest 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\CensusColumnMarriedWithinYear
44     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
45     *
46     * @return void
47     */
48    public function testMarriedWithinYear(): 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'])->andReturn(new Collection([$fact]));
55
56        $individual = Mockery::mock(Individual::class);
57        $individual->shouldReceive('spouseFamilies')->andReturn(new Collection([$family]));
58
59        $census = Mockery::mock(CensusInterface::class);
60        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
61
62        $column = new CensusColumnMarriedWithinYear($census, '', '');
63
64        $this->assertSame('Y', $column->generate($individual, $individual));
65    }
66
67    /**
68     * @covers \Fisharebest\Webtrees\Census\CensusColumnMarriedWithinYear
69     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
70     *
71     * @return void
72     */
73    public function testMarriedOverYearBeforeTheCensus(): void
74    {
75        $fact = Mockery::mock(Fact::class);
76        $fact->shouldReceive('date')->andReturn(new Date('01 JAN 1859'));
77
78        $family = Mockery::mock(Family::class);
79        $family->shouldReceive('facts')->with(['MARR'])->andReturn(new Collection([$fact]));
80
81        $individual = Mockery::mock(Individual::class);
82        $individual->shouldReceive('spouseFamilies')->andReturn(new Collection([$family]));
83
84        $census = Mockery::mock(CensusInterface::class);
85        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
86
87        $column = new CensusColumnMarriedWithinYear($census, '', '');
88
89        $this->assertSame('', $column->generate($individual, $individual));
90    }
91
92    /**
93     * @covers \Fisharebest\Webtrees\Census\CensusColumnMarriedWithinYear
94     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
95     *
96     * @return void
97     */
98    public function testMarriedAfterTheCensus(): void
99    {
100        $fact = Mockery::mock(Fact::class);
101        $fact->shouldReceive('date')->andReturn(new Date('02 JUN 1860'));
102
103        $family = Mockery::mock(Family::class);
104        $family->shouldReceive('facts')->with(['MARR'])->andReturn(new Collection([$fact]));
105
106        $individual = Mockery::mock(Individual::class);
107        $individual->shouldReceive('spouseFamilies')->andReturn(new Collection([$family]));
108
109        $census = Mockery::mock(CensusInterface::class);
110        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
111
112        $column = new CensusColumnMarriedWithinYear($census, '', '');
113
114        $this->assertSame('', $column->generate($individual, $individual));
115    }
116
117    /**
118     * @covers \Fisharebest\Webtrees\Census\CensusColumnMarriedWithinYear
119     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
120     *
121     * @return void
122     */
123    public function testNoMarriage(): void
124    {
125        $family = Mockery::mock(Family::class);
126        $family->shouldReceive('facts')->with(['MARR'])->andReturn(new Collection());
127
128        $individual = Mockery::mock(Individual::class);
129        $individual->shouldReceive('spouseFamilies')->andReturn(new Collection([$family]));
130
131        $census = Mockery::mock(CensusInterface::class);
132        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
133
134        $column = new CensusColumnMarriedWithinYear($census, '', '');
135
136        $this->assertSame('', $column->generate($individual, $individual));
137    }
138
139    /**
140     * @covers \Fisharebest\Webtrees\Census\CensusColumnMarriedWithinYear
141     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
142     *
143     * @return void
144     */
145    public function testNoSpouseFamily(): void
146    {
147        $individual = Mockery::mock(Individual::class);
148        $individual->shouldReceive('spouseFamilies')->andReturn(new Collection());
149
150        $census = Mockery::mock(CensusInterface::class);
151        $census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
152
153        $column = new CensusColumnMarriedWithinYear($census, '', '');
154
155        $this->assertSame('', $column->generate($individual, $individual));
156    }
157}
158