xref: /webtrees/tests/app/Census/CensusColumnConditionCanadaTest.php (revision b7e8616f5f3bd6f035d5d40dd804283727b5c140)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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            ->withConsecutive(
145                [['MARR']],
146                [['DIV']]
147            )
148            ->willReturnOnConsecutiveCalls(
149                new Collection([$fact]),
150                new Collection()
151            );
152        $family->expects(self::once())->method('spouse')->willReturn($spouse);
153
154        $individual = $this->createMock(Individual::class);
155        $individual->method('sex')->willReturn('M');
156        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
157
158        $census = $this->createMock(CensusInterface::class);
159
160        $column = new CensusColumnConditionCanada($census, '', '');
161        $census->method('censusDate')->willReturn('30 JUN 1830');
162
163        self::assertSame('W', $column->generate($individual, $individual));
164    }
165
166    /**
167     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
168     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
169     *
170     * @return void
171     */
172    public function testSpouseDeadFemale(): void
173    {
174        $fact = $this->createMock(Fact::class);
175
176        $spouse = $this->createMock(Individual::class);
177        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
178
179        $family = $this->createMock(Family::class);
180        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
181        $family
182            ->expects(self::exactly(2))
183            ->method('facts')
184            ->withConsecutive(
185                [['MARR']],
186                [['DIV']]
187            )
188            ->willReturnOnConsecutiveCalls(
189                new Collection([$fact]),
190                new Collection()
191            );
192        $family->expects(self::once())->method('spouse')->willReturn($spouse);
193
194        $individual = $this->createMock(Individual::class);
195        $individual->method('sex')->willReturn('F');
196        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
197
198        $census = $this->createMock(CensusInterface::class);
199
200        $column = new CensusColumnConditionCanada($census, '', '');
201        $census->method('censusDate')->willReturn('30 JUN 1830');
202
203        self::assertSame('W', $column->generate($individual, $individual));
204    }
205
206    /**
207     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
208     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
209     *
210     * @return void
211     */
212    public function testNoFamilyUnmarriedMale(): void
213    {
214        $family = $this->createMock(Family::class);
215        $family->method('getMarriageDate')->willReturn(new Date(''));
216        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
217
218        $individual = $this->createMock(Individual::class);
219        $individual->method('sex')->willReturn('M');
220        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
221        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
222
223        $census = $this->createMock(CensusInterface::class);
224        $census->method('censusDate')->willReturn('30 JUN 1830');
225
226        $column = new CensusColumnConditionCanada($census, '', '');
227
228        self::assertSame('S', $column->generate($individual, $individual));
229    }
230
231    /**
232     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
233     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
234     *
235     * @return void
236     */
237    public function testNoFamilyUnmarriedFemale(): 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('F');
245        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
246        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
247
248        $census = $this->createMock(CensusInterface::class);
249        $census->method('censusDate')->willReturn('30 JUN 1830');
250
251        $column = new CensusColumnConditionCanada($census, '', '');
252
253        self::assertSame('S', $column->generate($individual, $individual));
254    }
255
256    /**
257     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
258     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
259     *
260     * @return void
261     */
262    public function testChildMale(): void
263    {
264        $family = $this->createMock(Family::class);
265        $family->method('getMarriageDate')->willReturn(new Date(''));
266        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
267
268        $individual = $this->createMock(Individual::class);
269        $individual->method('sex')->willReturn('M');
270        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
271        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
272
273        $census = $this->createMock(CensusInterface::class);
274        $census->method('censusDate')->willReturn('30 JUN 1830');
275
276        $column = new CensusColumnConditionCanada($census, '', '');
277
278        self::assertSame('S', $column->generate($individual, $individual));
279    }
280
281    /**
282     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
283     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
284     *
285     * @return void
286     */
287    public function testChildFemale(): void
288    {
289        $family = $this->createMock(Family::class);
290        $family->method('getMarriageDate')->willReturn(new Date(''));
291        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
292
293        $individual = $this->createMock(Individual::class);
294        $individual->method('sex')->willReturn('F');
295        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
296        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1820'));
297
298        $census = $this->createMock(CensusInterface::class);
299        $census->method('censusDate')->willReturn('30 JUN 1830');
300
301        $column = new CensusColumnConditionCanada($census, '', '');
302
303        self::assertSame('S', $column->generate($individual, $individual));
304    }
305
306    /**
307     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
308     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
309     *
310     * @return void
311     */
312    public function testDivorcedMale(): void
313    {
314        $fact = $this->createMock(Fact::class);
315
316        $family = $this->createMock(Family::class);
317        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
318        $family
319            ->expects(self::exactly(2))
320            ->method('facts')
321            ->withConsecutive(
322                [['MARR']],
323                [['DIV']]
324            )->willReturnOnConsecutiveCalls(
325                new Collection([$fact]),
326                new Collection([$fact])
327            );
328
329        $individual = $this->createMock(Individual::class);
330        $individual->method('sex')->willReturn('M');
331        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
332
333        $census = $this->createMock(CensusInterface::class);
334
335        $column = new CensusColumnConditionCanada($census, '', '');
336        $census->method('censusDate')->willReturn('30 JUN 1830');
337
338        self::assertSame('D', $column->generate($individual, $individual));
339    }
340
341    /**
342     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
343     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
344     *
345     * @return void
346     */
347    public function testDivorcedFemale(): void
348    {
349        $fact = $this->createMock(Fact::class);
350
351        $family = $this->createMock(Family::class);
352        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
353        $family
354            ->expects(self::exactly(2))
355            ->method('facts')
356            ->withConsecutive(
357                [['MARR']],
358                [['DIV']]
359            )->willReturnOnConsecutiveCalls(
360                new Collection([$fact]),
361                new Collection([$fact])
362            );
363
364        $individual = $this->createMock(Individual::class);
365        $individual->method('sex')->willReturn('F');
366        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
367
368        $census = $this->createMock(CensusInterface::class);
369
370        $column = new CensusColumnConditionCanada($census, '', '');
371        $census->method('censusDate')->willReturn('30 JUN 1830');
372
373        self::assertSame('D', $column->generate($individual, $individual));
374    }
375
376    /**
377     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
378     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
379     *
380     * @return void
381     */
382    public function testMarriedMale(): void
383    {
384        $fact = $this->createMock(Fact::class);
385
386        $family = $this->createMock(Family::class);
387        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
388        $family
389            ->expects(self::exactly(2))
390            ->method('facts')
391            ->withConsecutive(
392                [['MARR']],
393                [['DIV']]
394            )->willReturnOnConsecutiveCalls(
395                new Collection([$fact]),
396                new Collection()
397            );
398
399        $individual = $this->createMock(Individual::class);
400        $individual->method('sex')->willReturn('M');
401        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
402
403        $census = $this->createMock(CensusInterface::class);
404
405        $column = new CensusColumnConditionCanada($census, '', '');
406        $census->method('censusDate')->willReturn('30 JUN 1830');
407
408        self::assertSame('M', $column->generate($individual, $individual));
409    }
410
411    /**
412     * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionCanada
413     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition
414     *
415     * @return void
416     */
417    public function testMarriedFemale(): void
418    {
419        $fact = $this->createMock(Fact::class);
420
421        $family = $this->createMock(Family::class);
422        $family->expects(self::once())->method('getMarriageDate')->willReturn(new Date(''));
423        $family
424            ->expects(self::exactly(2))
425            ->method('facts')
426            ->withConsecutive(
427                [['MARR']],
428                [['DIV']]
429            )->willReturnOnConsecutiveCalls(
430                new Collection([$fact]),
431                new Collection()
432            );
433
434        $individual = $this->createMock(Individual::class);
435        $individual->method('sex')->willReturn('F');
436        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
437
438        $census = $this->createMock(CensusInterface::class);
439
440        $column = new CensusColumnConditionCanada($census, '', '');
441        $census->method('censusDate')->willReturn('30 JUN 1830');
442
443        self::assertSame('M', $column->generate($individual, $individual));
444    }
445}
446