Skip to content

Commit

Permalink
WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Dec 29, 2023
1 parent 5746390 commit 52681b2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use DOMXPath;
use RuntimeException;
use const PHP_VERSION;
use function func_get_args, libxml_get_last_error, trim, version_compare;
use function func_get_args, method_exists, libxml_get_last_error, trim, version_compare;

/**
* @method Attr|false createAttribute(string $localName)
Expand Down Expand Up @@ -85,6 +85,13 @@ public function query(string $expression, ?DOMNode $contextNode = null, bool $re
return $result;
}

public function isEqualNode(?DOMNode $otherNode): bool
{
return method_exists('DOMDocument', 'isEqualNode')
? parent::isEqualNode($otherNode)
: NodeComparator::isEqualNode($this, $otherNode);
}

protected function getNodesNamespace(): string
{
$namespace = __NAMESPACE__;
Expand Down
13 changes: 13 additions & 0 deletions tests/DocumentFragmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,17 @@ public function testQuery()

$this->assertEquals('xx', $fragment->query('x')->item(0)->getAttribute('value'));
}

public function testIsEqualNode()
{
$dom = new Document;

$frag1 = $dom->createDocumentFragment();
$frag2 = $dom->createDocumentFragment();
$frag1->appendElement('x')->setAttribute('value', 'xx');
$frag2->appendElement('x')->setAttribute('value', 'xx');
$this->assertTrue($frag1->isEqualNode($frag2));
$frag2->appendElement('x');
$this->assertFalse($frag1->isEqualNode($frag2));
}
}
11 changes: 11 additions & 0 deletions tests/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,15 @@ public function testFirstOfError()

@$dom->firstOf('x x');
}

public function testIsEqualNode()
{
$dom1 = new Document;
$dom1->loadXML('<x foo="123"/>');
$dom2 = new Document;
$dom2->loadXML('<x foo="123"/>');
$this->assertTrue($dom1->isEqualNode($dom2));
$dom2->loadXML('<x/>');
$this->assertFalse($dom1->isEqualNode($dom2));
}
}

0 comments on commit 52681b2

Please sign in to comment.