1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Census; 19 20use Fisharebest\Webtrees\Date; 21use Fisharebest\Webtrees\Fact; 22use Fisharebest\Webtrees\Family; 23use Fisharebest\Webtrees\Individual; 24use Mockery; 25 26/** 27 * Test harness for the class CensusColumnYearsMarried 28 */ 29class CensusColumnYearsMarriedTest extends \Fisharebest\Webtrees\TestCase 30{ 31 /** 32 * Delete mock objects 33 * 34 * @return void 35 */ 36 public function tearDown() 37 { 38 Mockery::close(); 39 } 40 41 /** 42 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 43 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 44 * 45 * @return void 46 */ 47 public function testNoSpouseFamily(): void 48 { 49 $individual = Mockery::mock(Individual::class); 50 $individual->shouldReceive('getSpouseFamilies')->andReturn([]); 51 52 $census = Mockery::mock(CensusInterface::class); 53 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 54 55 $column = new CensusColumnYearsMarried($census, '', ''); 56 57 $this->assertSame('', $column->generate($individual, $individual)); 58 } 59 60 /** 61 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 62 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 63 * 64 * @return void 65 */ 66 public function testNoMarriage(): void 67 { 68 $family = Mockery::mock(Family::class); 69 $family->shouldReceive('facts')->with(['MARR'], true)->andReturn([]); 70 71 $individual = Mockery::mock(Individual::class); 72 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 73 74 $census = Mockery::mock(CensusInterface::class); 75 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 76 77 $column = new CensusColumnYearsMarried($census, '', ''); 78 79 $this->assertSame('', $column->generate($individual, $individual)); 80 } 81 82 /** 83 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 84 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 85 * 86 * @return void 87 */ 88 public function testUndatedMarriage(): void 89 { 90 $fact = Mockery::mock(Fact::class); 91 $fact->shouldReceive('date')->andReturn(new Date('')); 92 93 $family = Mockery::mock(Family::class); 94 $family->shouldReceive('facts')->with(['MARR'], true)->andReturn([$fact]); 95 96 $individual = Mockery::mock(Individual::class); 97 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 98 99 $census = Mockery::mock(CensusInterface::class); 100 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 101 102 $column = new CensusColumnYearsMarried($census, '', ''); 103 104 $this->assertSame('', $column->generate($individual, $individual)); 105 } 106 107 /** 108 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 109 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 110 * 111 * @return void 112 */ 113 public function testMarriageAfterCensus(): void 114 { 115 $fact = Mockery::mock(Fact::class); 116 $fact->shouldReceive('date')->andReturn(new Date('1861')); 117 118 $family = Mockery::mock(Family::class); 119 $family->shouldReceive('facts')->with(['MARR'], true)->andReturn([$fact]); 120 121 $individual = Mockery::mock(Individual::class); 122 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 123 124 $census = Mockery::mock(CensusInterface::class); 125 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 126 127 $column = new CensusColumnYearsMarried($census, '', ''); 128 129 $this->assertSame('', $column->generate($individual, $individual)); 130 } 131 132 /** 133 * @covers \Fisharebest\Webtrees\Census\CensusColumnYearsMarried 134 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 135 * 136 * @return void 137 */ 138 public function testMarriageBeforeCensus(): void 139 { 140 $fact = Mockery::mock(Fact::class); 141 $fact->shouldReceive('date')->andReturn(new Date('OCT 1851')); 142 143 $family = Mockery::mock(Family::class); 144 $family->shouldReceive('facts')->with(['MARR'], true)->andReturn([$fact]); 145 146 $individual = Mockery::mock(Individual::class); 147 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 148 149 $census = Mockery::mock(CensusInterface::class); 150 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 151 152 $column = new CensusColumnYearsMarried($census, '', ''); 153 154 $this->assertSame('8', $column->generate($individual, $individual)); 155 } 156} 157