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