1cb62cb3cSGreg Roach<?php 2cb62cb3cSGreg Roach 3cb62cb3cSGreg Roach/** 4cb62cb3cSGreg Roach * webtrees: online genealogy 55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team 6cb62cb3cSGreg Roach * This program is free software: you can redistribute it and/or modify 7cb62cb3cSGreg Roach * it under the terms of the GNU General Public License as published by 8cb62cb3cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9cb62cb3cSGreg Roach * (at your option) any later version. 10cb62cb3cSGreg Roach * This program is distributed in the hope that it will be useful, 11cb62cb3cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12cb62cb3cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13cb62cb3cSGreg Roach * GNU General Public License for more details. 14cb62cb3cSGreg Roach * You should have received a copy of the GNU General Public License 15cb62cb3cSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16cb62cb3cSGreg Roach */ 17cb62cb3cSGreg Roach 18cb62cb3cSGreg Roachdeclare(strict_types=1); 19cb62cb3cSGreg Roach 20cb62cb3cSGreg Roachnamespace Fisharebest\Webtrees\Services; 21cb62cb3cSGreg Roach 22cb62cb3cSGreg Roachuse Fisharebest\Webtrees\TestCase; 23*eed04cf9SJonathan Jaubartuse Fisharebest\Webtrees\Tree; 24cb62cb3cSGreg Roach 25cb62cb3cSGreg Roach/** 26cb62cb3cSGreg Roach * Test harness for the class GedcomEditService 27cb62cb3cSGreg Roach * 28cb62cb3cSGreg Roach * @covers \Fisharebest\Webtrees\Services\GedcomEditService 29cb62cb3cSGreg Roach */ 30cb62cb3cSGreg Roachclass GedcomEditServiceTest extends TestCase 31cb62cb3cSGreg Roach{ 3200c92694SGreg Roach protected static bool $uses_database = true; 3300c92694SGreg Roach 34cb62cb3cSGreg Roach /** 35cb62cb3cSGreg Roach * @covers \Fisharebest\Webtrees\Services\GedcomEditService::editLinesToGedcom 36cb62cb3cSGreg Roach */ 37cb62cb3cSGreg Roach public function testEditLinesToGedcom(): void 38cb62cb3cSGreg Roach { 39cb62cb3cSGreg Roach $gedcom_edit_service = new GedcomEditService(); 40cb62cb3cSGreg Roach 41f01ab4acSGreg Roach static::assertSame( 426e60786aSGreg Roach '1 BIRT Y', 43cb62cb3cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 44cb62cb3cSGreg Roach 'INDI', 45cb62cb3cSGreg Roach ['1'], 46cb62cb3cSGreg Roach ['BIRT'], 47a92a07c7SGreg Roach ['Y'], 48a92a07c7SGreg Roach false 49cb62cb3cSGreg Roach ) 50cb62cb3cSGreg Roach ); 51cb62cb3cSGreg Roach 52f01ab4acSGreg Roach static::assertSame( 53a92a07c7SGreg Roach "\n1 BIRT Y\n2 ADDR England", 54cb62cb3cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 55cb62cb3cSGreg Roach 'INDI', 56cb62cb3cSGreg Roach ['1', '2'], 57cb62cb3cSGreg Roach ['BIRT', 'ADDR'], 58cb62cb3cSGreg Roach ['Y', 'England'] 59cb62cb3cSGreg Roach ) 60cb62cb3cSGreg Roach ); 61cb62cb3cSGreg Roach 62f01ab4acSGreg Roach static::assertSame( 63a92a07c7SGreg Roach "\n1 BIRT\n2 PLAC England", 64cb62cb3cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 65cb62cb3cSGreg Roach 'INDI', 66cb62cb3cSGreg Roach ['1', '2'], 67cb62cb3cSGreg Roach ['BIRT', 'PLAC'], 68cb62cb3cSGreg Roach ['Y', 'England'] 69cb62cb3cSGreg Roach ) 70cb62cb3cSGreg Roach ); 71cb62cb3cSGreg Roach 72f01ab4acSGreg Roach static::assertSame( 73a92a07c7SGreg Roach "\n1 BIRT\n2 PLAC England\n2 SOUR @S1@\n3 PAGE 123", 74cb62cb3cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 75cb62cb3cSGreg Roach 'INDI', 76cb62cb3cSGreg Roach ['1', '2', '2', '3'], 77cb62cb3cSGreg Roach ['BIRT', 'PLAC', 'SOUR', 'PAGE'], 78cb62cb3cSGreg Roach ['Y', 'England', '@S1@', '123'] 79cb62cb3cSGreg Roach ) 80cb62cb3cSGreg Roach ); 81cb62cb3cSGreg Roach 82cefd719cSGreg Roach // Missing SOUR, so ignore PAGE 83f01ab4acSGreg Roach static::assertSame( 84a92a07c7SGreg Roach "\n1 BIRT\n2 PLAC England", 85cefd719cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 86cefd719cSGreg Roach 'INDI', 87cefd719cSGreg Roach ['1', '2', '2', '3'], 88cefd719cSGreg Roach ['BIRT', 'PLAC', 'SOUR', 'PAGE'], 89cefd719cSGreg Roach ['Y', 'England', '', '123'] 90cefd719cSGreg Roach ) 91cefd719cSGreg Roach ); 92cefd719cSGreg Roach 93f01ab4acSGreg Roach static::assertSame( 94a92a07c7SGreg Roach "\n1 BIRT\n2 PLAC England", 95cb62cb3cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 96cb62cb3cSGreg Roach 'INDI', 97cb62cb3cSGreg Roach ['1', '2', '2', '3'], 98cb62cb3cSGreg Roach ['BIRT', 'PLAC', 'SOUR', 'PAGE'], 99cb62cb3cSGreg Roach ['Y', 'England', '', '123'] 100cb62cb3cSGreg Roach ) 101cb62cb3cSGreg Roach ); 102cb62cb3cSGreg Roach 103f01ab4acSGreg Roach static::assertSame( 104a92a07c7SGreg Roach "\n1 BIRT\n2 PLAC England\n1 DEAT\n2 PLAC Scotland", 105cb62cb3cSGreg Roach $gedcom_edit_service->editLinesToGedcom( 106cb62cb3cSGreg Roach 'INDI', 107cb62cb3cSGreg Roach ['1', '2', '2', '3', '1', '2', '2', '3'], 108cb62cb3cSGreg Roach ['BIRT', 'PLAC', 'SOUR', 'PAGE', 'DEAT', 'PLAC', 'SOUR', 'PAGE'], 109cb62cb3cSGreg Roach ['Y', 'England', '', '123', 'Y', 'Scotland', '', '123'] 110cb62cb3cSGreg Roach ) 111cb62cb3cSGreg Roach ); 112cb62cb3cSGreg Roach } 113*eed04cf9SJonathan Jaubart 114*eed04cf9SJonathan Jaubart /** 115*eed04cf9SJonathan Jaubart * @dataProvider newFamilyFactsData 116*eed04cf9SJonathan Jaubart * 117*eed04cf9SJonathan Jaubart * @param string $required_famfacts 118*eed04cf9SJonathan Jaubart * @param array<string> $expected_new_facts 119*eed04cf9SJonathan Jaubart */ 120*eed04cf9SJonathan Jaubart public function testNewFamilyFacts(string $required_famfacts, array $expected_new_facts): void 121*eed04cf9SJonathan Jaubart { 122*eed04cf9SJonathan Jaubart $gedcom_edit_service = new GedcomEditService(); 123*eed04cf9SJonathan Jaubart 124*eed04cf9SJonathan Jaubart $tree = $this->createMock(Tree::class); 125*eed04cf9SJonathan Jaubart $tree->method('getPreference')->with('QUICK_REQUIRED_FAMFACTS')->willReturn($required_famfacts); 126*eed04cf9SJonathan Jaubart 127*eed04cf9SJonathan Jaubart $new_facts = $gedcom_edit_service->newFamilyFacts($tree); 128*eed04cf9SJonathan Jaubart self::assertSameSize($expected_new_facts, $new_facts); 129*eed04cf9SJonathan Jaubart for ($i = 0; $i < count($expected_new_facts); $i++) { 130*eed04cf9SJonathan Jaubart /** @var \Fisharebest\Webtrees\Fact $new_fact */ 131*eed04cf9SJonathan Jaubart $new_fact = $new_facts->get($i); 132*eed04cf9SJonathan Jaubart self::assertSame($expected_new_facts[$i], $new_fact->tag()); 133*eed04cf9SJonathan Jaubart } 134*eed04cf9SJonathan Jaubart } 135*eed04cf9SJonathan Jaubart 136*eed04cf9SJonathan Jaubart /** 137*eed04cf9SJonathan Jaubart * @dataProvider newIndividualFactsData 138*eed04cf9SJonathan Jaubart * 139*eed04cf9SJonathan Jaubart * @param string $required_facts 140*eed04cf9SJonathan Jaubart * @param string $sex 141*eed04cf9SJonathan Jaubart * @param array<string> $names 142*eed04cf9SJonathan Jaubart * @param array<string> $expected_new_facts 143*eed04cf9SJonathan Jaubart */ 144*eed04cf9SJonathan Jaubart public function testNewIndividualFactsWithNoFacts( 145*eed04cf9SJonathan Jaubart string $required_facts, 146*eed04cf9SJonathan Jaubart string $sex, 147*eed04cf9SJonathan Jaubart array $names, 148*eed04cf9SJonathan Jaubart array $expected_new_facts 149*eed04cf9SJonathan Jaubart ): void { 150*eed04cf9SJonathan Jaubart $gedcom_edit_service = new GedcomEditService(); 151*eed04cf9SJonathan Jaubart 152*eed04cf9SJonathan Jaubart $tree = $this->createMock(Tree::class); 153*eed04cf9SJonathan Jaubart $tree->method('getPreference')->with('QUICK_REQUIRED_FACTS')->willReturn($required_facts); 154*eed04cf9SJonathan Jaubart 155*eed04cf9SJonathan Jaubart $new_facts = $gedcom_edit_service->newIndividualFacts($tree, $sex, $names); 156*eed04cf9SJonathan Jaubart self::assertSameSize($expected_new_facts, $new_facts); 157*eed04cf9SJonathan Jaubart for ($i = 0; $i < count($expected_new_facts); $i++) { 158*eed04cf9SJonathan Jaubart /** @var \Fisharebest\Webtrees\Fact $new_fact */ 159*eed04cf9SJonathan Jaubart $new_fact = $new_facts->get($i); 160*eed04cf9SJonathan Jaubart self::assertSame($expected_new_facts[$i], $new_fact->tag()); 161*eed04cf9SJonathan Jaubart } 162*eed04cf9SJonathan Jaubart } 163*eed04cf9SJonathan Jaubart 164*eed04cf9SJonathan Jaubart /** 165*eed04cf9SJonathan Jaubart * Data provider for new family facts tests 166*eed04cf9SJonathan Jaubart * @return array<array<string|array<string>>> 167*eed04cf9SJonathan Jaubart */ 168*eed04cf9SJonathan Jaubart public function newFamilyFactsData(): array 169*eed04cf9SJonathan Jaubart { 170*eed04cf9SJonathan Jaubart return [ 171*eed04cf9SJonathan Jaubart ['', []], 172*eed04cf9SJonathan Jaubart ['MARR', ['FAM:MARR']], 173*eed04cf9SJonathan Jaubart ['FOOTAG', ['FAM:FOOTAG']], 174*eed04cf9SJonathan Jaubart ['MARR,DIV', ['FAM:MARR', 'FAM:DIV']], 175*eed04cf9SJonathan Jaubart ]; 176*eed04cf9SJonathan Jaubart } 177*eed04cf9SJonathan Jaubart 178*eed04cf9SJonathan Jaubart /** 179*eed04cf9SJonathan Jaubart * Data provider for new inidvidual facts tests 180*eed04cf9SJonathan Jaubart * @return array<array<string|array<string>>> 181*eed04cf9SJonathan Jaubart */ 182*eed04cf9SJonathan Jaubart public function newIndividualFactsData(): array 183*eed04cf9SJonathan Jaubart { 184*eed04cf9SJonathan Jaubart return [ 185*eed04cf9SJonathan Jaubart ['', 'F', ['1 NAME FOONAME'], ['INDI:SEX', 'INDI:NAME']], 186*eed04cf9SJonathan Jaubart ['BIRT', 'F', ['1 NAME FOONAME'], ['INDI:SEX', 'INDI:NAME', 'INDI:BIRT']], 187*eed04cf9SJonathan Jaubart ['FOOTAG', 'F', ['1 NAME FOONAME'], ['INDI:SEX', 'INDI:NAME', 'INDI:FOOTAG']], 188*eed04cf9SJonathan Jaubart ['BIRT,DEAT', 'F', ['1 NAME FOONAME'], ['INDI:SEX', 'INDI:NAME', 'INDI:BIRT', 'INDI:DEAT']], 189*eed04cf9SJonathan Jaubart ]; 190*eed04cf9SJonathan Jaubart } 191cb62cb3cSGreg Roach} 192