Dustin Wilson
2 years ago
8 changed files with 165 additions and 3 deletions
@ -0,0 +1,36 @@ |
|||
<?php |
|||
/** |
|||
* @license MIT |
|||
* Copyright 2017 Dustin Wilson, J. King, et al. |
|||
* See LICENSE and AUTHORS files for details |
|||
*/ |
|||
|
|||
declare(strict_types=1); |
|||
namespace MensBeam\HTML\DOM; |
|||
use MensBeam\HTML\DOM\Inner\{ |
|||
Document as InnerDocument, |
|||
Reflection |
|||
}; |
|||
|
|||
|
|||
trait NonDocumentTypeChildNode { |
|||
protected function __get_nextElementSibling(): ?Element { |
|||
// The nextElementSibling getter steps are to return the first following sibling |
|||
// that is an element; otherwise null. |
|||
|
|||
// PHP's DOM does this correctly already. |
|||
$inner = $this->innerNode; |
|||
$result = $inner->nextElementSibling; |
|||
return ($result !== null) ? $inner->ownerDocument->getWrapperNode($result) : null; |
|||
} |
|||
|
|||
protected function __get_previousElementSibling(): ?Element { |
|||
// The previousElementSibling getter steps are to return the first preceding |
|||
// sibling that is an element; otherwise null. |
|||
|
|||
// PHP's DOM does this correctly already. |
|||
$inner = $this->innerNode; |
|||
$result = $inner->previousElementSibling; |
|||
return ($result !== null) ? $inner->ownerDocument->getWrapperNode($result) : null; |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
<?php |
|||
/** |
|||
* @license MIT |
|||
* Copyright 2017 Dustin Wilson, J. King, et al. |
|||
* See LICENSE and AUTHORS files for details |
|||
*/ |
|||
|
|||
declare(strict_types=1); |
|||
namespace MensBeam\HTML\DOM\TestCase; |
|||
|
|||
use MensBeam\HTML\DOM\{ |
|||
Document, |
|||
DOMException, |
|||
Element, |
|||
Node |
|||
}; |
|||
|
|||
|
|||
/** @covers \MensBeam\HTML\DOM\NonDocumentTypeChildNode */ |
|||
class TestNonDocumentTypeChildNode extends \PHPUnit\Framework\TestCase { |
|||
public function testProperty_nextElementSibling_previousElementSibling(): void { |
|||
$d = new Document('<!DOCTYPE html><html><body></body></html>'); |
|||
$body = $d->body; |
|||
$br = $body->appendChild($d->createElement('br')); |
|||
$body->appendChild($d->createTextNode('eek')); |
|||
$ook = $body->appendChild($d->createTextNode('ook')); |
|||
$br2 = $body->appendChild($d->createElement('br')); |
|||
|
|||
$this->assertSame($br2, $br->nextElementSibling); |
|||
$this->assertSame($br, $ook->previousElementSibling); |
|||
} |
|||
} |
Loading…
Reference in new issue