xref: /webtrees/tests/app/Census/CensusColumnSurnameGivenNamesTest.php (revision 234e0863a607ff8e5f8e78a7fefe5366f39f8ebf)
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\TestCase;
24use Illuminate\Support\Collection;
25use PHPUnit\Framework\Attributes\CoversClass;
26
27
28#[CoversClass(CensusColumnSurnameGivenNames::class)]
29#[CoversClass(AbstractCensusColumn::class)]
30class CensusColumnSurnameGivenNamesTest extends TestCase
31{
32    public function testOneGivenName(): void
33    {
34        $individual = $this->createMock(Individual::class);
35        $individual->method('getAllNames')->willReturn([
36            [
37                'givn' => 'Joe',
38                'surname' => 'Sixpack',
39            ],
40        ]);
41        $individual->method('spouseFamilies')->willReturn(new Collection());
42
43        $census = $this->createMock(CensusInterface::class);
44        $census->method('censusDate')->willReturn('');
45
46        $column = new CensusColumnSurnameGivenNames($census, '', '');
47
48        self::assertSame('Sixpack, Joe', $column->generate($individual, $individual));
49    }
50
51    public function testMultipleGivenNames(): void
52    {
53        $individual = $this->createMock(Individual::class);
54        $individual->method('getAllNames')->willReturn([
55            [
56                'givn'    => 'Joe Fred',
57                'surname' => 'Sixpack',
58            ],
59        ]);
60        $individual->method('spouseFamilies')->willReturn(new Collection());
61
62        $census = $this->createMock(CensusInterface::class);
63        $census->method('censusDate')->willReturn('');
64
65        $column = new CensusColumnSurnameGivenNames($census, '', '');
66
67        self::assertSame('Sixpack, Joe Fred', $column->generate($individual, $individual));
68    }
69
70    public function testNoName(): void
71    {
72        $individual = $this->createMock(Individual::class);
73        $individual->method('getAllNames')->willReturn([
74            [
75                'givn'    => Individual::PRAENOMEN_NESCIO,
76                'surname' => Individual::NOMEN_NESCIO,
77            ],
78        ]);
79        $individual->method('spouseFamilies')->willReturn(new Collection());
80
81        $census = $this->createMock(CensusInterface::class);
82        $census->method('censusDate')->willReturn('');
83
84        $column = new CensusColumnSurnameGivenNames($census, '', '');
85
86        self::assertSame('…, …', $column->generate($individual, $individual));
87    }
88}
89