xref: /webtrees/tests/app/TreeTest.php (revision 57b6995839fec603cfb57771a7d3699cfb136638)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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;
2969675509SGreg Roachuse Symfony\Component\Cache\Adapter\NullAdapter;
303976b470SGreg Roach
31ea517a3bSGreg Roachuse function fclose;
32ea517a3bSGreg Roachuse function file_get_contents;
33ea517a3bSGreg Roachuse function preg_replace;
3494026f20SGreg Roachuse function stream_get_contents;
3594026f20SGreg Roach
36a25f0a04SGreg Roach/**
37a25f0a04SGreg Roach * Test harness for the class Tree
38a25f0a04SGreg Roach */
39e5a6b4d4SGreg Roachclass TreeTest extends TestCase
40c1010edaSGreg Roach{
41cd94ca66SGreg Roach    protected static bool $uses_database = true;
42126654d7SGreg Roach
43*57b69958SGreg Roach    protected function setUp(): void
4469675509SGreg Roach    {
4569675509SGreg Roach        parent::setUp();
4669675509SGreg Roach
47cd94ca66SGreg Roach        $cache_factory = $this->createMock(CacheFactoryInterface::class);
4869675509SGreg Roach        $cache_factory->method('array')->willReturn(new Cache(new NullAdapter()));
496b9cb339SGreg Roach        Registry::cache($cache_factory);
5069675509SGreg Roach    }
5169675509SGreg Roach
52a25f0a04SGreg Roach    /**
53126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::__construct
54126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::id
55126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::name
56126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::title
5752348eb8SGreg Roach     * @return void
58a25f0a04SGreg Roach     */
59126654d7SGreg Roach    public function testConstructor(): void
60c1010edaSGreg Roach    {
612c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
622c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
631e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
64126654d7SGreg Roach
655e933c21SGreg Roach        self::assertSame('name', $tree->name());
665e933c21SGreg Roach        self::assertSame('title', $tree->title());
67126654d7SGreg Roach    }
68126654d7SGreg Roach
69126654d7SGreg Roach    /**
70126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::getPreference
71126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::setPreference
72126654d7SGreg Roach     * @return void
73126654d7SGreg Roach     */
74af343084SGreg Roach    public function testTreePreferences(): void
75126654d7SGreg Roach    {
762c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
772c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
781e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
79126654d7SGreg Roach
80126654d7SGreg Roach        $tree->setPreference('foo', 'bar');
818a07c98eSGreg Roach        $pref = $tree->getPreference('foo');
825e933c21SGreg Roach        self::assertSame('bar', $pref);
83a25f0a04SGreg Roach    }
84af343084SGreg Roach
85af343084SGreg Roach    /**
86af343084SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::getUserPreference
87000dd58cSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::setUserPreference
88af343084SGreg Roach     * @return void
89af343084SGreg Roach     */
90af343084SGreg Roach    public function testUserTreePreferences(): void
91af343084SGreg Roach    {
92e5a6b4d4SGreg Roach        $user_service          = new UserService();
932c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
942c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
951e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
96e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
97af343084SGreg Roach
98af343084SGreg Roach        $pref = $tree->getUserPreference($user, 'foo', 'default');
995e933c21SGreg Roach        self::assertSame('default', $pref);
100af343084SGreg Roach
101af343084SGreg Roach        $tree->setUserPreference($user, 'foo', 'bar');
102af343084SGreg Roach        $pref = $tree->getUserPreference($user, 'foo', 'default');
1035e933c21SGreg Roach        self::assertSame('bar', $pref);
1047d76853dSGreg Roach    }
1057d76853dSGreg Roach
1067d76853dSGreg Roach    /**
1077d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createIndividual
1087d76853dSGreg Roach     * @return void
1097d76853dSGreg Roach     */
1107d76853dSGreg Roach    public function testCreateInvalidIndividual(): void
1117d76853dSGreg Roach    {
1123cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
1133cfcc809SGreg Roach
114e5a6b4d4SGreg Roach        $user_service          = new UserService();
1152c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
1162c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
1171e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
118e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
1191fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
1207d76853dSGreg Roach        Auth::login($user);
1217d76853dSGreg Roach
1227d76853dSGreg Roach        $tree->createIndividual("0 @@ FOO\n1 SEX U");
1237d76853dSGreg Roach    }
1247d76853dSGreg Roach
1257d76853dSGreg Roach    /**
126963fbaeeSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createIndividual
127963fbaeeSGreg Roach     * @return void
128963fbaeeSGreg Roach     */
129963fbaeeSGreg Roach    public function testCreateIndividual(): void
130963fbaeeSGreg Roach    {
131e5a6b4d4SGreg Roach        $user_service          = new UserService();
1322c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
1332c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
1341e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
135e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
1361fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
137963fbaeeSGreg Roach        Auth::login($user);
138963fbaeeSGreg Roach
1398f9b0fb2SGreg Roach        $record = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
1405e933c21SGreg Roach        self::assertTrue($record->isPendingAddition());
141963fbaeeSGreg Roach
1421fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1');
1438f9b0fb2SGreg Roach        $record = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
1445e933c21SGreg Roach        self::assertFalse($record->isPendingAddition());
1458f9b0fb2SGreg Roach    }
146963fbaeeSGreg Roach
1478f9b0fb2SGreg Roach    /**
1487d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createFamily
1498f9b0fb2SGreg Roach     * @return void
1508f9b0fb2SGreg Roach     */
1517d76853dSGreg Roach    public function testCreateInvalidFamily(): void
1528f9b0fb2SGreg Roach    {
1533cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
1543cfcc809SGreg Roach
155e5a6b4d4SGreg Roach        $user_service          = new UserService();
1562c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
1572c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
1581e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
159e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
1601fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
1617d76853dSGreg Roach        Auth::login($user);
162963fbaeeSGreg Roach
1637d76853dSGreg Roach        $tree->createFamily("0 @@ FOO\n1 MARR Y");
1648f9b0fb2SGreg Roach    }
165963fbaeeSGreg Roach
1668f9b0fb2SGreg Roach    /**
1678f9b0fb2SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createFamily
1688f9b0fb2SGreg Roach     * @return void
1698f9b0fb2SGreg Roach     */
1708f9b0fb2SGreg Roach    public function testCreateFamily(): void
1718f9b0fb2SGreg Roach    {
172e5a6b4d4SGreg Roach        $user_service          = new UserService();
1732c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
1742c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
1751e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
176e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
1771fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
1788f9b0fb2SGreg Roach        Auth::login($user);
1798f9b0fb2SGreg Roach
1808f9b0fb2SGreg Roach        $record = $tree->createFamily("0 @@ FAM\n1 MARR Y");
1815e933c21SGreg Roach        self::assertTrue($record->isPendingAddition());
1828f9b0fb2SGreg Roach
1831fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1');
1848f9b0fb2SGreg Roach        $record = $tree->createFamily("0 @@ FAM\n1 MARR Y");
1855e933c21SGreg Roach        self::assertFalse($record->isPendingAddition());
1868f9b0fb2SGreg Roach    }
1878f9b0fb2SGreg Roach
1888f9b0fb2SGreg Roach    /**
1897d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createMediaObject
1907d76853dSGreg Roach     * @return void
1917d76853dSGreg Roach     */
1927d76853dSGreg Roach    public function testCreateInvalidMediaObject(): void
1937d76853dSGreg Roach    {
1943cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
1953cfcc809SGreg Roach
196e5a6b4d4SGreg Roach        $user_service          = new UserService();
1972c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
1982c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
1991e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
200e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
2011fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
2027d76853dSGreg Roach        Auth::login($user);
2037d76853dSGreg Roach
2047d76853dSGreg Roach        $tree->createMediaObject("0 @@ FOO\n1 MARR Y");
2057d76853dSGreg Roach    }
2067d76853dSGreg Roach
2077d76853dSGreg Roach    /**
2087d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createMediaObject
2097d76853dSGreg Roach     * @return void
2107d76853dSGreg Roach     */
2117d76853dSGreg Roach    public function testCreateMediaObject(): void
2127d76853dSGreg Roach    {
213e5a6b4d4SGreg Roach        $user_service          = new UserService();
2142c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
2152c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
2161e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
217e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
2181fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
2197d76853dSGreg Roach        Auth::login($user);
2207d76853dSGreg Roach
2217d76853dSGreg Roach        $record = $tree->createMediaObject("0 @@ OBJE\n1 FILE foo.jpeg");
2225e933c21SGreg Roach        self::assertTrue($record->isPendingAddition());
2237d76853dSGreg Roach
2241fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1');
2257d76853dSGreg Roach        $record = $tree->createMediaObject("0 @@ OBJE\n1 FILE foo.jpeg");
2265e933c21SGreg Roach        self::assertFalse($record->isPendingAddition());
2277d76853dSGreg Roach    }
2287d76853dSGreg Roach
2297d76853dSGreg Roach    /**
230bec87e94SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createRecord
231bec87e94SGreg Roach     * @return void
232bec87e94SGreg Roach     */
233bec87e94SGreg Roach    public function testCreateInvalidRecord(): void
234bec87e94SGreg Roach    {
2353cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
2363cfcc809SGreg Roach
237e5a6b4d4SGreg Roach        $user_service          = new UserService();
2382c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
2392c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
2401e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
241e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
2421fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
243bec87e94SGreg Roach        Auth::login($user);
244bec87e94SGreg Roach
245bec87e94SGreg Roach        $tree->createRecord("0 @@FOO\n1 NOTE noted");
246bec87e94SGreg Roach    }
247bec87e94SGreg Roach
248bec87e94SGreg Roach    /**
249bec87e94SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createRecord
250bec87e94SGreg Roach     * @return void
251bec87e94SGreg Roach     */
252bec87e94SGreg Roach    public function testCreateRecord(): void
253bec87e94SGreg Roach    {
254e5a6b4d4SGreg Roach        $user_service          = new UserService();
2552c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
2562c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
2571e653452SGreg Roach        $tree                  = $tree_service->create('name', 'title');
258e5a6b4d4SGreg Roach        $user                  = $user_service->create('user', 'User', 'user@example.com', 'secret');
2591fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
260bec87e94SGreg Roach        Auth::login($user);
261bec87e94SGreg Roach
262bec87e94SGreg Roach        $record = $tree->createRecord("0 @@ FOO\n1 NOTE noted");
2635e933c21SGreg Roach        self::assertTrue($record->isPendingAddition());
264bec87e94SGreg Roach
2651fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1');
266bec87e94SGreg Roach        $record = $tree->createRecord("0 @@ FOO\n1 NOTE noted");
2675e933c21SGreg Roach        self::assertFalse($record->isPendingAddition());
268bec87e94SGreg Roach    }
269bec87e94SGreg Roach
270bec87e94SGreg Roach    /**
2718f9b0fb2SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::significantIndividual
2728f9b0fb2SGreg Roach     * @return void
2738f9b0fb2SGreg Roach     */
2748f9b0fb2SGreg Roach    public function testSignificantIndividual(): void
2758f9b0fb2SGreg Roach    {
2762c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
277e5a6b4d4SGreg Roach        $user_service = new UserService();
2782c685d76SGreg Roach        $tree_service = new TreeService($gedcom_import_service);
2791e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
280e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
2811fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1');
2828f9b0fb2SGreg Roach        Auth::login($user);
2838f9b0fb2SGreg Roach
2845afbc57aSGreg Roach        // Delete the tree's default individual.
2852c685d76SGreg Roach        $gedcom_import_service->updateRecord('0 @X1@ INDI', $tree, true);
2865afbc57aSGreg Roach
2871f244d77SGreg Roach        // No individuals in tree?  Fake individual
2885e933c21SGreg Roach        self::assertSame('I', $tree->significantIndividual($user)->xref());
2898f9b0fb2SGreg Roach
2908f9b0fb2SGreg Roach        $record1 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2918f9b0fb2SGreg Roach        $record2 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2928f9b0fb2SGreg Roach        $record3 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2938f9b0fb2SGreg Roach        $record4 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2948f9b0fb2SGreg Roach
2958f9b0fb2SGreg Roach        // Individuals exist?  First one (lowest XREF).
2965e933c21SGreg Roach        self::assertSame($record1->xref(), $tree->significantIndividual($user)->xref());
2978f9b0fb2SGreg Roach
2988f9b0fb2SGreg Roach        // Preference for tree?
2998f9b0fb2SGreg Roach        $tree->setPreference('PEDIGREE_ROOT_ID', $record2->xref());
3005e933c21SGreg Roach        self::assertSame($record2->xref(), $tree->significantIndividual($user)->xref());
3018f9b0fb2SGreg Roach
3028f9b0fb2SGreg Roach        // User preference
3031fe542e9SGreg Roach        $tree->setUserPreference($user, UserInterface::PREF_TREE_ACCOUNT_XREF, $record3->xref());
3045e933c21SGreg Roach        self::assertSame($record3->xref(), $tree->significantIndividual($user)->xref());
3058f9b0fb2SGreg Roach
3068f9b0fb2SGreg Roach        // User record
3071fe542e9SGreg Roach        $tree->setUserPreference($user, UserInterface::PREF_TREE_DEFAULT_XREF, $record4->xref());
3085e933c21SGreg Roach        self::assertSame($record4->xref(), $tree->significantIndividual($user)->xref());
309963fbaeeSGreg Roach    }
310a7890280SGreg Roach
311a7890280SGreg Roach    /**
3125cd281f4SGreg Roach     * @covers \Fisharebest\Webtrees\Services\TreeService::importGedcomFile
3135cd281f4SGreg Roach     * @covers \Fisharebest\Webtrees\Services\TreeService::deleteGenealogyData
314a7890280SGreg Roach     * @return void
315a7890280SGreg Roach     */
316a7890280SGreg Roach    public function testImportAndDeleteGedcomFile(): void
317a7890280SGreg Roach    {
3182c685d76SGreg Roach        $gedcom_import_service = new GedcomImportService();
3192c685d76SGreg Roach        $tree_service          = new TreeService($gedcom_import_service);
320a7890280SGreg Roach        $tree                  = $this->importTree('demo.ged');
3215e933c21SGreg Roach        self::assertNotNull($tree_service->all()->get('demo.ged'));
322432ff88aSGreg Roach        Site::setPreference('DEFAULT_GEDCOM', $tree->name());
323a7890280SGreg Roach
3245afbc57aSGreg Roach        $tree_service->delete($tree);
325432ff88aSGreg Roach
3265e933c21SGreg Roach        self::assertNull($tree_service->all()->get('demo.ged'));
3275e933c21SGreg Roach        self::assertSame('', Site::getPreference('DEFAULT_GEDCOM'));
328a7890280SGreg Roach    }
32915a3f100SGreg Roach
33015a3f100SGreg Roach    /**
33115a3f100SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::hasPendingEdit
33215a3f100SGreg Roach     * @return void
33315a3f100SGreg Roach     */
33415a3f100SGreg Roach    public function testHasPendingEdits(): void
33515a3f100SGreg Roach    {
336e5a6b4d4SGreg Roach        $user_service = new UserService();
33715a3f100SGreg Roach        $tree         = $this->importTree('demo.ged');
338e5a6b4d4SGreg Roach        $user         = $user_service->create('admin', 'Administrator', 'admin@example.com', 'secret');
3391fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
34015a3f100SGreg Roach        Auth::login($user);
34115a3f100SGreg Roach
3421fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '1');
34315a3f100SGreg Roach        $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
3445e933c21SGreg Roach        self::assertFalse($tree->hasPendingEdit());
34515a3f100SGreg Roach
3461fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_AUTO_ACCEPT_EDITS, '');
34715a3f100SGreg Roach        $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
3485e933c21SGreg Roach        self::assertTrue($tree->hasPendingEdit());
34915a3f100SGreg Roach    }
35094026f20SGreg Roach
35194026f20SGreg Roach    /**
35269c05a6eSGreg Roach     * @covers \Fisharebest\Webtrees\Services\GedcomExportService::export
35394026f20SGreg Roach     * @return void
35494026f20SGreg Roach     */
35594026f20SGreg Roach    public function testExportGedcom(): void
35694026f20SGreg Roach    {
35794026f20SGreg Roach        $tree = $this->importTree('demo.ged');
35894026f20SGreg Roach
35969c05a6eSGreg Roach        $gedcom_export_service = new GedcomExportService();
36094026f20SGreg Roach
361ea517a3bSGreg Roach        $resource = $gedcom_export_service->export($tree, true);
36294026f20SGreg Roach        $original = file_get_contents(__DIR__ . '/../data/demo.ged');
363ea517a3bSGreg Roach        $export   = stream_get_contents($resource);
364ea517a3bSGreg Roach        fclose($resource);
36594026f20SGreg Roach
36669c05a6eSGreg Roach        // The version, date and time in the HEAD record will be different.
36769c05a6eSGreg Roach        $original = preg_replace('/\n2 VERS .*/', '', $original, 1);
36869c05a6eSGreg Roach        $export   = preg_replace('/\n2 VERS .*/', '', $export, 1);
36994026f20SGreg Roach        $original = preg_replace('/\n1 DATE .. ... ..../', '', $original, 1);
37094026f20SGreg Roach        $export   = preg_replace('/\n1 DATE .. ... ..../', '', $export, 1);
37194026f20SGreg Roach        $original = preg_replace('/\n2 TIME ..:..:../', '', $original, 1);
37294026f20SGreg Roach        $export   = preg_replace('/\n2 TIME ..:..:../', '', $export, 1);
37394026f20SGreg Roach
3745e933c21SGreg Roach        self::assertSame($original, $export);
37594026f20SGreg Roach    }
376a25f0a04SGreg Roach}
377