xref: /webtrees/tests/app/Census/CensusColumnConditionUsTest.php (revision db3aeb3eb846bb233f34557aedb1559aadf9275a)
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;
25
26/**
27 * Test harness for the class CensusColumnConditionUs
28 */
29class CensusColumnConditionUsTest extends \Fisharebest\Webtrees\TestCase
30{
31    /**
32     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
33     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
34     *
35     * @return void
36     */
37    public function testNoSpouseFamiliesMale(): void
38    {
39        $individual = $this->createMock(Individual::class);
40        $individual->method('sex')->willReturn('M');
41        $individual->method('spouseFamilies')->willReturn(new Collection());
42        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
43
44        $census = $this->createMock(CensusInterface::class);
45        $census->method('censusDate')->willReturn('30 JUN 1830');
46
47        $column = new CensusColumnConditionUs($census, '', '');
48
49        $this->assertSame('S', $column->generate($individual, $individual));
50    }
51
52    /**
53     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
54     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
55     *
56     * @return void
57     */
58    public function testNoSpouseFamiliesFemale(): void
59    {
60        $individual = $this->createMock(Individual::class);
61        $individual->method('sex')->willReturn('F');
62        $individual->method('spouseFamilies')->willReturn(new Collection());
63        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
64
65        $census = $this->createMock(CensusInterface::class);
66        $census->method('censusDate')->willReturn('30 JUN 1830');
67
68        $column = new CensusColumnConditionUs($census, '', '');
69
70        $this->assertSame('S', $column->generate($individual, $individual));
71    }
72
73    /**
74     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
75     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
76     *
77     * @return void
78     */
79    public function testNoFamilyFactsMale(): void
80    {
81        $family = $this->createMock(Family::class);
82        $family->method('getMarriageDate')->willReturn(new Date(''));
83        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
84
85        $individual = $this->createMock(Individual::class);
86        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
87        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
88        $individual->method('sex')->willReturn('M');
89
90        $census = $this->createMock(CensusInterface::class);
91
92        $column = new CensusColumnConditionUs($census, '', '');
93        $census->method('censusDate')->willReturn('30 JUN 1830');
94
95        $this->assertSame('S', $column->generate($individual, $individual));
96    }
97
98    /**
99     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
100     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
101     *
102     * @return void
103     */
104    public function testNoFamilyFactsFemale(): void
105    {
106        $family = $this->createMock(Family::class);
107        $family->method('getMarriageDate')->willReturn(new Date(''));
108        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
109
110        $individual = $this->createMock(Individual::class);
111        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
112        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
113        $individual->method('sex')->willReturn('F');
114
115        $census = $this->createMock(CensusInterface::class);
116
117        $column = new CensusColumnConditionUs($census, '', '');
118        $census->method('censusDate')->willReturn('30 JUN 1830');
119
120        $this->assertSame('S', $column->generate($individual, $individual));
121    }
122
123    /**
124     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
125     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
126     *
127     * @return void
128     */
129    public function testSpouseDeadMale(): void
130    {
131        $fact = $this->createMock(Fact::class);
132
133        $spouse = $this->createMock(Individual::class);
134        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
135
136        $family = $this->createMock(Family::class);
137        $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date(''));
138        $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact]));
139        $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection());
140        $family->expects($this->at(3))->method('spouse')->willReturn($spouse);
141
142        $individual = $this->createMock(Individual::class);
143        $individual->method('sex')->willReturn('M');
144        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
145
146        $census = $this->createMock(CensusInterface::class);
147
148        $column = new CensusColumnConditionUs($census, '', '');
149        $census->method('censusDate')->willReturn('30 JUN 1830');
150
151        $this->assertSame('W', $column->generate($individual, $individual));
152    }
153
154    /**
155     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
156     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
157     *
158     * @return void
159     */
160    public function testSpouseDeadFemale(): void
161    {
162        $fact = $this->createMock(Fact::class);
163
164        $spouse = $this->createMock(Individual::class);
165        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
166
167        $family = $this->createMock(Family::class);
168        $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date(''));
169        $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact]));
170        $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection());
171        $family->expects($this->at(3))->method('spouse')->willReturn($spouse);
172
173        $individual = $this->createMock(Individual::class);
174        $individual->method('sex')->willReturn('F');
175        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
176
177        $census = $this->createMock(CensusInterface::class);
178
179        $column = new CensusColumnConditionUs($census, '', '');
180        $census->method('censusDate')->willReturn('30 JUN 1830');
181
182        $this->assertSame('W', $column->generate($individual, $individual));
183    }
184
185    /**
186     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
187     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
188     *
189     * @return void
190     */
191    public function testNoFamilyUnmarriedMale(): void
192    {
193        $family = $this->createMock(Family::class);
194        $family->method('getMarriageDate')->willReturn(new Date(''));
195        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
196
197        $individual = $this->createMock(Individual::class);
198        $individual->method('sex')->willReturn('M');
199        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
200        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
201
202        $census = $this->createMock(CensusInterface::class);
203        $census->method('censusDate')->willReturn('30 JUN 1830');
204
205        $column = new CensusColumnConditionUs($census, '', '');
206
207        $this->assertSame('S', $column->generate($individual, $individual));
208    }
209
210    /**
211     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
212     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
213     *
214     * @return void
215     */
216    public function testNoFamilyUnmarriedFemale(): void
217    {
218        $family = $this->createMock(Family::class);
219        $family->method('getMarriageDate')->willReturn(new Date(''));
220        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
221
222        $individual = $this->createMock(Individual::class);
223        $individual->method('sex')->willReturn('F');
224        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
225        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
226
227        $census = $this->createMock(CensusInterface::class);
228        $census->method('censusDate')->willReturn('30 JUN 1830');
229
230        $column = new CensusColumnConditionUs($census, '', '');
231
232        $this->assertSame('S', $column->generate($individual, $individual));
233    }
234
235    /**
236     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
237     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
238     *
239     * @return void
240     */
241    public function testChildMale(): void
242    {
243        $family = $this->createMock(Family::class);
244        $family->method('getMarriageDate')->willReturn(new Date(''));
245        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
246
247        $individual = $this->createMock(Individual::class);
248        $individual->method('sex')->willReturn('M');
249        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
250        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
251
252        $census = $this->createMock(CensusInterface::class);
253        $census->method('censusDate')->willReturn('30 JUN 1830');
254
255        $column = new CensusColumnConditionUs($census, '', '');
256
257        $this->assertSame('S', $column->generate($individual, $individual));
258    }
259
260    /**
261     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
262     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
263     *
264     * @return void
265     */
266    public function testChildFemale(): void
267    {
268        $family = $this->createMock(Family::class);
269        $family->method('getMarriageDate')->willReturn(new Date(''));
270        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
271
272        $individual = $this->createMock(Individual::class);
273        $individual->method('sex')->willReturn('F');
274        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
275        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
276
277        $census = $this->createMock(CensusInterface::class);
278        $census->method('censusDate')->willReturn('30 JUN 1830');
279
280        $column = new CensusColumnConditionUs($census, '', '');
281
282        $this->assertSame('S', $column->generate($individual, $individual));
283    }
284
285    /**
286     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
287     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
288     *
289     * @return void
290     */
291    public function testDivorcedMale(): void
292    {
293        $fact = $this->createMock(Fact::class);
294
295        $family = $this->createMock(Family::class);
296        $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date(''));
297        $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact]));
298        $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection([$fact]));
299
300        $individual = $this->createMock(Individual::class);
301        $individual->method('sex')->willReturn('M');
302        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
303
304        $census = $this->createMock(CensusInterface::class);
305
306        $column = new CensusColumnConditionUs($census, '', '');
307        $census->method('censusDate')->willReturn('30 JUN 1830');
308
309        $this->assertSame('D', $column->generate($individual, $individual));
310    }
311
312    /**
313     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionUs
314     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
315     *
316     * @return void
317     */
318    public function testDivorcedFemale(): void
319    {
320        $fact = $this->createMock(Fact::class);
321
322        $family = $this->createMock(Family::class);
323        $family->expects($this->at(0))->method('getMarriageDate')->willReturn(new Date(''));
324        $family->expects($this->at(1))->method('facts')->with(['MARR'])->willReturn(new Collection([$fact]));
325        $family->expects($this->at(2))->method('facts')->with(['DIV'])->willReturn(new Collection([$fact]));
326
327        $individual = $this->createMock(Individual::class);
328        $individual->method('sex')->willReturn('F');
329        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
330
331        $census = $this->createMock(CensusInterface::class);
332
333        $column = new CensusColumnConditionUs($census, '', '');
334        $census->method('censusDate')->willReturn('30 JUN 1830');
335
336        $this->assertSame('D', $column->generate($individual, $individual));
337    }
338}
339