1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2017 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 <http://www.gnu.org/licenses/>. 16 */ 17namespace Fisharebest\Webtrees\Census; 18 19use Fisharebest\Webtrees\Date; 20use Mockery; 21 22/** 23 * Test harness for the class CensusColumnConditionEnglish 24 */ 25class CensusColumnConditionEnglishTest extends \PHPUnit_Framework_TestCase { 26 /** 27 * Delete mock objects 28 */ 29 public function tearDown() { 30 Mockery::close(); 31 } 32 33 /** 34 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 35 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 36 */ 37 public function testNoSpouseFamiliesMale() { 38 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 39 $individual->shouldReceive('getSex')->andReturn('M'); 40 $individual->shouldReceive('getSpouseFamilies')->andReturn([]); 41 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1800')); 42 43 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 44 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 45 46 $column = new CensusColumnConditionEnglish($census, '', ''); 47 48 $this->assertSame('Unm', $column->generate($individual)); 49 } 50 51 /** 52 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 53 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 54 */ 55 public function testNoSpouseFamiliesFemale() { 56 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 57 $individual->shouldReceive('getSex')->andReturn('F'); 58 $individual->shouldReceive('getSpouseFamilies')->andReturn([]); 59 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1800')); 60 61 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 62 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 63 64 $column = new CensusColumnConditionEnglish($census, '', ''); 65 66 $this->assertSame('Unm', $column->generate($individual)); 67 } 68 69 /** 70 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 71 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 72 */ 73 public function testNoFamilyFactsMale() { 74 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 75 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 76 $family->shouldReceive('getFacts')->with('MARR')->andReturn([]); 77 78 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 79 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 80 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1800')); 81 $individual->shouldReceive('getSex')->andReturn('M'); 82 83 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 84 85 $column = new CensusColumnConditionEnglish($census, '', ''); 86 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 87 88 $this->assertSame('Unm', $column->generate($individual)); 89 } 90 91 /** 92 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 93 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 94 */ 95 public function testNoFamilyFactsFemale() { 96 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 97 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 98 $family->shouldReceive('getFacts')->with('MARR')->andReturn([]); 99 100 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 101 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 102 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1800')); 103 $individual->shouldReceive('getSex')->andReturn('F'); 104 105 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 106 107 $column = new CensusColumnConditionEnglish($census, '', ''); 108 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 109 110 $this->assertSame('Unm', $column->generate($individual)); 111 } 112 113 /** 114 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 115 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 116 */ 117 public function testSpouseDeadMale() { 118 $fact = Mockery::mock('Fisharebest\Webtrees\Fact'); 119 120 $spouse = Mockery::mock('Fisharebest\Webtrees\Individual'); 121 $spouse->shouldReceive('getDeathDate')->andReturn(new Date('1820')); 122 123 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 124 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 125 $family->shouldReceive('getFacts')->with('MARR')->andReturn([$fact]); 126 $family->shouldReceive('getFacts')->with('DIV')->andReturn([]); 127 $family->shouldReceive('getSpouse')->andReturn($spouse); 128 129 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 130 $individual->shouldReceive('getSex')->andReturn('M'); 131 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 132 133 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 134 135 $column = new CensusColumnConditionEnglish($census, '', ''); 136 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 137 138 $this->assertSame('Wid', $column->generate($individual)); 139 } 140 141 /** 142 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 143 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 144 */ 145 public function testSpouseDeadFemale() { 146 $fact = Mockery::mock('Fisharebest\Webtrees\Fact'); 147 148 $spouse = Mockery::mock('Fisharebest\Webtrees\Individual'); 149 $spouse->shouldReceive('getDeathDate')->andReturn(new Date('1820')); 150 151 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 152 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 153 $family->shouldReceive('getFacts')->with('MARR')->andReturn([$fact]); 154 $family->shouldReceive('getFacts')->with('DIV')->andReturn([]); 155 $family->shouldReceive('getSpouse')->andReturn($spouse); 156 157 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 158 $individual->shouldReceive('getSex')->andReturn('F'); 159 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 160 161 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 162 163 $column = new CensusColumnConditionEnglish($census, '', ''); 164 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 165 166 $this->assertSame('Wid', $column->generate($individual)); 167 } 168 169 /** 170 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 171 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 172 */ 173 public function testNoFamilyUnmarriedMale() { 174 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 175 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 176 $family->shouldReceive('getFacts')->with('MARR')->andReturn([]); 177 178 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 179 $individual->shouldReceive('getSex')->andReturn('M'); 180 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 181 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1800')); 182 183 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 184 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 185 186 $column = new CensusColumnConditionEnglish($census, '', ''); 187 188 $this->assertSame('Unm', $column->generate($individual)); 189 } 190 191 /** 192 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 193 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 194 */ 195 public function testNoFamilyUnmarriedFemale() { 196 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 197 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 198 $family->shouldReceive('getFacts')->with('MARR')->andReturn([]); 199 200 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 201 $individual->shouldReceive('getSex')->andReturn('F'); 202 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 203 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1800')); 204 205 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 206 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 207 208 $column = new CensusColumnConditionEnglish($census, '', ''); 209 210 $this->assertSame('Unm', $column->generate($individual)); 211 } 212 213 /** 214 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 215 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 216 */ 217 public function testChildMale() { 218 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 219 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 220 $family->shouldReceive('getFacts')->with('MARR')->andReturn([]); 221 222 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 223 $individual->shouldReceive('getSex')->andReturn('M'); 224 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 225 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1820')); 226 227 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 228 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 229 230 $column = new CensusColumnConditionEnglish($census, '', ''); 231 232 $this->assertSame('', $column->generate($individual)); 233 } 234 235 /** 236 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 237 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 238 */ 239 public function testChildFemale() { 240 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 241 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 242 $family->shouldReceive('getFacts')->with('MARR')->andReturn([]); 243 244 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 245 $individual->shouldReceive('getSex')->andReturn('F'); 246 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 247 $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('1820')); 248 249 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 250 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 251 252 $column = new CensusColumnConditionEnglish($census, '', ''); 253 254 $this->assertSame('', $column->generate($individual)); 255 } 256 257 /** 258 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 259 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 260 */ 261 public function testDivorcedMale() { 262 $fact = Mockery::mock('Fisharebest\Webtrees\Fact'); 263 264 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 265 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 266 $family->shouldReceive('getFacts')->with('MARR')->andReturn([$fact]); 267 $family->shouldReceive('getFacts')->with('DIV')->andReturn([$fact]); 268 269 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 270 $individual->shouldReceive('getSex')->andReturn('M'); 271 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 272 273 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 274 275 $column = new CensusColumnConditionEnglish($census, '', ''); 276 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 277 278 $this->assertSame('Div', $column->generate($individual)); 279 } 280 281 /** 282 * @covers \Fisharebest\Webtrees\Census\CensusColumnConditionEnglish 283 * @covers \Fisharebest\Webtrees\Census\AbstractCensusColumnCondition 284 */ 285 public function testDivorcedFemale() { 286 $fact = Mockery::mock('Fisharebest\Webtrees\Fact'); 287 288 $family = Mockery::mock('Fisharebest\Webtrees\Family'); 289 $family->shouldReceive('getMarriageDate')->andReturn(new Date('')); 290 $family->shouldReceive('getFacts')->with('MARR')->andReturn([$fact]); 291 $family->shouldReceive('getFacts')->with('DIV')->andReturn([$fact]); 292 293 $individual = Mockery::mock('Fisharebest\Webtrees\Individual'); 294 $individual->shouldReceive('getSex')->andReturn('F'); 295 $individual->shouldReceive('getSpouseFamilies')->andReturn([$family]); 296 297 $census = Mockery::mock('Fisharebest\Webtrees\Census\CensusInterface'); 298 299 $column = new CensusColumnConditionEnglish($census, '', ''); 300 $census->shouldReceive('censusDate')->andReturn('30 JUN 1830'); 301 302 $this->assertSame('Div', $column->generate($individual)); 303 } 304} 305