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; 28use PHPUnit\Framework\Attributes\CoversClass; 29 30 31#[CoversClass(CensusColumnMonthIfMarriedWithinYear::class)] 32#[CoversClass(AbstractCensusColumn::class)] 33class CensusColumnMonthIfMarriedWithinYearTest extends TestCase 34{ 35 public function testMarriedWithinYear(): void 36 { 37 $fact = $this->createMock(Fact::class); 38 $fact->method('date')->willReturn(new Date('01 DEC 1859')); 39 40 $family = $this->createMock(Family::class); 41 $family->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 42 43 $individual = $this->createMock(Individual::class); 44 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 45 46 $census = $this->createMock(CensusInterface::class); 47 $census->method('censusDate')->willReturn('01 JUN 1860'); 48 49 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 50 51 self::assertSame('Dec', $column->generate($individual, $individual)); 52 } 53 54 public function testMarriedOverYearBeforeTheCensus(): void 55 { 56 $fact = $this->createMock(Fact::class); 57 $fact->method('date')->willReturn(new Date('01 JAN 1859')); 58 59 $family = $this->createMock(Family::class); 60 $family->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 61 62 $individual = $this->createMock(Individual::class); 63 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 64 65 $census = $this->createMock(CensusInterface::class); 66 $census->method('censusDate')->willReturn('01 JUN 1860'); 67 68 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 69 70 self::assertSame('', $column->generate($individual, $individual)); 71 } 72 73 public function testMarriedAfterTheCensus(): void 74 { 75 $fact = $this->createMock(Fact::class); 76 $fact->method('date')->willReturn(new Date('02 JUN 1860')); 77 78 $family = $this->createMock(Family::class); 79 $family->method('facts')->with(['MARR'])->willReturn(new Collection([$fact])); 80 81 $individual = $this->createMock(Individual::class); 82 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 83 84 $census = $this->createMock(CensusInterface::class); 85 $census->method('censusDate')->willReturn('01 JUN 1860'); 86 87 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 88 89 self::assertSame('', $column->generate($individual, $individual)); 90 } 91 92 public function testNoMarriage(): void 93 { 94 $family = $this->createMock(Family::class); 95 $family->method('facts')->with(['MARR'])->willReturn(new Collection()); 96 97 $individual = $this->createMock(Individual::class); 98 $individual->method('spouseFamilies')->willReturn(new Collection([$family])); 99 100 $census = $this->createMock(CensusInterface::class); 101 $census->method('censusDate')->willReturn('01 JUN 1860'); 102 103 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 104 105 self::assertSame('', $column->generate($individual, $individual)); 106 } 107 108 public function testNoSpouseFamily(): void 109 { 110 $individual = $this->createMock(Individual::class); 111 $individual->method('spouseFamilies')->willReturn(new Collection()); 112 113 $census = $this->createMock(CensusInterface::class); 114 $census->method('censusDate')->willReturn('01 JUN 1860'); 115 116 $column = new CensusColumnMonthIfMarriedWithinYear($census, '', ''); 117 118 self::assertSame('', $column->generate($individual, $individual)); 119 } 120} 121