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