xref: /webtrees/tests/app/Census/CensusColumnYearsMarriedTest.php (revision 7338314f5c633aee8dc624b41c8275e3e2dbe938)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2015 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
18namespace Fisharebest\Webtrees\Census;
19
20use Fisharebest\Localization\Translator;
21use Fisharebest\Webtrees\Date;
22use Fisharebest\Webtrees\Fact;
23use Fisharebest\Webtrees\Family;
24use Fisharebest\Webtrees\I18N;
25use Fisharebest\Webtrees\Individual;
26use Mockery;
27
28/**
29 * Test harness for the class CensusColumnYearsMarried
30 */
31class CensusColumnYearsMarriedTest extends \PHPUnit_Framework_TestCase {
32	/**
33	 * Delete mock objects
34	 */
35	public function tearDown() {
36		Mockery::close();
37	}
38
39	/**
40	 * @covers Fisharebest\Webtrees\Census\CensusColumnYearsMarried
41	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
42	 */
43	public function testNoSpouseFamily() {
44		$individual = Mockery::mock(Individual::class);
45		$individual->shouldReceive('getSpouseFamilies')->andReturn([]);
46
47		$census = Mockery::mock(CensusInterface::class);
48		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
49
50		$column = new CensusColumnYearsMarried($census, '', '');
51
52		$this->assertSame('', $column->generate($individual));
53	}
54
55	/**
56	 * @covers Fisharebest\Webtrees\Census\CensusColumnYearsMarried
57	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
58	 */
59	public function testNoMarriage() {
60		$family = Mockery::mock(Family::class);
61		$family->shouldReceive('getFacts')->with('MARR', true)->andReturn([]);
62
63		$individual = Mockery::mock(Individual::class);
64		$individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
65
66		$census = Mockery::mock(CensusInterface::class);
67		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
68
69		$column = new CensusColumnYearsMarried($census, '', '');
70
71		$this->assertSame('', $column->generate($individual));
72	}
73
74	/**
75	 * @covers Fisharebest\Webtrees\Census\CensusColumnYearsMarried
76	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
77	 */
78	public function testUndatedMarriage() {
79		$fact = Mockery::mock(Fact::class);
80		$fact->shouldReceive('getDate')->andReturn(new Date(''));
81
82		$family = Mockery::mock(Family::class);
83		$family->shouldReceive('getFacts')->with('MARR', true)->andReturn([$fact]);
84
85		$individual = Mockery::mock(Individual::class);
86		$individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
87
88		$census = Mockery::mock(CensusInterface::class);
89		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
90
91		$column = new CensusColumnYearsMarried($census, '', '');
92
93		$this->assertSame('', $column->generate($individual));
94	}
95
96	/**
97	 * @covers Fisharebest\Webtrees\Census\CensusColumnYearsMarried
98	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
99	 */
100	public function testMarriageAfterCensus() {
101		$fact = Mockery::mock(Fact::class);
102		$fact->shouldReceive('getDate')->andReturn(new Date('1861'));
103
104		$family = Mockery::mock(Family::class);
105		$family->shouldReceive('getFacts')->with('MARR', true)->andReturn([$fact]);
106
107		$individual = Mockery::mock(Individual::class);
108		$individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
109
110		$census = Mockery::mock(CensusInterface::class);
111		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
112
113		$column = new CensusColumnYearsMarried($census, '', '');
114
115		$this->assertSame('', $column->generate($individual));
116	}
117
118	/**
119	 * @covers Fisharebest\Webtrees\Census\CensusColumnYearsMarried
120	 * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
121	 */
122	public function testMarriageBeforeCensus() {
123		$fact = Mockery::mock(Fact::class);
124		$fact->shouldReceive('getDate')->andReturn(new Date('OCT 1851'));
125
126		$family = Mockery::mock(Family::class);
127		$family->shouldReceive('getFacts')->with('MARR', true)->andReturn([$fact]);
128
129		$individual = Mockery::mock(Individual::class);
130		$individual->shouldReceive('getSpouseFamilies')->andReturn([$family]);
131
132		$census = Mockery::mock(CensusInterface::class);
133		$census->shouldReceive('censusDate')->andReturn('01 JUN 1860');
134
135		$column = new CensusColumnYearsMarried($census, '', '');
136
137		$this->assertSame('8', $column->generate($individual));
138	}
139}
140