summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2021-02-01 16:50:30 +0000
committerGreg Roach <greg@subaqua.co.uk>2021-02-02 16:52:32 +0000
commitc2ed51d13a57743094c11c8fe84befd9d4f158cd (patch)
tree4f2d541fed3550f5d64f9754e9d37f5e9b9ce447 /tests
parent4d2b9c53c95ad846160295dd8f4136a5b53f9f7b (diff)
downloadwebtrees-c2ed51d13a57743094c11c8fe84befd9d4f158cd.tar.gz
webtrees-c2ed51d13a57743094c11c8fe84befd9d4f158cd.tar.bz2
webtrees-c2ed51d13a57743094c11c8fe84befd9d4f158cd.zip
Merge GEDCOM element code from 2.1 branch
Diffstat (limited to 'tests')
-rw-r--r--tests/app/Elements/DateValueTest.php (renamed from tests/app/GedcomTagTest.php)22
-rw-r--r--tests/app/Elements/LanguageIdTest.php44
-rw-r--r--tests/app/Elements/XrefFamilyTest.php143
-rw-r--r--tests/app/Elements/XrefIndividualTest.php146
-rw-r--r--tests/app/Elements/XrefLocationTest.php145
-rw-r--r--tests/app/Elements/XrefMediaTest.php144
-rw-r--r--tests/app/Elements/XrefNoteTest.php144
-rw-r--r--tests/app/Elements/XrefRepositoryTest.php144
-rw-r--r--tests/app/Elements/XrefSourceTest.php144
-rw-r--r--tests/app/Elements/XrefSubmissionTest.php144
-rw-r--r--tests/app/Elements/XrefSubmitterTest.php144
11 files changed, 1356 insertions, 8 deletions
diff --git a/tests/app/GedcomTagTest.php b/tests/app/Elements/DateValueTest.php
index 11679677e1..bf31ab99c1 100644
--- a/tests/app/GedcomTagTest.php
+++ b/tests/app/Elements/DateValueTest.php
@@ -17,22 +17,28 @@
declare(strict_types=1);
-namespace Fisharebest\Webtrees;
+namespace Fisharebest\Webtrees\Elements;
+
+use Fisharebest\Webtrees\TestCase;
/**
- * Test harness for the class GedcomTag
+ * Test harness for the class DateValue
*
- * @covers \Fisharebest\Webtrees\GedcomTag
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\DateValue
*/
-class GedcomTagTest extends TestCase
+class DateValueTest extends TestCase
{
/**
- * Test that the class exists
- *
* @return void
*/
- public function testClassExists(): void
+ public function testEscape(): void
{
- self::assertTrue(class_exists(GedcomTag::class));
+ $element = new DateValue('');
+
+ self::assertSame(
+ '@#DJULAIN@ 44 B.C. INT (says test@@example.com)',
+ $element->escape('@#DJULAIN@ 44 B.C. INT (says test@example.com)')
+ );
}
}
diff --git a/tests/app/Elements/LanguageIdTest.php b/tests/app/Elements/LanguageIdTest.php
new file mode 100644
index 0000000000..35b024cf44
--- /dev/null
+++ b/tests/app/Elements/LanguageIdTest.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use Fisharebest\Webtrees\TestCase;
+
+/**
+ * Test harness for the class LanguageId
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\LanguageId
+ */
+class LanguageIdTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testCanonical(): void
+ {
+ $element = new LanguageId('');
+
+ self::assertSame('English', $element->canonical("\t English\t "));
+ self::assertSame('Klingon', $element->canonical('kLiNgOn'));
+ self::assertSame('Anglo-Saxon', $element->canonical('anglo-saxon'));
+ self::assertSame('Catalan_Spn', $element->canonical('CATALAN_SPN'));
+ }
+}
diff --git a/tests/app/Elements/XrefFamilyTest.php b/tests/app/Elements/XrefFamilyTest.php
new file mode 100644
index 0000000000..9a31ab55e6
--- /dev/null
+++ b/tests/app/Elements/XrefFamilyTest.php
@@ -0,0 +1,143 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\FamilyFactory;
+use Fisharebest\Webtrees\Family;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+/**
+ * Test harness for the class XrefFamily
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefFamily
+ */
+class XrefFamilyTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefFamily('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(FamilyFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::familyFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefFamily('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefFamily('');
+
+ $record = $this->createMock(Family::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(FamilyFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::familyFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefFamily('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefFamily('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(FamilyFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::familyFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefIndividualTest.php b/tests/app/Elements/XrefIndividualTest.php
new file mode 100644
index 0000000000..58d6dfe3fa
--- /dev/null
+++ b/tests/app/Elements/XrefIndividualTest.php
@@ -0,0 +1,146 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\FamilyFactory;
+use Fisharebest\Webtrees\Factories\IndividualFactory;
+use Fisharebest\Webtrees\Individual;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefIndividual
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefIndividual
+ */
+class XrefIndividualTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefIndividual('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(IndividualFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::individualFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefIndividual('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefIndividual('');
+
+ $record = $this->createMock(Individual::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(IndividualFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::individualFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefIndividual('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefIndividual('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(IndividualFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::individualFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefLocationTest.php b/tests/app/Elements/XrefLocationTest.php
new file mode 100644
index 0000000000..c9cb52dc8c
--- /dev/null
+++ b/tests/app/Elements/XrefLocationTest.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\LocationFactory;
+use Fisharebest\Webtrees\Location;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefLocation
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefLocation
+ */
+class XrefLocationTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefLocation('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(LocationFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::locationFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefLocation('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefLocation('');
+
+ $record = $this->createMock(Location::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(LocationFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::LocationFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefLocation('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefLocation('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(LocationFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::LocationFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefMediaTest.php b/tests/app/Elements/XrefMediaTest.php
new file mode 100644
index 0000000000..e8988a8531
--- /dev/null
+++ b/tests/app/Elements/XrefMediaTest.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\MediaFactory;
+use Fisharebest\Webtrees\Media;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefMedia
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefMedia
+ */
+class XrefMediaTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefMedia('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(MediaFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::mediaFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefMedia('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefMedia('');
+
+ $record = $this->createMock(Media::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(MediaFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::mediaFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefMedia('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefMedia('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(MediaFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::mediaFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefNoteTest.php b/tests/app/Elements/XrefNoteTest.php
new file mode 100644
index 0000000000..30c45f7034
--- /dev/null
+++ b/tests/app/Elements/XrefNoteTest.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\NoteFactory;
+use Fisharebest\Webtrees\Note;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefNote
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefNote
+ */
+class XrefNoteTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefNote('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(NoteFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::noteFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefNote('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefNote('');
+
+ $record = $this->createMock(Note::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(NoteFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::noteFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefNote('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefNote('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(NoteFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::noteFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefRepositoryTest.php b/tests/app/Elements/XrefRepositoryTest.php
new file mode 100644
index 0000000000..a6b3b180ef
--- /dev/null
+++ b/tests/app/Elements/XrefRepositoryTest.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\RepositoryFactory;
+use Fisharebest\Webtrees\Repository;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefRepository
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefRepository
+ */
+class XrefRepositoryTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefRepository('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(RepositoryFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::repositoryFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefRepository('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefRepository('');
+
+ $record = $this->createMock(Repository::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(RepositoryFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::repositoryFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefRepository('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefRepository('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(RepositoryFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::repositoryFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefSourceTest.php b/tests/app/Elements/XrefSourceTest.php
new file mode 100644
index 0000000000..d7736c2ddb
--- /dev/null
+++ b/tests/app/Elements/XrefSourceTest.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\SourceFactory;
+use Fisharebest\Webtrees\Source;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefSource
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefSource
+ */
+class XrefSourceTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefSource('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SourceFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::sourceFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefSource('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefSource('');
+
+ $record = $this->createMock(Source::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SourceFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::sourceFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefSource('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefSource('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SourceFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::sourceFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefSubmissionTest.php b/tests/app/Elements/XrefSubmissionTest.php
new file mode 100644
index 0000000000..3eac2ce18d
--- /dev/null
+++ b/tests/app/Elements/XrefSubmissionTest.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\SubmissionFactory;
+use Fisharebest\Webtrees\Submission;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefSubmission
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefSubmission
+ */
+class XrefSubmissionTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefSubmission('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SubmissionFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::submissionFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefSubmission('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefSubmission('');
+
+ $record = $this->createMock(Submission::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SubmissionFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::submissionFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefSubmission('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefSubmission('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SubmissionFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::submissionFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}
diff --git a/tests/app/Elements/XrefSubmitterTest.php b/tests/app/Elements/XrefSubmitterTest.php
new file mode 100644
index 0000000000..5de359f154
--- /dev/null
+++ b/tests/app/Elements/XrefSubmitterTest.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2021 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Elements;
+
+use DOMDocument;
+use Fisharebest\Webtrees\Factories\SubmitterFactory;
+use Fisharebest\Webtrees\Submitter;
+use Fisharebest\Webtrees\Registry;
+use Fisharebest\Webtrees\TestCase;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ServerRequestInterface;
+
+use function app;
+
+/**
+ * Test harness for the class XrefSubmitter
+ *
+ * @covers \Fisharebest\Webtrees\Elements\AbstractElement
+ * @covers \Fisharebest\Webtrees\Elements\AbstractXrefElement
+ * @covers \Fisharebest\Webtrees\Elements\XrefSubmitter
+ */
+class XrefSubmitterTest extends TestCase
+{
+ /**
+ * @return void
+ */
+ public function testEdit(): void
+ {
+ $element = new XrefSubmitter('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SubmitterFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::submitterFactory($factory);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+
+ app()->instance(ServerRequestInterface::class, $request);
+
+ $html = $element->edit('some-id', 'some-name', '@X123@', $tree);
+ $dom = new DOMDocument();
+ $dom->loadHTML($html);
+
+ $select_nodes = $dom->getElementsByTagName('select');
+ self::assertEquals(1, $select_nodes->count());
+
+ $option_nodes = $select_nodes[0]->getElementsByTagName('option');
+ self::assertEquals(1, $option_nodes->count());
+ }
+ /**
+ * @return void
+ */
+ public function testEscape(): void
+ {
+ $element = new XrefSubmitter('');
+
+ self::assertSame('@X123@', $element->escape('@X123@'));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLink(): void
+ {
+ $element = new XrefSubmitter('');
+
+ $record = $this->createMock(Submitter::class);
+
+ $record->expects(self::once())
+ ->method('fullName')
+ ->willReturn('Full Name');
+
+ $record->expects(self::once())
+ ->method('url')
+ ->willReturn('https://url');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SubmitterFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn($record);
+
+
+ Registry::submitterFactory($factory);
+
+ self::assertSame('<a href="https://url">Full Name</a>', $element->value('@X123@', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithInvalidXref(): void
+ {
+ $element = new XrefSubmitter('');
+
+ $tree = $this->createMock(Tree::class);
+
+ self::assertSame('<span class="error">invalid</span>', $element->value('invalid', $tree));
+ }
+
+ /**
+ * @return void
+ */
+ public function testValueXrefLinkWithMissingRecord(): void
+ {
+ $element = new XrefSubmitter('');
+
+ $tree = $this->createMock(Tree::class);
+
+ $factory = $this->createMock(SubmitterFactory::class);
+
+ $factory->expects(self::once())
+ ->method('make')
+ ->willReturn(null);
+
+ Registry::submitterFactory($factory);
+
+ self::assertSame('<span class="error">@X321@</span>', $element->value('@X321@', $tree));
+ }
+}