xref: /webtrees/tests/app/Census/CensusColumnConditionFrenchGarconTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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
31#[CoversClass(CensusColumnConditionFrenchGarcon::class)]
32#[CoversClass(AbstractCensusColumnCondition::class)]
33class CensusColumnConditionFrenchGarconTest extends TestCase
34{
35    public function testNoSpouseFamiliesMale(): void
36    {
37        $individual = $this->createMock(Individual::class);
38        $individual->method('sex')->willReturn('M');
39        $individual->method('spouseFamilies')->willReturn(new Collection());
40        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
41
42        $census = $this->createMock(CensusInterface::class);
43        $census->method('censusDate')->willReturn('30 JUN 1830');
44
45        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
46
47        self::assertSame('1', $column->generate($individual, $individual));
48    }
49
50    public function testNoSpouseFamiliesFemale(): void
51    {
52        $individual = $this->createMock(Individual::class);
53        $individual->method('sex')->willReturn('F');
54        $individual->method('spouseFamilies')->willReturn(new Collection());
55        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
56
57        $census = $this->createMock(CensusInterface::class);
58        $census->method('censusDate')->willReturn('30 JUN 1830');
59
60        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
61
62        self::assertSame('', $column->generate($individual, $individual));
63    }
64
65    public function testNoFamilyFactsMale(): void
66    {
67        $family = $this->createMock(Family::class);
68        $family->method('getMarriageDate')->willReturn(new Date(''));
69        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
70
71        $individual = $this->createMock(Individual::class);
72        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
73        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
74        $individual->method('sex')->willReturn('M');
75
76        $census = $this->createMock(CensusInterface::class);
77
78        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
79        $census->method('censusDate')->willReturn('30 JUN 1830');
80
81        self::assertSame('1', $column->generate($individual, $individual));
82    }
83
84    public function testNoFamilyFactsFemale(): void
85    {
86        $family = $this->createMock(Family::class);
87        $family->method('getMarriageDate')->willReturn(new Date(''));
88        $family->method('facts')->with(['MARR'])->willReturn(new Collection());
89
90        $individual = $this->createMock(Individual::class);
91        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
92        $individual->method('getEstimatedBirthDate')->willReturn(new Date('1800'));
93        $individual->method('sex')->willReturn('F');
94
95        $census = $this->createMock(CensusInterface::class);
96
97        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
98        $census->method('censusDate')->willReturn('30 JUN 1830');
99
100        self::assertSame('', $column->generate($individual, $individual));
101    }
102
103    public function testSpouseDeadMale(): void
104    {
105        $fact = $this->createMock(Fact::class);
106
107        $spouse = $this->createMock(Individual::class);
108        $spouse->method('getDeathDate')->willReturn(new Date('1820'));
109
110        $family = $this->createMock(Family::class);
111        $family
112            ->expects(self::exactly(2))
113            ->method('facts')
114            ->with(self::withConsecutive([['MARR'], ['DIV']]))
115            ->willReturnOnConsecutiveCalls(
116                new Collection([$fact]),
117                new Collection()
118            );
119        $family->expects(self::once())->method('spouse')->willReturn($spouse);
120
121        $individual = $this->createMock(Individual::class);
122        $individual->method('sex')->willReturn('M');
123        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
124
125        $census = $this->createMock(CensusInterface::class);
126
127        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
128        $census->method('censusDate')->willReturn('30 JUN 1830');
129
130        self::assertSame('', $column->generate($individual, $individual));
131    }
132
133    public function testSpouseDeadFemale(): 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
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 CensusColumnConditionFrenchGarcon($census, '', '');
158        $census->method('censusDate')->willReturn('30 JUN 1830');
159
160        self::assertSame('', $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 CensusColumnConditionFrenchGarcon($census, '', '');
178
179        self::assertSame('1', $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 CensusColumnConditionFrenchGarcon($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 CensusColumnConditionFrenchGarcon($census, '', '');
216
217        self::assertSame('1', $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 CensusColumnConditionFrenchGarcon($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
245            ->expects(self::exactly(2))
246            ->method('facts')
247            ->with(self::withConsecutive([['MARR'], ['DIV']]))
248            ->willReturn(
249                new Collection([$fact]),
250                new Collection([$fact])
251            );
252
253        $individual = $this->createMock(Individual::class);
254        $individual->method('sex')->willReturn('M');
255        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
256
257        $census = $this->createMock(CensusInterface::class);
258
259        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
260        $census->method('censusDate')->willReturn('30 JUN 1830');
261
262        self::assertSame('', $column->generate($individual, $individual));
263    }
264
265    public function testDivorcedFemale(): void
266    {
267        $fact = $this->createMock(Fact::class);
268
269        $family = $this->createMock(Family::class);
270        $family
271            ->expects(self::exactly(2))
272            ->method('facts')
273            ->with(self::withConsecutive([['MARR'], ['DIV']]))
274            ->willReturn(
275                new Collection([$fact]),
276                new Collection([$fact])
277            );
278
279        $individual = $this->createMock(Individual::class);
280        $individual->method('sex')->willReturn('F');
281        $individual->method('spouseFamilies')->willReturn(new Collection([$family]));
282
283        $census = $this->createMock(CensusInterface::class);
284
285        $column = new CensusColumnConditionFrenchGarcon($census, '', '');
286        $census->method('censusDate')->willReturn('30 JUN 1830');
287
288        self::assertSame('', $column->generate($individual, $individual));
289    }
290}
291