xref: /webtrees/tests/app/Census/CensusColumnBornForeignPartsTest.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\Individual;
23use Fisharebest\Webtrees\Place;
24use Fisharebest\Webtrees\TestCase;
25use Illuminate\Support\Collection;
26use PHPUnit\Framework\Attributes\CoversClass;
27
28
29#[CoversClass(CensusColumnBornForeignParts::class)]
30#[CoversClass(AbstractCensusColumn::class)]
31class CensusColumnBornForeignPartsTest extends TestCase
32{
33    private function getPlaceMock(string $place): Place
34    {
35        $placeParts = explode(', ', $place);
36
37        $placeMock = $this->createMock(Place::class);
38        $placeMock->method('gedcomName')->willReturn($place);
39        $placeMock->method('lastParts')->willReturn((new Collection($placeParts))->slice(-1));
40
41        return $placeMock;
42    }
43
44    public function testBornEnglandCensusEngland(): void
45    {
46        $individual = $this->createMock(Individual::class);
47        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
48
49        $census = $this->createMock(CensusInterface::class);
50        $census->method('censusPlace')->willReturn('England');
51
52        $column = new CensusColumnBornForeignParts($census, '', '');
53
54        self::assertSame('', $column->generate($individual, $individual));
55    }
56
57    public function testBornWalesCensusEngland(): void
58    {
59        $individual = $this->createMock(Individual::class);
60        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales'));
61
62        $census = $this->createMock(CensusInterface::class);
63        $census->method('censusPlace')->willReturn('England');
64
65        $column = new CensusColumnBornForeignParts($census, '', '');
66
67        self::assertSame('', $column->generate($individual, $individual));
68    }
69
70    public function testBornScotlandCensusEngland(): void
71    {
72        $individual = $this->createMock(Individual::class);
73        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland'));
74
75        $census = $this->createMock(CensusInterface::class);
76        $census->method('censusPlace')->willReturn('England');
77
78        $column = new CensusColumnBornForeignParts($census, '', '');
79
80        self::assertSame('S', $column->generate($individual, $individual));
81    }
82
83    public function testBornIrelandCensusEngland(): void
84    {
85        $individual = $this->createMock(Individual::class);
86        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland'));
87
88        $census = $this->createMock(CensusInterface::class);
89        $census->method('censusPlace')->willReturn('England');
90
91        $column = new CensusColumnBornForeignParts($census, '', '');
92
93        self::assertSame('I', $column->generate($individual, $individual));
94    }
95
96    public function testBornForeignCensusEngland(): void
97    {
98        $individual = $this->createMock(Individual::class);
99        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia'));
100
101        $census = $this->createMock(CensusInterface::class);
102        $census->method('censusPlace')->willReturn('England');
103
104        $column = new CensusColumnBornForeignParts($census, '', '');
105
106        self::assertSame('F', $column->generate($individual, $individual));
107    }
108
109    public function testBornEnglandCensusIreland(): void
110    {
111        $individual = $this->createMock(Individual::class);
112        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
113
114        $census = $this->createMock(CensusInterface::class);
115        $census->method('censusPlace')->willReturn('Ireland');
116
117        $column = new CensusColumnBornForeignParts($census, '', '');
118
119        self::assertSame('E', $column->generate($individual, $individual));
120    }
121
122    public function testBornWalesCensusIreland(): void
123    {
124        $individual = $this->createMock(Individual::class);
125        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales'));
126
127        $census = $this->createMock(CensusInterface::class);
128        $census->method('censusPlace')->willReturn('Ireland');
129
130        $column = new CensusColumnBornForeignParts($census, '', '');
131
132        self::assertSame('E', $column->generate($individual, $individual));
133    }
134
135    public function testBornScotlandCensusIreland(): void
136    {
137        $individual = $this->createMock(Individual::class);
138        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland'));
139
140        $census = $this->createMock(CensusInterface::class);
141        $census->method('censusPlace')->willReturn('Ireland');
142
143        $column = new CensusColumnBornForeignParts($census, '', '');
144
145        self::assertSame('S', $column->generate($individual, $individual));
146    }
147
148    public function testBornIrelandCensusIreland(): void
149    {
150        $individual = $this->createMock(Individual::class);
151        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland'));
152
153        $census = $this->createMock(CensusInterface::class);
154        $census->method('censusPlace')->willReturn('Ireland');
155
156        $column = new CensusColumnBornForeignParts($census, '', '');
157
158        self::assertSame('', $column->generate($individual, $individual));
159    }
160
161    public function testBornForeignCensusIreland(): void
162    {
163        $individual = $this->createMock(Individual::class);
164        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia'));
165
166        $census = $this->createMock(CensusInterface::class);
167        $census->method('censusPlace')->willReturn('Ireland');
168
169        $column = new CensusColumnBornForeignParts($census, '', '');
170
171        self::assertSame('F', $column->generate($individual, $individual));
172    }
173
174    public function testBornEnglandCensusScotland(): void
175    {
176        $individual = $this->createMock(Individual::class);
177        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
178
179        $census = $this->createMock(CensusInterface::class);
180        $census->method('censusPlace')->willReturn('Scotland');
181
182        $column = new CensusColumnBornForeignParts($census, '', '');
183
184        self::assertSame('E', $column->generate($individual, $individual));
185    }
186
187    public function testBornWalesCensusScotland(): void
188    {
189        $individual = $this->createMock(Individual::class);
190        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales'));
191
192        $census = $this->createMock(CensusInterface::class);
193        $census->method('censusPlace')->willReturn('Scotland');
194
195        $column = new CensusColumnBornForeignParts($census, '', '');
196
197        self::assertSame('E', $column->generate($individual, $individual));
198    }
199
200    public function testBornScotlandCensusScotland(): void
201    {
202        $individual = $this->createMock(Individual::class);
203        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland'));
204
205        $census = $this->createMock(CensusInterface::class);
206        $census->method('censusPlace')->willReturn('Scotland');
207
208        $column = new CensusColumnBornForeignParts($census, '', '');
209
210        self::assertSame('', $column->generate($individual, $individual));
211    }
212
213    public function testBornIrelandCensusScotland(): void
214    {
215        $individual = $this->createMock(Individual::class);
216        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland'));
217
218        $census = $this->createMock(CensusInterface::class);
219        $census->method('censusPlace')->willReturn('Scotland');
220
221        $column = new CensusColumnBornForeignParts($census, '', '');
222
223        self::assertSame('I', $column->generate($individual, $individual));
224    }
225
226    public function testBornForeignCensusScotland(): void
227    {
228        $individual = $this->createMock(Individual::class);
229        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia'));
230
231        $census = $this->createMock(CensusInterface::class);
232        $census->method('censusPlace')->willReturn('Scotland');
233
234        $column = new CensusColumnBornForeignParts($census, '', '');
235
236        self::assertSame('F', $column->generate($individual, $individual));
237    }
238
239    public function testBornEnglandCensusWales(): void
240    {
241        $individual = $this->createMock(Individual::class);
242        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('London, England'));
243
244        $census = $this->createMock(CensusInterface::class);
245        $census->method('censusPlace')->willReturn('Wales');
246
247        $column = new CensusColumnBornForeignParts($census, '', '');
248
249        self::assertSame('', $column->generate($individual, $individual));
250    }
251
252    public function testBornWalesCensusWales(): void
253    {
254        $individual = $this->createMock(Individual::class);
255        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Cardiff, Wales'));
256
257        $census = $this->createMock(CensusInterface::class);
258        $census->method('censusPlace')->willReturn('Wales');
259
260        $column = new CensusColumnBornForeignParts($census, '', '');
261
262        self::assertSame('', $column->generate($individual, $individual));
263    }
264
265    public function testBornScotlandCensusWales(): void
266    {
267        $individual = $this->createMock(Individual::class);
268        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Edinburgh, Scotland'));
269
270        $census = $this->createMock(CensusInterface::class);
271        $census->method('censusPlace')->willReturn('Wales');
272
273        $column = new CensusColumnBornForeignParts($census, '', '');
274
275        self::assertSame('S', $column->generate($individual, $individual));
276    }
277
278    public function testBornIrelandCensusWales(): void
279    {
280        $individual = $this->createMock(Individual::class);
281        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Dublin, Ireland'));
282
283        $census = $this->createMock(CensusInterface::class);
284        $census->method('censusPlace')->willReturn('Wales');
285
286        $column = new CensusColumnBornForeignParts($census, '', '');
287
288        self::assertSame('I', $column->generate($individual, $individual));
289    }
290
291    public function testBornForeignCensusWales(): void
292    {
293        $individual = $this->createMock(Individual::class);
294        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock('Elbonia'));
295
296        $census = $this->createMock(CensusInterface::class);
297        $census->method('censusPlace')->willReturn('Wales');
298
299        $column = new CensusColumnBornForeignParts($census, '', '');
300
301        self::assertSame('F', $column->generate($individual, $individual));
302    }
303
304    public function testBornNowhereCensusEngland(): void
305    {
306        $individual = $this->createMock(Individual::class);
307        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock(''));
308
309        $census = $this->createMock(CensusInterface::class);
310        $census->method('censusPlace')->willReturn('England');
311
312        $column = new CensusColumnBornForeignParts($census, '', '');
313
314        self::assertSame('', $column->generate($individual, $individual));
315    }
316
317    public function testBornNowhereCensusWales(): void
318    {
319        $individual = $this->createMock(Individual::class);
320        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock(''));
321
322        $census = $this->createMock(CensusInterface::class);
323        $census->method('censusPlace')->willReturn('Wales');
324
325        $column = new CensusColumnBornForeignParts($census, '', '');
326
327        self::assertSame('', $column->generate($individual, $individual));
328    }
329
330    public function testBornNowhereCensusScotland(): void
331    {
332        $individual = $this->createMock(Individual::class);
333        $individual->method('getBirthPlace')->willReturn($this->getPlaceMock(''));
334
335        $census = $this->createMock(CensusInterface::class);
336        $census->method('censusPlace')->willReturn('Scotland');
337
338        $column = new CensusColumnBornForeignParts($census, '', '');
339
340        self::assertSame('', $column->generate($individual, $individual));
341    }
342}
343