ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilHtmlDomNodeIteratorTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
23final class ilHtmlDomNodeIteratorTest extends TestCase
24{
25 public function testDomNodeIteratorIteratesOverXhtmlDocumentNodes(): void
26 {
27 $dom = new DOMDocument();
28 $dom->loadHTML('<body><div><p><b>phpunit</b> <i>test</i></p></div></body>');
29
30 $expectedElements = [
31 'body',
32 'div',
33 'p',
34 'b',
35 '#text',
36 '#text',
37 'i',
38 '#text',
39 ];
40 $actualElements = [];
41
42 $iter = new RecursiveIteratorIterator(
43 new ilHtmlDomNodeIterator($dom),
44 RecursiveIteratorIterator::SELF_FIRST
45 );
46 foreach ($iter as $element) {
48 $actualElements[] = $element->nodeName;
49 }
50
51 $this->assertSame($expectedElements, $actualElements);
52 }
53}
Class ilHtmlDomNodeIterator.