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