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\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 CensusColumnAgeMarried 31 */ 32class CensusColumnAgeMarriedTest extends TestCase 33{ 34 /** 35 * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried 36 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 37 */ 38 public function testAgeMarried(): void 39 { 40 $fact = $this->createMock(Fact::class); 41 $fact->method('date')->willReturn(new Date('01 DEC 1859')); 42 43 $family = $this->createMock(Family::class); 44 $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact])); 45 46 $individual = $this->createMock(Individual::class); 47 $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840')); 48 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 49 50 $census = $this->createMock(CensusInterface::class); 51 $census->method('censusDate')->willReturn('01 JUN 1860'); 52 53 $column = new CensusColumnAgeMarried($census, '', ''); 54 55 self::assertSame('19', $column->generate($individual, $individual)); 56 } 57 58 /** 59 * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried 60 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 61 */ 62 public function testNoBirthDate(): void 63 { 64 $individual = $this->createMock(Individual::class); 65 $individual->method('getBirthDate')->willReturn(new Date('')); 66 $individual->method('spouseFamilies')->willReturn(new Collection()); 67 68 $census = $this->createMock(CensusInterface::class); 69 $census->method('censusDate')->willReturn('01 JUN 1860'); 70 71 $column = new CensusColumnAgeMarried($census, '', ''); 72 73 self::assertSame('', $column->generate($individual, $individual)); 74 } 75 76 /** 77 * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried 78 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 79 */ 80 public function testNoMarriage(): void 81 { 82 $family = $this->createMock(Family::class); 83 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 84 85 $individual = $this->createMock(Individual::class); 86 $individual->method('getBirthDate')->willReturn(new Date('')); 87 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 88 89 $census = $this->createMock(CensusInterface::class); 90 $census->method('censusDate')->willReturn('01 JUN 1860'); 91 92 $column = new CensusColumnAgeMarried($census, '', ''); 93 94 self::assertSame('', $column->generate($individual, $individual)); 95 } 96 97 /** 98 * @covers \Fisharebest\Webtrees\Census\CensusColumnAgeMarried 99 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 100 */ 101 public function testNoSpouseFamily(): void 102 { 103 $individual = $this->createMock(Individual::class); 104 $individual->method('getBirthDate')->willReturn(new Date('15 MAR 1840')); 105 $individual->method('spouseFamilies')->willReturn(new Collection()); 106 107 $census = $this->createMock(CensusInterface::class); 108 $census->method('censusDate')->willReturn('01 JUN 1860'); 109 110 $column = new CensusColumnAgeMarried($census, '', ''); 111 112 self::assertSame('', $column->generate($individual, $individual)); 113 } 114} 115