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 CensusColumnYearsMarried 31 */ 32class CensusColumnYearsMarriedTest extends TestCase 33{ 34 /** 35 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 36 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 37 */ 38 public function testNoSpouseFamily(): void 39 { 40 $individual = $this->createMock(Individual::class); 41 $individual->method('spouseFamilies')->willReturn(new Collection()); 42 43 $census = $this->createMock(CensusInterface::class); 44 $census->method('censusDate')->willReturn('01 JUN 1860'); 45 46 $column = new CensusColumnYearsMarried($census, '', ''); 47 48 self::assertSame('', $column->generate($individual, $individual)); 49 } 50 51 /** 52 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 53 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 54 */ 55 public function testNoMarriage(): void 56 { 57 $family = $this->createMock(Family::class); 58 $family->method('facts')->with(['MARR'], true)->willReturn(new Collection()); 59 60 $individual = $this->createMock(Individual::class); 61 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 62 63 $census = $this->createMock(CensusInterface::class); 64 $census->method('censusDate')->willReturn('01 JUN 1860'); 65 66 $column = new CensusColumnYearsMarried($census, '', ''); 67 68 self::assertSame('', $column->generate($individual, $individual)); 69 } 70 71 /** 72 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 73 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 74 */ 75 public function testUndatedMarriage(): void 76 { 77 $fact = $this->createMock(Fact::class); 78 $fact->method('date')->willReturn(new Date('')); 79 80 $family = $this->createMock(Family::class); 81 $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact])); 82 83 $individual = $this->createMock(Individual::class); 84 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 85 86 $census = $this->createMock(CensusInterface::class); 87 $census->method('censusDate')->willReturn('01 JUN 1860'); 88 89 $column = new CensusColumnYearsMarried($census, '', ''); 90 91 self::assertSame('', $column->generate($individual, $individual)); 92 } 93 94 /** 95 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 96 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 97 */ 98 public function testMarriageAfterCensus(): void 99 { 100 $fact = $this->createMock(Fact::class); 101 $fact->method('date')->willReturn(new Date('1861')); 102 103 $family = $this->createMock(Family::class); 104 $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact])); 105 106 $individual = $this->createMock(Individual::class); 107 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 108 109 $census = $this->createMock(CensusInterface::class); 110 $census->method('censusDate')->willReturn('01 JUN 1860'); 111 112 $column = new CensusColumnYearsMarried($census, '', ''); 113 114 self::assertSame('', $column->generate($individual, $individual)); 115 } 116 117 /** 118 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 119 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 120 */ 121 public function testMarriageBeforeCensus(): void 122 { 123 $fact = $this->createMock(Fact::class); 124 $fact->method('date')->willReturn(new Date('OCT 1851')); 125 126 $family = $this->createMock(Family::class); 127 $family->method('facts')->with(['MARR'], true)->willReturn(new Collection([$fact])); 128 129 $individual = $this->createMock(Individual::class); 130 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 131 132 $census = $this->createMock(CensusInterface::class); 133 $census->method('censusDate')->willReturn('01 JUN 1860'); 134 135 $column = new CensusColumnYearsMarried($census, '', ''); 136 137 self::assertSame('8', $column->generate($individual, $individual)); 138 } 139} 140