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