summaryrefslogtreecommitdiff
path: root/tests/app/Elements/XrefLocationTest.php
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/app/Elements/XrefLocationTest.php
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/app/Elements/XrefLocationTest.php')
-rw-r--r--tests/app/Elements/XrefLocationTest.php145
1 files changed, 145 insertions, 0 deletions
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));
+ }
+}