xref: /webtrees/tests/app/Census/CensusColumnReligionTest.php (revision a26ec5ede3c2ecdb45b783755ede967935aaecba)
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\Fact;
23use Fisharebest\Webtrees\Individual;
24use Fisharebest\Webtrees\TestCase;
25use Illuminate\Support\Collection;
26
27/**
28 * Test harness for the class CensusColumnReligion
29 */
30class CensusColumnReligionTest extends TestCase
31{
32    /**
33     * @covers \Fisharebest\Webtrees\Census\CensusColumnReligion
34     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
35     */
36    public function testNoReligion(): void
37    {
38        $individual = $this->createMock(Individual::class);
39        $individual
40            ->expects(self::exactly(2))
41            ->method('facts')
42            ->with(self::withConsecutive([['RELI'], []]))
43            ->willReturnOnConsecutiveCalls(new Collection(), new Collection());
44
45        $census = $this->createMock(CensusInterface::class);
46
47        $column = new CensusColumnReligion($census, '', '');
48
49        self::assertSame('', $column->generate($individual, $individual));
50    }
51
52    /**
53     * @covers \Fisharebest\Webtrees\Census\CensusColumnReligion
54     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
55     */
56    public function testRecordReligion(): void
57    {
58        $individual = $this->createMock(Individual::class);
59        $fact       = $this->createMock(Fact::class);
60        $fact->method('value')->willReturn('Jedi');
61        $individual->method('facts')->with(['RELI'])->willReturn(new Collection([$fact]));
62
63        $census = $this->createMock(CensusInterface::class);
64
65        $column = new CensusColumnReligion($census, '', '');
66
67        self::assertSame('Jedi', $column->generate($individual, $individual));
68    }
69
70    /**
71     * @covers \Fisharebest\Webtrees\Census\CensusColumnReligion
72     * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn
73     */
74    public function testEventReligion(): void
75    {
76        $individual = $this->createMock(Individual::class);
77        $fact       = $this->createMock(Fact::class);
78        $fact->method('attribute')->with('RELI')->willReturn('Jedi');
79        $individual
80            ->expects(self::exactly(2))
81            ->method('facts')
82            ->with(self::withConsecutive([['RELI'], []]))
83            ->willReturnOnConsecutiveCalls(
84                new Collection(),
85                new Collection([$fact])
86            );
87
88        $census = $this->createMock(CensusInterface::class);
89
90        $column = new CensusColumnReligion($census, '', '');
91
92        self::assertSame('Jedi', $column->generate($individual, $individual));
93    }
94}
95