xref: /webtrees/tests/app/Census/CensusColumnConditionCanadaMarriedWidowedTest.php (revision 059898c926a4478bc49a5a58f1ac1c58d0ea796d)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Census;
21
22use Fisharebest\Webtrees\Date;
23use Fisharebest\Webtrees\Fact;
24use Fisharebest\Webtrees\Family;
25use Fisharebest\Webtrees\Individual;
26use Fisharebest\Webtrees\TestCase;
27use Illuminate\Support\Collection;
28
29/**
30 * Test harness for the class CensusColumnConditionCanadaMarriedWidowed
31 */
32class CensusColumnConditionCanadaMarriedWidowedTest extends TestCase
33{
34    /**
35     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
36     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
37     *
38     * @return void
39     */
40    public function testNoSpouseFamiliesMale(): void
41    {
42        $individual = $this->createMock(Individual::class);
43        $individual->method('sex')->willReturn('M');
44        $individual->method('spouseFamilies')->willReturn(new Collection());
45        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
46
47        $census = $this->createMock(CensusInterface::class);
48        $census->method('censusDate')->willReturn('30 JUN 1830');
49
50        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
51
52        self::assertSame('', $column->generate($individual, $individual));
53    }
54
55    /**
56     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
57     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
58     *
59     * @return void
60     */
61    public function testNoSpouseFamiliesFemale(): void
62    {
63        $individual = $this->createMock(Individual::class);
64        $individual->method('sex')->willReturn('F');
65        $individual->method('spouseFamilies')->willReturn(new Collection());
66        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
67
68        $census = $this->createMock(CensusInterface::class);
69        $census->method('censusDate')->willReturn('30 JUN 1830');
70
71        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
72
73        self::assertSame('', $column->generate($individual, $individual));
74    }
75
76    /**
77     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
78     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
79     *
80     * @return void
81     */
82    public function testNoFamilyFactsMale(): void
83    {
84        $family = $this->createMock(Family::class);
85        $family->method('getMarriageDate')->willReturn(new Date(''));
86        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
87
88        $individual = $this->createMock(Individual::class);
89        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
90        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
91        $individual->method('sex')->willReturn('M');
92
93        $census = $this->createMock(CensusInterface::class);
94
95        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
96        $census->method('censusDate')->willReturn('30 JUN 1830');
97
98        self::assertSame('', $column->generate($individual, $individual));
99    }
100
101    /**
102     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
103     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
104     *
105     * @return void
106     */
107    public function testNoFamilyFactsFemale(): void
108    {
109        $family = $this->createMock(Family::class);
110        $family->method('getMarriageDate')->willReturn(new Date(''));
111        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
112
113        $individual = $this->createMock(Individual::class);
114        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
115        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
116        $individual->method('sex')->willReturn('F');
117
118        $census = $this->createMock(CensusInterface::class);
119
120        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
121        $census->method('censusDate')->willReturn('30 JUN 1830');
122
123        self::assertSame('', $column->generate($individual, $individual));
124    }
125
126    /**
127     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
128     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
129     *
130     * @return void
131     */
132    public function testSpouseDeadMale(): void
133    {
134        $fact = $this->createMock(Fact::class);
135
136        $spouse = $this->createMock(Individual::class);
137        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
138
139        $family = $this->createMock(Family::class);
140        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
141        $family->expects(self::exactly(2))
142            ->method('facts')
143            ->with(self::withConsecutive([['MARR'], ['DIV']]))
144            ->willReturnOnConsecutiveCalls(
145                new Collection([$fact]),
146                new Collection()
147            );
148        $family->expects(self::once())->method('spouse')->willReturn($spouse);
149
150        $individual = $this->createMock(Individual::class);
151        $individual->method('sex')->willReturn('M');
152        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
153
154        $census = $this->createMock(CensusInterface::class);
155
156        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
157        $census->method('censusDate')->willReturn('30 JUN 1830');
158
159        self::assertSame('W', $column->generate($individual, $individual));
160    }
161
162    /**
163     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
164     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
165     *
166     * @return void
167     */
168    public function testSpouseDeadFemale(): void
169    {
170        $fact = $this->createMock(Fact::class);
171
172        $spouse = $this->createMock(Individual::class);
173        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
174
175        $family = $this->createMock(Family::class);
176        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
177        $family
178            ->expects(self::exactly(2))
179            ->method('facts')
180            ->with(self::withConsecutive([['MARR'], ['DIV']]))
181            ->willReturnOnConsecutiveCalls(
182                new Collection([$fact]),
183                new Collection()
184            );
185        $family->expects(self::once())->method('spouse')->willReturn($spouse);
186
187        $individual = $this->createMock(Individual::class);
188        $individual->method('sex')->willReturn('F');
189        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
190
191        $census = $this->createMock(CensusInterface::class);
192
193        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
194        $census->method('censusDate')->willReturn('30 JUN 1830');
195
196        self::assertSame('W', $column->generate($individual, $individual));
197    }
198
199    /**
200     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
201     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
202     *
203     * @return void
204     */
205    public function testNoFamilyUnmarriedMale(): void
206    {
207        $family = $this->createMock(Family::class);
208        $family->method('getMarriageDate')->willReturn(new Date(''));
209        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
210
211        $individual = $this->createMock(Individual::class);
212        $individual->method('sex')->willReturn('M');
213        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
214        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
215
216        $census = $this->createMock(CensusInterface::class);
217        $census->method('censusDate')->willReturn('30 JUN 1830');
218
219        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
220
221        self::assertSame('', $column->generate($individual, $individual));
222    }
223
224    /**
225     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
226     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
227     *
228     * @return void
229     */
230    public function testNoFamilyUnmarriedFemale(): void
231    {
232        $family = $this->createMock(Family::class);
233        $family->method('getMarriageDate')->willReturn(new Date(''));
234        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
235
236        $individual = $this->createMock(Individual::class);
237        $individual->method('sex')->willReturn('F');
238        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
239        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
240
241        $census = $this->createMock(CensusInterface::class);
242        $census->method('censusDate')->willReturn('30 JUN 1830');
243
244        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
245
246        self::assertSame('', $column->generate($individual, $individual));
247    }
248
249    /**
250     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
251     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
252     *
253     * @return void
254     */
255    public function testChildMale(): void
256    {
257        $family = $this->createMock(Family::class);
258        $family->method('getMarriageDate')->willReturn(new Date(''));
259        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
260
261        $individual = $this->createMock(Individual::class);
262        $individual->method('sex')->willReturn('M');
263        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
264        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
265
266        $census = $this->createMock(CensusInterface::class);
267        $census->method('censusDate')->willReturn('30 JUN 1830');
268
269        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
270
271        self::assertSame('', $column->generate($individual, $individual));
272    }
273
274    /**
275     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
276     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
277     *
278     * @return void
279     */
280    public function testChildFemale(): void
281    {
282        $family = $this->createMock(Family::class);
283        $family->method('getMarriageDate')->willReturn(new Date(''));
284        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
285
286        $individual = $this->createMock(Individual::class);
287        $individual->method('sex')->willReturn('F');
288        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
289        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
290
291        $census = $this->createMock(CensusInterface::class);
292        $census->method('censusDate')->willReturn('30 JUN 1830');
293
294        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
295
296        self::assertSame('', $column->generate($individual, $individual));
297    }
298
299    /**
300     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
301     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
302     *
303     * @return void
304     */
305    public function testDivorcedMale(): void
306    {
307        $fact = $this->createMock(Fact::class);
308
309        $family = $this->createMock(Family::class);
310        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
311        $family
312            ->expects(self::exactly(2))
313            ->method('facts')
314            ->with(self::withConsecutive([['MARR'], ['DIV']]))
315            ->willReturnOnConsecutiveCalls(
316                new Collection([$fact]),
317                new Collection([$fact])
318            );
319
320        $individual = $this->createMock(Individual::class);
321        $individual->method('sex')->willReturn('M');
322        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
323
324        $census = $this->createMock(CensusInterface::class);
325
326        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
327        $census->method('censusDate')->willReturn('30 JUN 1830');
328
329        self::assertSame('', $column->generate($individual, $individual));
330    }
331
332    /**
333     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
334     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
335     *
336     * @return void
337     */
338    public function testDivorcedFemale(): void
339    {
340        $fact = $this->createMock(Fact::class);
341
342        $family = $this->createMock(Family::class);
343        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
344        $family
345            ->expects(self::exactly(2))
346            ->method('facts')
347            ->with(self::withConsecutive([['MARR'], ['DIV']]))
348            ->willReturnOnConsecutiveCalls(
349                new Collection([$fact]),
350                new Collection([$fact])
351            );
352
353        $individual = $this->createMock(Individual::class);
354        $individual->method('sex')->willReturn('F');
355        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
356
357        $census = $this->createMock(CensusInterface::class);
358
359        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
360        $census->method('censusDate')->willReturn('30 JUN 1830');
361
362        self::assertSame('', $column->generate($individual, $individual));
363    }
364
365    /**
366     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
367     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
368     *
369     * @return void
370     */
371    public function testMarriedMale(): void
372    {
373        $fact = $this->createMock(Fact::class);
374
375        $family = $this->createMock(Family::class);
376        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
377        $family
378            ->expects(self::exactly(2))
379            ->method('facts')
380            ->with(self::withConsecutive([['MARR'], ['DIV']]))
381            ->willReturnOnConsecutiveCalls(
382                new Collection([$fact]),
383                new Collection()
384            );
385
386        $individual = $this->createMock(Individual::class);
387        $individual->method('sex')->willReturn('M');
388        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
389
390        $census = $this->createMock(CensusInterface::class);
391
392        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
393        $census->method('censusDate')->willReturn('30 JUN 1830');
394
395        self::assertSame('M', $column->generate($individual, $individual));
396    }
397
398    /**
399     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanadaMarriedWidowed
400     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
401     *
402     * @return void
403     */
404    public function testMarriedFemale(): void
405    {
406        $fact = $this->createMock(Fact::class);
407
408        $family = $this->createMock(Family::class);
409        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
410        $family
411            ->expects(self::exactly(2))
412            ->method('facts')
413            ->with(self::withConsecutive([['MARR'], ['DIV']]))
414            ->willReturnOnConsecutiveCalls(
415                new Collection([$fact]),
416                new Collection()
417            );
418
419        $individual = $this->createMock(Individual::class);
420        $individual->method('sex')->willReturn('F');
421        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
422
423        $census = $this->createMock(CensusInterface::class);
424
425        $column = new CensusColumnConditionCanadaMarriedWidowed($census, '', '');
426        $census->method('censusDate')->willReturn('30 JUN 1830');
427
428        self::assertSame('M', $column->generate($individual, $individual));
429    }
430}
431