1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team 6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a25f0a04SGreg Roach * (at your option) any later version. 10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a25f0a04SGreg Roach * GNU General Public License for more details. 14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16a25f0a04SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees; 21a25f0a04SGreg Roach 2269675509SGreg Roachuse Fisharebest\Webtrees\Contracts\CacheFactoryInterface; 231fe542e9SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 2469c05a6eSGreg Roachuse Fisharebest\Webtrees\Services\GedcomExportService; 252c685d76SGreg Roachuse Fisharebest\Webtrees\Services\GedcomImportService; 265afbc57aSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 27e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 283cfcc809SGreg Roachuse InvalidArgumentException; 29*16ecfcafSGreg Roachuse Nyholm\Psr7\Factory\Psr17Factory; 3069675509SGreg Roachuse Symfony\Component\Cache\Adapter\NullAdapter; 313976b470SGreg Roach 32ea517a3bSGreg Roachuse function fclose; 33ea517a3bSGreg Roachuse function file_get_contents; 34ea517a3bSGreg Roachuse function preg_replace; 3594026f20SGreg Roachuse function stream_get_contents; 3694026f20SGreg Roach 37a25f0a04SGreg Roach/** 38a25f0a04SGreg Roach * Test harness for the class Tree 39a25f0a04SGreg Roach */ 40e5a6b4d4SGreg Roachclass TreeTest extends TestCase 41c1010edaSGreg Roach{ 42cd94ca66SGreg Roach protected static bool $uses_database = true; 43126654d7SGreg Roach 4492a78a2fSGreg Roach /** 4592a78a2fSGreg Roach * Things to run before every test. 4692a78a2fSGreg Roach */ 4757b69958SGreg Roach protected function setUp(): void 4869675509SGreg Roach { 4969675509SGreg Roach parent::setUp(); 5069675509SGreg Roach 51cd94ca66SGreg Roach $cache_factory = $this->createMock(CacheFactoryInterface::class); 5269675509SGreg Roach $cache_factory->method('array')->willReturn(new Cache(new NullAdapter())); 536b9cb339SGreg Roach Registry::cache($cache_factory); 5469675509SGreg Roach } 5569675509SGreg Roach 56a25f0a04SGreg Roach /** 57126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::__construct 58126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::id 59126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::name 60126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::title 6152348eb8SGreg Roach * @return void 62a25f0a04SGreg Roach */ 63126654d7SGreg Roach public function testConstructor(): void 64c1010edaSGreg Roach { 652c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 662c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 671e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 68126654d7SGreg Roach 695e933c21SGreg Roach self::assertSame('name', $tree->name()); 705e933c21SGreg Roach self::assertSame('title', $tree->title()); 71126654d7SGreg Roach } 72126654d7SGreg Roach 73126654d7SGreg Roach /** 74126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::getPreference 75126654d7SGreg Roach * @covers \Fisharebest\Webtrees\Tree::setPreference 76126654d7SGreg Roach * @return void 77126654d7SGreg Roach */ 78af343084SGreg Roach public function testTreePreferences(): void 79126654d7SGreg Roach { 802c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 812c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 821e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 83126654d7SGreg Roach 84126654d7SGreg Roach $tree->setPreference('foo', 'bar'); 858a07c98eSGreg Roach $pref = $tree->getPreference('foo'); 865e933c21SGreg Roach self::assertSame('bar', $pref); 87a25f0a04SGreg Roach } 88af343084SGreg Roach 89af343084SGreg Roach /** 90af343084SGreg Roach * @covers \Fisharebest\Webtrees\Tree::getUserPreference 91000dd58cSGreg Roach * @covers \Fisharebest\Webtrees\Tree::setUserPreference 92af343084SGreg Roach * @return void 93af343084SGreg Roach */ 94af343084SGreg Roach public function testUserTreePreferences(): void 95af343084SGreg Roach { 96e5a6b4d4SGreg Roach $user_service = new UserService(); 972c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 982c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 991e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 100e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 101af343084SGreg Roach 102af343084SGreg Roach $pref = $tree->getUserPreference($user, 'foo', 'default'); 1035e933c21SGreg Roach self::assertSame('default', $pref); 104af343084SGreg Roach 105af343084SGreg Roach $tree->setUserPreference($user, 'foo', 'bar'); 106af343084SGreg Roach $pref = $tree->getUserPreference($user, 'foo', 'default'); 1075e933c21SGreg Roach self::assertSame('bar', $pref); 1087d76853dSGreg Roach } 1097d76853dSGreg Roach 1107d76853dSGreg Roach /** 1117d76853dSGreg Roach * @covers \Fisharebest\Webtrees\Tree::createIndividual 1127d76853dSGreg Roach * @return void 1137d76853dSGreg Roach */ 1147d76853dSGreg Roach public function testCreateInvalidIndividual(): void 1157d76853dSGreg Roach { 1163cfcc809SGreg Roach $this->expectException(InvalidArgumentException::class); 1173cfcc809SGreg Roach 118e5a6b4d4SGreg Roach $user_service = new UserService(); 1192c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 1202c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 1211e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 122e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 1231fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 1247d76853dSGreg Roach Auth::login($user); 1257d76853dSGreg Roach 1267d76853dSGreg Roach $tree->createIndividual("0 @@ FOO\n1 SEX U"); 1277d76853dSGreg Roach } 1287d76853dSGreg Roach 1297d76853dSGreg Roach /** 130963fbaeeSGreg Roach * @covers \Fisharebest\Webtrees\Tree::createIndividual 131963fbaeeSGreg Roach * @return void 132963fbaeeSGreg Roach */ 133963fbaeeSGreg Roach public function testCreateIndividual(): void 134963fbaeeSGreg Roach { 135e5a6b4d4SGreg Roach $user_service = new UserService(); 1362c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 1372c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 1381e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 139e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 1401fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 141963fbaeeSGreg Roach Auth::login($user); 142963fbaeeSGreg Roach 1438f9b0fb2SGreg Roach $record = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 1445e933c21SGreg Roach self::assertTrue($record->isPendingAddition()); 145963fbaeeSGreg Roach 1461fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1'); 1478f9b0fb2SGreg Roach $record = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 1485e933c21SGreg Roach self::assertFalse($record->isPendingAddition()); 1498f9b0fb2SGreg Roach } 150963fbaeeSGreg Roach 1518f9b0fb2SGreg Roach /** 1527d76853dSGreg Roach * @covers \Fisharebest\Webtrees\Tree::createFamily 1538f9b0fb2SGreg Roach * @return void 1548f9b0fb2SGreg Roach */ 1557d76853dSGreg Roach public function testCreateInvalidFamily(): void 1568f9b0fb2SGreg Roach { 1573cfcc809SGreg Roach $this->expectException(InvalidArgumentException::class); 1583cfcc809SGreg Roach 159e5a6b4d4SGreg Roach $user_service = new UserService(); 1602c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 1612c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 1621e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 163e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 1641fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 1657d76853dSGreg Roach Auth::login($user); 166963fbaeeSGreg Roach 1677d76853dSGreg Roach $tree->createFamily("0 @@ FOO\n1 MARR Y"); 1688f9b0fb2SGreg Roach } 169963fbaeeSGreg Roach 1708f9b0fb2SGreg Roach /** 1718f9b0fb2SGreg Roach * @covers \Fisharebest\Webtrees\Tree::createFamily 1728f9b0fb2SGreg Roach * @return void 1738f9b0fb2SGreg Roach */ 1748f9b0fb2SGreg Roach public function testCreateFamily(): void 1758f9b0fb2SGreg Roach { 176e5a6b4d4SGreg Roach $user_service = new UserService(); 1772c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 1782c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 1791e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 180e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 1811fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 1828f9b0fb2SGreg Roach Auth::login($user); 1838f9b0fb2SGreg Roach 1848f9b0fb2SGreg Roach $record = $tree->createFamily("0 @@ FAM\n1 MARR Y"); 1855e933c21SGreg Roach self::assertTrue($record->isPendingAddition()); 1868f9b0fb2SGreg Roach 1871fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1'); 1888f9b0fb2SGreg Roach $record = $tree->createFamily("0 @@ FAM\n1 MARR Y"); 1895e933c21SGreg Roach self::assertFalse($record->isPendingAddition()); 1908f9b0fb2SGreg Roach } 1918f9b0fb2SGreg Roach 1928f9b0fb2SGreg Roach /** 1937d76853dSGreg Roach * @covers \Fisharebest\Webtrees\Tree::createMediaObject 1947d76853dSGreg Roach * @return void 1957d76853dSGreg Roach */ 1967d76853dSGreg Roach public function testCreateInvalidMediaObject(): void 1977d76853dSGreg Roach { 1983cfcc809SGreg Roach $this->expectException(InvalidArgumentException::class); 1993cfcc809SGreg Roach 200e5a6b4d4SGreg Roach $user_service = new UserService(); 2012c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 2022c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 2031e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 204e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 2051fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 2067d76853dSGreg Roach Auth::login($user); 2077d76853dSGreg Roach 2087d76853dSGreg Roach $tree->createMediaObject("0 @@ FOO\n1 MARR Y"); 2097d76853dSGreg Roach } 2107d76853dSGreg Roach 2117d76853dSGreg Roach /** 2127d76853dSGreg Roach * @covers \Fisharebest\Webtrees\Tree::createMediaObject 2137d76853dSGreg Roach * @return void 2147d76853dSGreg Roach */ 2157d76853dSGreg Roach public function testCreateMediaObject(): void 2167d76853dSGreg Roach { 217e5a6b4d4SGreg Roach $user_service = new UserService(); 2182c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 2192c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 2201e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 221e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 2221fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 2237d76853dSGreg Roach Auth::login($user); 2247d76853dSGreg Roach 2257d76853dSGreg Roach $record = $tree->createMediaObject("0 @@ OBJE\n1 FILE foo.jpeg"); 2265e933c21SGreg Roach self::assertTrue($record->isPendingAddition()); 2277d76853dSGreg Roach 2281fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1'); 2297d76853dSGreg Roach $record = $tree->createMediaObject("0 @@ OBJE\n1 FILE foo.jpeg"); 2305e933c21SGreg Roach self::assertFalse($record->isPendingAddition()); 2317d76853dSGreg Roach } 2327d76853dSGreg Roach 2337d76853dSGreg Roach /** 234bec87e94SGreg Roach * @covers \Fisharebest\Webtrees\Tree::createRecord 235bec87e94SGreg Roach * @return void 236bec87e94SGreg Roach */ 237bec87e94SGreg Roach public function testCreateInvalidRecord(): void 238bec87e94SGreg Roach { 2393cfcc809SGreg Roach $this->expectException(InvalidArgumentException::class); 2403cfcc809SGreg Roach 241e5a6b4d4SGreg Roach $user_service = new UserService(); 2422c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 2432c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 2441e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 245e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 2461fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 247bec87e94SGreg Roach Auth::login($user); 248bec87e94SGreg Roach 249bec87e94SGreg Roach $tree->createRecord("0 @@FOO\n1 NOTE noted"); 250bec87e94SGreg Roach } 251bec87e94SGreg Roach 252bec87e94SGreg Roach /** 253bec87e94SGreg Roach * @covers \Fisharebest\Webtrees\Tree::createRecord 254bec87e94SGreg Roach * @return void 255bec87e94SGreg Roach */ 256bec87e94SGreg Roach public function testCreateRecord(): void 257bec87e94SGreg Roach { 258e5a6b4d4SGreg Roach $user_service = new UserService(); 2592c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 2602c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 2611e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 262e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 2631fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 264bec87e94SGreg Roach Auth::login($user); 265bec87e94SGreg Roach 266bec87e94SGreg Roach $record = $tree->createRecord("0 @@ FOO\n1 NOTE noted"); 2675e933c21SGreg Roach self::assertTrue($record->isPendingAddition()); 268bec87e94SGreg Roach 2691fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1'); 270bec87e94SGreg Roach $record = $tree->createRecord("0 @@ FOO\n1 NOTE noted"); 2715e933c21SGreg Roach self::assertFalse($record->isPendingAddition()); 272bec87e94SGreg Roach } 273bec87e94SGreg Roach 274bec87e94SGreg Roach /** 2758f9b0fb2SGreg Roach * @covers \Fisharebest\Webtrees\Tree::significantIndividual 2768f9b0fb2SGreg Roach * @return void 2778f9b0fb2SGreg Roach */ 2788f9b0fb2SGreg Roach public function testSignificantIndividual(): void 2798f9b0fb2SGreg Roach { 2802c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 281e5a6b4d4SGreg Roach $user_service = new UserService(); 2822c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 2831e653452SGreg Roach $tree = $tree_service->create('name', 'title'); 284e5a6b4d4SGreg Roach $user = $user_service->create('user', 'User', 'user@example.com', 'secret'); 2851fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1'); 2868f9b0fb2SGreg Roach Auth::login($user); 2878f9b0fb2SGreg Roach 2885afbc57aSGreg Roach // Delete the tree's default individual. 2892c685d76SGreg Roach $gedcom_import_service->updateRecord('0 @X1@ INDI', $tree, true); 2905afbc57aSGreg Roach 2911f244d77SGreg Roach // No individuals in tree? Fake individual 2925e933c21SGreg Roach self::assertSame('I', $tree->significantIndividual($user)->xref()); 2938f9b0fb2SGreg Roach 2948f9b0fb2SGreg Roach $record1 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 2958f9b0fb2SGreg Roach $record2 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 2968f9b0fb2SGreg Roach $record3 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 2978f9b0fb2SGreg Roach $record4 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 2988f9b0fb2SGreg Roach 2998f9b0fb2SGreg Roach // Individuals exist? First one (lowest XREF). 3005e933c21SGreg Roach self::assertSame($record1->xref(), $tree->significantIndividual($user)->xref()); 3018f9b0fb2SGreg Roach 3028f9b0fb2SGreg Roach // Preference for tree? 3038f9b0fb2SGreg Roach $tree->setPreference('PEDIGREE_ROOT_ID', $record2->xref()); 3045e933c21SGreg Roach self::assertSame($record2->xref(), $tree->significantIndividual($user)->xref()); 3058f9b0fb2SGreg Roach 3068f9b0fb2SGreg Roach // User preference 3071fe542e9SGreg Roach $tree->setUserPreference($user, UserInterface::PREF_TREE_ACCOUNT_XREF, $record3->xref()); 3085e933c21SGreg Roach self::assertSame($record3->xref(), $tree->significantIndividual($user)->xref()); 3098f9b0fb2SGreg Roach 3108f9b0fb2SGreg Roach // User record 3111fe542e9SGreg Roach $tree->setUserPreference($user, UserInterface::PREF_TREE_DEFAULT_XREF, $record4->xref()); 3125e933c21SGreg Roach self::assertSame($record4->xref(), $tree->significantIndividual($user)->xref()); 313963fbaeeSGreg Roach } 314a7890280SGreg Roach 315a7890280SGreg Roach /** 3165cd281f4SGreg Roach * @covers \Fisharebest\Webtrees\Services\TreeService::importGedcomFile 317a7890280SGreg Roach * @return void 318a7890280SGreg Roach */ 319a7890280SGreg Roach public function testImportAndDeleteGedcomFile(): void 320a7890280SGreg Roach { 3212c685d76SGreg Roach $gedcom_import_service = new GedcomImportService(); 3222c685d76SGreg Roach $tree_service = new TreeService($gedcom_import_service); 323a7890280SGreg Roach $tree = $this->importTree('demo.ged'); 3245e933c21SGreg Roach self::assertNotNull($tree_service->all()->get('demo.ged')); 325432ff88aSGreg Roach Site::setPreference('DEFAULT_GEDCOM', $tree->name()); 326a7890280SGreg Roach 3275afbc57aSGreg Roach $tree_service->delete($tree); 328432ff88aSGreg Roach 3295e933c21SGreg Roach self::assertNull($tree_service->all()->get('demo.ged')); 3305e933c21SGreg Roach self::assertSame('', Site::getPreference('DEFAULT_GEDCOM')); 331a7890280SGreg Roach } 33215a3f100SGreg Roach 33315a3f100SGreg Roach /** 33415a3f100SGreg Roach * @covers \Fisharebest\Webtrees\Tree::hasPendingEdit 33515a3f100SGreg Roach * @return void 33615a3f100SGreg Roach */ 33715a3f100SGreg Roach public function testHasPendingEdits(): void 33815a3f100SGreg Roach { 339e5a6b4d4SGreg Roach $user_service = new UserService(); 34015a3f100SGreg Roach $tree = $this->importTree('demo.ged'); 341e5a6b4d4SGreg Roach $user = $user_service->create('admin', 'Administrator', 'admin@example.com', 'secret'); 3421fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1'); 34315a3f100SGreg Roach Auth::login($user); 34415a3f100SGreg Roach 3451fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1'); 34615a3f100SGreg Roach $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 3475e933c21SGreg Roach self::assertFalse($tree->hasPendingEdit()); 34815a3f100SGreg Roach 3491fe542e9SGreg Roach $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, ''); 35015a3f100SGreg Roach $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/"); 3515e933c21SGreg Roach self::assertTrue($tree->hasPendingEdit()); 35215a3f100SGreg Roach } 35394026f20SGreg Roach 35494026f20SGreg Roach /** 35569c05a6eSGreg Roach * @covers \Fisharebest\Webtrees\Services\GedcomExportService::export 35694026f20SGreg Roach * @return void 35794026f20SGreg Roach */ 35894026f20SGreg Roach public function testExportGedcom(): void 35994026f20SGreg Roach { 36094026f20SGreg Roach $tree = $this->importTree('demo.ged'); 36194026f20SGreg Roach 362*16ecfcafSGreg Roach $gedcom_export_service = new GedcomExportService(new Psr17Factory(), new Psr17Factory()); 36394026f20SGreg Roach 364ea517a3bSGreg Roach $resource = $gedcom_export_service->export($tree, true); 36594026f20SGreg Roach $original = file_get_contents(__DIR__ . '/../data/demo.ged'); 366ea517a3bSGreg Roach $export = stream_get_contents($resource); 367ea517a3bSGreg Roach fclose($resource); 36894026f20SGreg Roach 36969c05a6eSGreg Roach // The version, date and time in the HEAD record will be different. 37069c05a6eSGreg Roach $original = preg_replace('/\n2 VERS .*/', '', $original, 1); 37169c05a6eSGreg Roach $export = preg_replace('/\n2 VERS .*/', '', $export, 1); 37294026f20SGreg Roach $original = preg_replace('/\n1 DATE .. ... ..../', '', $original, 1); 37394026f20SGreg Roach $export = preg_replace('/\n1 DATE .. ... ..../', '', $export, 1); 37494026f20SGreg Roach $original = preg_replace('/\n2 TIME ..:..:../', '', $original, 1); 37594026f20SGreg Roach $export = preg_replace('/\n2 TIME ..:..:../', '', $export, 1); 37694026f20SGreg Roach 3775e933c21SGreg Roach self::assertSame($original, $export); 37894026f20SGreg Roach } 379a25f0a04SGreg Roach} 380