Skip to content

Commit

Permalink
fix for more precise matching only-child
Browse files Browse the repository at this point in the history
  • Loading branch information
Rct567 committed Oct 28, 2017
1 parent a580fcf commit ff144ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rct567/DomQuery/DomQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ function ($matches) {
'disabled' => '[@disabled]',
'first-child' => '[not(preceding-sibling::*)]',
'last-child' => '[not(following-sibling::*)]',
'only-child' => '[count(*)=1]',
'only-child' => '[not(preceding-sibling::*) and not(following-sibling::*)]',
'empty' => '[count(*) = 0 and string-length() = 0]',
'not-empty' => '[count(*) > 0 or string-length() > 0]',
'parent' => '[count(*) > 0]',
Expand Down
21 changes: 21 additions & 0 deletions tests/Rct567/DomQuery/Tests/DomQuerySelectorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,27 @@ public function testLastChildPseudoSelector()

$this->assertEquals(0, $dom->find('div:last-child')->length);
$this->assertEquals('item 3', $dom->find('li:last-child')->text());
$this->assertTrue($dom->find('ul')->is(':last-child'));
}

/*
* Test only child pseudo selector
*/
public function testOnlyChildPseudoSelector()
{
$dom = new DomQuery('<section>
<ul id="list-b">
<li>nope</li>
<span>nope</span>
</ul>
<ul id="list-b">
<li>yep</li>
</ul></section>');

$this->assertEquals(0, $dom->find('span:only-child')->length);
$this->assertEquals(0, $dom->find('ul:only-child')->length);
$this->assertTrue($dom->is(':only-child'));
$this->assertEquals('yep', $dom->find('li:only-child')->text());
}

/*
Expand Down

0 comments on commit ff144ca

Please sign in to comment.