1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 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 * @return void 36 */ 37 public function testNoReligion(): void 38 { 39 $individual = $this->createMock(Individual::class); 40 $individual 41 ->expects(self::exactly(2)) 42 ->method('facts') 43 ->withConsecutive([['RELI']], []) 44 ->willReturnOnConsecutiveCalls(new Collection(), new Collection()); 45 46 $census = $this->createMock(CensusInterface::class); 47 48 $column = new CensusColumnReligion($census, '', ''); 49 50 self::assertSame('', $column->generate($individual, $individual)); 51 } 52 53 /** 54 * @covers \Fisharebest\Webtrees\Census\CensusColumnReligion 55 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 56 * @return void 57 */ 58 public function testRecordReligion(): void 59 { 60 $individual = $this->createMock(Individual::class); 61 $fact = $this->createMock(Fact::class); 62 $fact->method('value')->willReturn('Jedi'); 63 $individual->method('facts')->with(['RELI'])->willReturn(new Collection([$fact])); 64 65 $census = $this->createMock(CensusInterface::class); 66 67 $column = new CensusColumnReligion($census, '', ''); 68 69 self::assertSame('Jedi', $column->generate($individual, $individual)); 70 } 71 72 /** 73 * @covers \Fisharebest\Webtrees\Census\CensusColumnReligion 74 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 75 * @return void 76 */ 77 public function testEventReligion(): void 78 { 79 $individual = $this->createMock(Individual::class); 80 $fact = $this->createMock(Fact::class); 81 $fact->method('attribute')->with('RELI')->willReturn('Jedi'); 82 $individual 83 ->expects(self::exactly(2)) 84 ->method('facts') 85 ->withConsecutive( 86 [['RELI']], 87 [] 88 ) 89 ->willReturnOnConsecutiveCalls( 90 new Collection(), 91 new Collection([$fact]) 92 ); 93 94 $census = $this->createMock(CensusInterface::class); 95 96 $column = new CensusColumnReligion($census, '', ''); 97 98 self::assertSame('Jedi', $column->generate($individual, $individual)); 99 } 100} 101