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