Skip to content

Commit

Permalink
Method Element::matches() allows check children nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Imangazaliev committed May 14, 2017
1 parent c37358f commit 69ab6a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DiDom/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function matches($selector, $strict = false)
throw new LogicException('Node must be an instance of DOMElement');
}

$innerHtml = $node->ownerDocument->saveXml($node, LIBXML_NOEMPTYTAG);
$innerHtml = $this->html();
$html = "<root>$innerHtml</root>";

$selector = 'root > '.trim($selector);
Expand Down
19 changes: 19 additions & 0 deletions tests/DiDom/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,25 @@ public function testMatches()
$element = new Element('p');

$this->assertTrue($element->matches('p', true));

$html = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="#"><img src="foo.jpg" alt="Foo"></a>
</body>
</html>';

$document = new Document($html, false);
$anchor = $document->first('a');

$this->assertTrue($anchor->matches('a:has(img[src$=".jpg"])'));
$this->assertTrue($anchor->matches('a img'));
$this->assertFalse($anchor->matches('a img[alt="Bar"]'));
$this->assertFalse($anchor->matches('img'));
}

public function testHasAttribute()
Expand Down

0 comments on commit 69ab6a0

Please sign in to comment.