. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Elements; use DOMDocument; use Fisharebest\Webtrees\Factories\SharedNoteFactory; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\SharedNote; use Fisharebest\Webtrees\TestCase; use Fisharebest\Webtrees\Tree; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(AbstractElement::class)] #[CoversClass(AbstractXrefElement::class)] #[CoversClass(XrefSharedNote::class)] class XrefSharedNoteTest extends TestCase { public function testEdit(): void { $element = new XrefSharedNote(''); $tree = $this->createMock(Tree::class); $factory = $this->createMock(SharedNoteFactory::class); $factory->expects($this->once()) ->method('make') ->willReturn(null); Registry::sharedNoteFactory($factory); $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()); } public function testEscape(): void { $element = new XrefSharedNote(''); self::assertSame('@X123@', $element->escape('@X123@')); } public function testValueXrefLink(): void { $element = new XrefSharedNote(''); $record = $this->createMock(SharedNote::class); $record->expects($this->once()) ->method('fullName') ->willReturn('Full Name'); $record->expects($this->once()) ->method('url') ->willReturn('https://url'); $tree = $this->createMock(Tree::class); $factory = $this->createMock(SharedNoteFactory::class); $factory->expects($this->once()) ->method('make') ->willReturn($record); Registry::sharedNoteFactory($factory); self::assertSame('Full Name', $element->value('@X123@', $tree)); } public function testValueXrefLinkWithInvalidXref(): void { $element = new XrefSharedNote(''); $tree = $this->createMock(Tree::class); self::assertSame('invalid', $element->value('invalid', $tree)); } public function testValueXrefLinkWithMissingRecord(): void { $element = new XrefSharedNote(''); $tree = $this->createMock(Tree::class); $factory = $this->createMock(SharedNoteFactory::class); $factory->expects($this->once()) ->method('make') ->willReturn(null); Registry::sharedNoteFactory($factory); self::assertSame('@X321@', $element->value('@X321@', $tree)); } }