ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilHtmlDomNodeIteratorTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
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 }