xref: /webtrees/tests/app/TreeTest.php (revision 69c05a6e92d49a04585e420425781681b3eaff1c)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
58fcd0d32SGreg Roach * Copyright (C) 2019 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
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees;
21a25f0a04SGreg Roach
225afbc57aSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsImport;
23*69c05a6eSGreg Roachuse Fisharebest\Webtrees\Services\GedcomExportService;
245afbc57aSGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
25e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
263cfcc809SGreg Roachuse InvalidArgumentException;
273976b470SGreg Roach
2894026f20SGreg Roachuse function stream_get_contents;
2994026f20SGreg Roach
30a25f0a04SGreg Roach/**
31a25f0a04SGreg Roach * Test harness for the class Tree
32a25f0a04SGreg Roach */
33e5a6b4d4SGreg Roachclass TreeTest extends TestCase
34c1010edaSGreg Roach{
35126654d7SGreg Roach    protected static $uses_database = true;
36126654d7SGreg Roach
37a25f0a04SGreg Roach    /**
38126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::__construct
39126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::id
40126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::name
41126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::title
4252348eb8SGreg Roach     * @return void
43a25f0a04SGreg Roach     */
44126654d7SGreg Roach    public function testConstructor(): void
45c1010edaSGreg Roach    {
461e653452SGreg Roach        $tree_service = new TreeService();
471e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
48126654d7SGreg Roach
491e653452SGreg Roach        $this->assertSame('name', $tree->name());
501e653452SGreg Roach        $this->assertSame('title', $tree->title());
51126654d7SGreg Roach    }
52126654d7SGreg Roach
53126654d7SGreg Roach    /**
54126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::getPreference
55126654d7SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::setPreference
56126654d7SGreg Roach     * @return void
57126654d7SGreg Roach     */
58af343084SGreg Roach    public function testTreePreferences(): void
59126654d7SGreg Roach    {
601e653452SGreg Roach        $tree_service = new TreeService();
611e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
62126654d7SGreg Roach
63126654d7SGreg Roach        $pref = $tree->getPreference('foo', 'default');
64126654d7SGreg Roach        $this->assertSame('default', $pref);
65126654d7SGreg Roach
66126654d7SGreg Roach        $tree->setPreference('foo', 'bar');
67126654d7SGreg Roach        $pref = $tree->getPreference('foo', 'default');
68126654d7SGreg Roach        $this->assertSame('bar', $pref);
69a25f0a04SGreg Roach    }
70af343084SGreg Roach
71af343084SGreg Roach    /**
72af343084SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::getUserPreference
73000dd58cSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::setUserPreference
74af343084SGreg Roach     * @return void
75af343084SGreg Roach     */
76af343084SGreg Roach    public function testUserTreePreferences(): void
77af343084SGreg Roach    {
78e5a6b4d4SGreg Roach        $user_service = new UserService();
791e653452SGreg Roach        $tree_service = new TreeService();
801e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
81e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
82af343084SGreg Roach
83af343084SGreg Roach        $pref = $tree->getUserPreference($user, 'foo', 'default');
84af343084SGreg Roach        $this->assertSame('default', $pref);
85af343084SGreg Roach
86af343084SGreg Roach        $tree->setUserPreference($user, 'foo', 'bar');
87af343084SGreg Roach        $pref = $tree->getUserPreference($user, 'foo', 'default');
88af343084SGreg Roach        $this->assertSame('bar', $pref);
89af343084SGreg Roach    }
90963fbaeeSGreg Roach
91963fbaeeSGreg Roach    /**
927d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::getNewXref
937d76853dSGreg Roach     * @return void
947d76853dSGreg Roach     */
957d76853dSGreg Roach    public function testGetNewXref(): void
967d76853dSGreg Roach    {
975afbc57aSGreg Roach        $tree_service = new TreeService();
985afbc57aSGreg Roach        $tree         = $tree_service->create('tree-name', 'Tree title');
997d76853dSGreg Roach
1005afbc57aSGreg Roach        // New trees have an individual X1.
1017d76853dSGreg Roach        $this->assertSame('X2', $tree->getNewXref());
1027d76853dSGreg Roach        $this->assertSame('X3', $tree->getNewXref());
1037d76853dSGreg Roach        $this->assertSame('X4', $tree->getNewXref());
1047d76853dSGreg Roach        $this->assertSame('X5', $tree->getNewXref());
1057d76853dSGreg Roach    }
1067d76853dSGreg Roach
1077d76853dSGreg Roach    /**
1087d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createIndividual
1097d76853dSGreg Roach     * @return void
1107d76853dSGreg Roach     */
1117d76853dSGreg Roach    public function testCreateInvalidIndividual(): void
1127d76853dSGreg Roach    {
1133cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
1143cfcc809SGreg Roach
115e5a6b4d4SGreg Roach        $user_service = new UserService();
1161e653452SGreg Roach        $tree_service = new TreeService();
1171e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
118e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
1197c4add84SGreg Roach        $user->setPreference(User::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();
1321e653452SGreg Roach        $tree_service = new TreeService();
1331e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
134e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
1357c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
136963fbaeeSGreg Roach        Auth::login($user);
137963fbaeeSGreg Roach
1388f9b0fb2SGreg Roach        $record = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
1398f9b0fb2SGreg Roach        $this->assertTrue($record->isPendingAddition());
140963fbaeeSGreg Roach
1417c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '1');
1428f9b0fb2SGreg Roach        $record = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
1438f9b0fb2SGreg Roach        $this->assertFalse($record->isPendingAddition());
1448f9b0fb2SGreg Roach    }
145963fbaeeSGreg Roach
1468f9b0fb2SGreg Roach    /**
1477d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createFamily
1488f9b0fb2SGreg Roach     * @return void
1498f9b0fb2SGreg Roach     */
1507d76853dSGreg Roach    public function testCreateInvalidFamily(): void
1518f9b0fb2SGreg Roach    {
1523cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
1533cfcc809SGreg Roach
154e5a6b4d4SGreg Roach        $user_service = new UserService();
1551e653452SGreg Roach        $tree_service = new TreeService();
1561e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
157e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
1587c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
1597d76853dSGreg Roach        Auth::login($user);
160963fbaeeSGreg Roach
1617d76853dSGreg Roach        $tree->createFamily("0 @@ FOO\n1 MARR Y");
1628f9b0fb2SGreg Roach    }
163963fbaeeSGreg Roach
1648f9b0fb2SGreg Roach    /**
1658f9b0fb2SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createFamily
1668f9b0fb2SGreg Roach     * @return void
1678f9b0fb2SGreg Roach     */
1688f9b0fb2SGreg Roach    public function testCreateFamily(): void
1698f9b0fb2SGreg Roach    {
170e5a6b4d4SGreg Roach        $user_service = new UserService();
1711e653452SGreg Roach        $tree_service = new TreeService();
1721e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
173e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
1747c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
1758f9b0fb2SGreg Roach        Auth::login($user);
1768f9b0fb2SGreg Roach
1778f9b0fb2SGreg Roach        $record = $tree->createFamily("0 @@ FAM\n1 MARR Y");
1788f9b0fb2SGreg Roach        $this->assertTrue($record->isPendingAddition());
1798f9b0fb2SGreg Roach
1807c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '1');
1818f9b0fb2SGreg Roach        $record = $tree->createFamily("0 @@ FAM\n1 MARR Y");
1828f9b0fb2SGreg Roach        $this->assertFalse($record->isPendingAddition());
1838f9b0fb2SGreg Roach    }
1848f9b0fb2SGreg Roach
1858f9b0fb2SGreg Roach    /**
1867d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createMediaObject
1877d76853dSGreg Roach     * @return void
1887d76853dSGreg Roach     */
1897d76853dSGreg Roach    public function testCreateInvalidMediaObject(): void
1907d76853dSGreg Roach    {
1913cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
1923cfcc809SGreg Roach
193e5a6b4d4SGreg Roach        $user_service = new UserService();
1941e653452SGreg Roach        $tree_service = new TreeService();
1951e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
196e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
1977c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
1987d76853dSGreg Roach        Auth::login($user);
1997d76853dSGreg Roach
2007d76853dSGreg Roach        $tree->createMediaObject("0 @@ FOO\n1 MARR Y");
2017d76853dSGreg Roach    }
2027d76853dSGreg Roach
2037d76853dSGreg Roach    /**
2047d76853dSGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createMediaObject
2057d76853dSGreg Roach     * @return void
2067d76853dSGreg Roach     */
2077d76853dSGreg Roach    public function testCreateMediaObject(): void
2087d76853dSGreg Roach    {
209e5a6b4d4SGreg Roach        $user_service = new UserService();
2101e653452SGreg Roach        $tree_service = new TreeService();
2111e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
212e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
2137c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
2147d76853dSGreg Roach        Auth::login($user);
2157d76853dSGreg Roach
2167d76853dSGreg Roach        $record = $tree->createMediaObject("0 @@ OBJE\n1 FILE foo.jpeg");
2177d76853dSGreg Roach        $this->assertTrue($record->isPendingAddition());
2187d76853dSGreg Roach
2197c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '1');
2207d76853dSGreg Roach        $record = $tree->createMediaObject("0 @@ OBJE\n1 FILE foo.jpeg");
2217d76853dSGreg Roach        $this->assertFalse($record->isPendingAddition());
2227d76853dSGreg Roach    }
2237d76853dSGreg Roach
2247d76853dSGreg Roach    /**
225bec87e94SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createRecord
226bec87e94SGreg Roach     * @return void
227bec87e94SGreg Roach     */
228bec87e94SGreg Roach    public function testCreateInvalidRecord(): void
229bec87e94SGreg Roach    {
2303cfcc809SGreg Roach        $this->expectException(InvalidArgumentException::class);
2313cfcc809SGreg Roach
232e5a6b4d4SGreg Roach        $user_service = new UserService();
2331e653452SGreg Roach        $tree_service = new TreeService();
2341e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
235e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
2367c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
237bec87e94SGreg Roach        Auth::login($user);
238bec87e94SGreg Roach
239bec87e94SGreg Roach        $tree->createRecord("0 @@FOO\n1 NOTE noted");
240bec87e94SGreg Roach    }
241bec87e94SGreg Roach
242bec87e94SGreg Roach    /**
243bec87e94SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::createRecord
244bec87e94SGreg Roach     * @return void
245bec87e94SGreg Roach     */
246bec87e94SGreg Roach    public function testCreateRecord(): void
247bec87e94SGreg Roach    {
248e5a6b4d4SGreg Roach        $user_service = new UserService();
2491e653452SGreg Roach        $tree_service = new TreeService();
2501e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
251e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
2527c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
253bec87e94SGreg Roach        Auth::login($user);
254bec87e94SGreg Roach
255bec87e94SGreg Roach        $record = $tree->createRecord("0 @@ FOO\n1 NOTE noted");
256bec87e94SGreg Roach        $this->assertTrue($record->isPendingAddition());
257bec87e94SGreg Roach
2587c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '1');
259bec87e94SGreg Roach        $record = $tree->createRecord("0 @@ FOO\n1 NOTE noted");
260bec87e94SGreg Roach        $this->assertFalse($record->isPendingAddition());
261bec87e94SGreg Roach    }
262bec87e94SGreg Roach
263bec87e94SGreg Roach    /**
2648f9b0fb2SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::significantIndividual
2658f9b0fb2SGreg Roach     * @return void
2668f9b0fb2SGreg Roach     */
2678f9b0fb2SGreg Roach    public function testSignificantIndividual(): void
2688f9b0fb2SGreg Roach    {
269e5a6b4d4SGreg Roach        $user_service = new UserService();
2701e653452SGreg Roach        $tree_service = new TreeService();
2711e653452SGreg Roach        $tree         = $tree_service->create('name', 'title');
272e5a6b4d4SGreg Roach        $user         = $user_service->create('user', 'User', 'user@example.com', 'secret');
2737c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '1');
2748f9b0fb2SGreg Roach        Auth::login($user);
2758f9b0fb2SGreg Roach
2765afbc57aSGreg Roach        // Delete the tree's default individual.
2775afbc57aSGreg Roach        FunctionsImport::updateRecord('0 @X1@ INDI', $tree, true);
2785afbc57aSGreg Roach
2798f9b0fb2SGreg Roach        // No individuals in tree?  Dummy individual
2808f9b0fb2SGreg Roach        $this->assertSame('I', $tree->significantIndividual($user)->xref());
2818f9b0fb2SGreg Roach
2828f9b0fb2SGreg Roach        $record1 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2838f9b0fb2SGreg Roach        $record2 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2848f9b0fb2SGreg Roach        $record3 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2858f9b0fb2SGreg Roach        $record4 = $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
2868f9b0fb2SGreg Roach
2878f9b0fb2SGreg Roach        // Individuals exist?  First one (lowest XREF).
2888f9b0fb2SGreg Roach        $this->assertSame($record1->xref(), $tree->significantIndividual($user)->xref());
2898f9b0fb2SGreg Roach
2908f9b0fb2SGreg Roach        // Preference for tree?
2918f9b0fb2SGreg Roach        $tree->setPreference('PEDIGREE_ROOT_ID', $record2->xref());
2928f9b0fb2SGreg Roach        $this->assertSame($record2->xref(), $tree->significantIndividual($user)->xref());
2938f9b0fb2SGreg Roach
2948f9b0fb2SGreg Roach        // User preference
2957c4add84SGreg Roach        $tree->setUserPreference($user, User::PREF_TREE_ACCOUNT_XREF, $record3->xref());
2968f9b0fb2SGreg Roach        $this->assertSame($record3->xref(), $tree->significantIndividual($user)->xref());
2978f9b0fb2SGreg Roach
2988f9b0fb2SGreg Roach        // User record
2997c4add84SGreg Roach        $tree->setUserPreference($user, User::PREF_TREE_DEFAULT_XREF, $record4->xref());
3008f9b0fb2SGreg Roach        $this->assertSame($record4->xref(), $tree->significantIndividual($user)->xref());
301963fbaeeSGreg Roach    }
302a7890280SGreg Roach
303a7890280SGreg Roach    /**
304a7890280SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::importGedcomFile
305a7890280SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::deleteGenealogyData
306a7890280SGreg Roach     * @return void
307a7890280SGreg Roach     */
308a7890280SGreg Roach    public function testImportAndDeleteGedcomFile(): void
309a7890280SGreg Roach    {
3105afbc57aSGreg Roach        $tree_service = new TreeService();
311a7890280SGreg Roach        $tree = $this->importTree('demo.ged');
3121e653452SGreg Roach        $this->assertNotNull($tree_service->all()->get('demo.ged'));
313432ff88aSGreg Roach        Site::setPreference('DEFAULT_GEDCOM', $tree->name());
314a7890280SGreg Roach
3155afbc57aSGreg Roach        $tree_service->delete($tree);
316432ff88aSGreg Roach
3171e653452SGreg Roach        $this->assertNull($tree_service->all()->get('demo.ged'));
318432ff88aSGreg Roach        $this->assertSame('', Site::getPreference('DEFAULT_GEDCOM'));
319a7890280SGreg Roach    }
32015a3f100SGreg Roach
32115a3f100SGreg Roach    /**
32215a3f100SGreg Roach     * @covers \Fisharebest\Webtrees\Tree::hasPendingEdit
32315a3f100SGreg Roach     * @return void
32415a3f100SGreg Roach     */
32515a3f100SGreg Roach    public function testHasPendingEdits(): void
32615a3f100SGreg Roach    {
327e5a6b4d4SGreg Roach        $user_service = new UserService();
32815a3f100SGreg Roach        $tree         = $this->importTree('demo.ged');
329e5a6b4d4SGreg Roach        $user         = $user_service->create('admin', 'Administrator', 'admin@example.com', 'secret');
3307c4add84SGreg Roach        $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1');
33115a3f100SGreg Roach        Auth::login($user);
33215a3f100SGreg Roach
3337c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '1');
33415a3f100SGreg Roach        $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
33515a3f100SGreg Roach        $this->assertFalse($tree->hasPendingEdit());
33615a3f100SGreg Roach
3377c4add84SGreg Roach        $user->setPreference(User::PREF_AUTO_ACCEPT_EDITS, '');
33815a3f100SGreg Roach        $tree->createIndividual("0 @@ INDI\n1 SEX F\n1 NAME Foo /Bar/");
33915a3f100SGreg Roach        $this->assertTrue($tree->hasPendingEdit());
34015a3f100SGreg Roach    }
34194026f20SGreg Roach
34294026f20SGreg Roach    /**
343*69c05a6eSGreg Roach     * @covers \Fisharebest\Webtrees\Services\GedcomExportService::export
34494026f20SGreg Roach     * @return void
34594026f20SGreg Roach     */
34694026f20SGreg Roach    public function testExportGedcom(): void
34794026f20SGreg Roach    {
34894026f20SGreg Roach        $tree = $this->importTree('demo.ged');
34994026f20SGreg Roach
350803193feSGreg Roach        $fp = fopen('php://memory', 'wb');
35194026f20SGreg Roach
352*69c05a6eSGreg Roach        $gedcom_export_service = new GedcomExportService();
353*69c05a6eSGreg Roach        $gedcom_export_service->export($tree, $fp, true);
35494026f20SGreg Roach
35594026f20SGreg Roach        rewind($fp);
35694026f20SGreg Roach
35794026f20SGreg Roach        $original = file_get_contents(__DIR__ . '/../data/demo.ged');
35894026f20SGreg Roach        $export   = stream_get_contents($fp);
35994026f20SGreg Roach
360*69c05a6eSGreg Roach        // The version, date and time in the HEAD record will be different.
361*69c05a6eSGreg Roach        $original = preg_replace('/\n2 VERS .*/', '', $original, 1);
362*69c05a6eSGreg Roach        $export   = preg_replace('/\n2 VERS .*/', '', $export, 1);
36394026f20SGreg Roach        $original = preg_replace('/\n1 DATE .. ... ..../', '', $original, 1);
36494026f20SGreg Roach        $export   = preg_replace('/\n1 DATE .. ... ..../', '', $export, 1);
36594026f20SGreg Roach        $original = preg_replace('/\n2 TIME ..:..:../', '', $original, 1);
36694026f20SGreg Roach        $export   = preg_replace('/\n2 TIME ..:..:../', '', $export, 1);
36794026f20SGreg Roach
36894026f20SGreg Roach        $this->assertSame($original, $export);
36994026f20SGreg Roach    }
370a25f0a04SGreg Roach}
371