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 CensusColumnMonthIfMarriedWithinYear 28 */ 29class CensusColumnMonthIfMarriedWithinYearTest 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\CensusColumnMonthIfMarriedWithinYear 43 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 44 * 45 * @return void 46 */ 47 public function testMarriedWithinYear(): void 48 { 49 $fact = Mockery::mock(Fact::class); 50 $fact->shouldReceive('date')->andReturn(new Date('01 DEC 1859')); 51 52 $family = Mockery::mock(Family::class); 53 $family->shouldReceive('facts')->with(['MARR'])->andReturn([$fact]); 54 55 $individual = Mockery::mock(Individual::class); 56 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 57 58 $census = Mockery::mock(CensusInterface::class); 59 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 60 61 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 62 63 $this->assertSame('Dec', $column->generate($individual, $individual)); 64 } 65 66 /** 67 * @covers \Fisharebest\Webtrees\Census\CensusColumnMonthIfMarriedWithinYear 68 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 69 * 70 * @return void 71 */ 72 public function testMarriedOverYearBeforeTheCensus(): void 73 { 74 $fact = Mockery::mock(Fact::class); 75 $fact->shouldReceive('date')->andReturn(new Date('01 JAN 1859')); 76 77 $family = Mockery::mock(Family::class); 78 $family->shouldReceive('facts')->with(['MARR'])->andReturn([$fact]); 79 80 $individual = Mockery::mock(Individual::class); 81 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 82 83 $census = Mockery::mock(CensusInterface::class); 84 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 85 86 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 87 88 $this->assertSame('', $column->generate($individual, $individual)); 89 } 90 91 /** 92 * @covers \Fisharebest\Webtrees\Census\CensusColumnMonthIfMarriedWithinYear 93 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 94 * 95 * @return void 96 */ 97 public function testMarriedAfterTheCensus(): void 98 { 99 $fact = Mockery::mock(Fact::class); 100 $fact->shouldReceive('date')->andReturn(new Date('02 JUN 1860')); 101 102 $family = Mockery::mock(Family::class); 103 $family->shouldReceive('facts')->with(['MARR'])->andReturn([$fact]); 104 105 $individual = Mockery::mock(Individual::class); 106 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 107 108 $census = Mockery::mock(CensusInterface::class); 109 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 110 111 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 112 113 $this->assertSame('', $column->generate($individual, $individual)); 114 } 115 116 /** 117 * @covers \Fisharebest\Webtrees\Census\CensusColumnMonthIfMarriedWithinYear 118 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 119 * 120 * @return void 121 */ 122 public function testNoMarriage(): void 123 { 124 $family = Mockery::mock(Family::class); 125 $family->shouldReceive('facts')->with(['MARR'])->andReturn([]); 126 127 $individual = Mockery::mock(Individual::class); 128 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 129 130 $census = Mockery::mock(CensusInterface::class); 131 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 132 133 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 134 135 $this->assertSame('', $column->generate($individual, $individual)); 136 } 137 138 /** 139 * @covers \Fisharebest\Webtrees\Census\CensusColumnMonthIfMarriedWithinYear 140 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumn 141 * 142 * @return void 143 */ 144 public function testNoSpouseFamily(): void 145 { 146 $individual = Mockery::mock(Individual::class); 147 $individual->shouldReceive('getSpouseFamilies')->andReturn([]); 148 149 $census = Mockery::mock(CensusInterface::class); 150 $census->shouldReceive('censusDate')->andReturn('01 JUN 1860'); 151 152 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 153 154 $this->assertSame('', $column->generate($individual, $individual)); 155 } 156} 157