@@ -141,6 +141,7 @@ public function testAddChild00() {
141141 $ this ->assertEquals ('p ' , $ node ->getChild (2 )->getNodeName ());
142142 $ this ->assertEquals ('img ' , $ node ->getChild (3 )->getNodeName ());
143143 $ this ->assertEquals ('ok ' , $ node ->getChild (3 )->getAttribute ('src ' ));
144+
144145 }
145146 /**
146147 * @test
@@ -344,6 +345,14 @@ public function testAddChild17() {
344345 . '</html> ' .HTMLDoc::NL , $ node ->asCode ([
345346 'with-colors ' => false
346347 ]));
348+ $ this ->assertEquals ('<span style="color:rgb(204,225,70)"><</span><span style="color:rgb(204,225,70)">!DOCTYPE html</span><span style="color:rgb(204,225,70)">></span> ' .HTMLDoc::NL
349+ . '<span style="color:rgb(204,225,70)"><</span><span style="color:rgb(204,225,70)">html</span><span style="color:rgb(204,225,70)">></span> ' .HTMLDoc::NL
350+ . ' <span style="color:rgb(204,225,70)"><</span><span style="color:rgb(204,225,70)">body</span><span style="color:rgb(204,225,70)">></span> ' .HTMLDoc::NL
351+ . ' <span style="color:rgb(204,225,70)"><</span><span style="color:rgb(204,225,70)">img</span> <span style="color:rgb(0,124,0)">src</span> <span style="color:gray">=</span> <span style="color:rgb(170,85,137)">"image.png"</span><span style="color:rgb(204,225,70)">></span> ' .HTMLDoc::NL
352+ . ' <span style="color:rgb(204,225,70)"></</span><span style="color:rgb(204,225,70)">body</span><span style="color:rgb(204,225,70)">></span> ' .HTMLDoc::NL
353+ . '<span style="color:rgb(204,225,70)"></</span><span style="color:rgb(204,225,70)">html</span><span style="color:rgb(204,225,70)">></span> ' .HTMLDoc::NL , $ node ->asCode ([
354+ 'with-colors ' => true
355+ ]));
347356 $ node ->setIsQuotedAttribute (false );
348357 }
349358 /**
@@ -392,29 +401,60 @@ public function testApplyClass00() {
392401 * @test
393402 */
394403 public function testAsCode00 () {
395- $ node = new HTMLNode ();
404+ $ node = new HTMLNode ('div ' , [
405+ 'class ' => 'box ' ,
406+ "hidden "
407+ ]);
396408 $ this ->assertEquals ("<pre style= \"margin:0;background-color:rgb(21, 18, 33); "
397409 . " color:gray \"> \r\n<span style= \"color:rgb(204,225,70) \"> "
398410 . "<</span><span style= \"color:rgb(204,225,70) \"> "
399- . "div</span><span style= \"color:rgb(204,225,70) \"> "
400- . "></span> \r\n<span style= \"color:rgb(204,225,70) \"> "
411+ . "div</span> "
412+ . " <span style= \"color:rgb(0,124,0) \">class</span> "
413+ . " <span style= \"color:gray \">=</span> "
414+ . " <span style= \"color:rgb(170,85,137) \"> \"box \"</span> "
415+ . " <span style= \"color:rgb(0,124,0) \">hidden</span> "
416+ . "<span style= \"color:rgb(204,225,70) \">></span> \r\n"
417+ . ""
418+ . ""
419+
420+ . "<span style= \"color:rgb(204,225,70) \"> "
401421 . "</</span><span style= \"color:rgb(204,225,70) \"> "
402422 . "div</span><span style= \"color:rgb(204,225,70) \"> "
403- . "></span> \r\n</pre> " ,$ node ->asCode ());
423+ . "></span> \r\n"
424+ . "</pre> " ,$ node ->asCode ());
404425 }
405426 /**
406427 * @test
407428 */
408429 public function testAsCode01 () {
409- $ node = new HTMLNode ();
410- $ node ->addCommentNode ('This is a comment. ' );
411- $ node ->addTextNode ('This is a simple text node. ' );
412- $ child00 = new HTMLNode ('input ' );
413- $ child00 ->setID ('child-00 ' );
414- $ child00 ->setWritingDir ('ltr ' );
415- $ node ->addChild ($ child00 );
416- $ this ->assertTrue (true );
417- //$this->assertEquals("<pre style=\"margin:0;background-color:rgb(21, 18, 33); color:gray\">\r\n<span style=\"color:rgb(204,225,70)\"><</span><span style=\"color:rgb(204,225,70)\">div</span><span style=\"color:rgb(204,225,70)\">></span>\r\n<span style=\"color:rgb(204,225,70)\"></</span><span style=\"color:rgb(204,225,70)\">div</span><span style=\"color:rgb(204,225,70)\">></span>\r\n</pre>",$node->asCode());
430+ $ node = new HTMLNode ('code ' );
431+ $ this ->assertEquals (""
432+ . "<pre style= \"margin:0;background-color:rgb(21, 18, 33); color:gray \"> \r\n"
433+ . "<span style= \"color:rgb(204,225,70) \"><</span><span style= \"color:rgb(204,225,70) \">code</span> "
434+ . "<span style= \"color:rgb(204,225,70) \">></span><span style= \"color:rgb(204,225,70) \"></</span><span style= \"color:rgb(204,225,70) \">code</span><span style= \"color:rgb(204,225,70) \">></span> \r\n"
435+ . "</pre> " ,$ node ->asCode ());
436+ }
437+ /**
438+ * @test
439+ */
440+ public function testAsCode02 () {
441+ $ node = new HTMLNode ('div ' );
442+ $ node ->comment ('Hello ' );
443+ $ this ->assertEquals (""
444+ . "<div> \r\n"
445+ . " <!--Hello--> \r\n"
446+ . "</div> \r\n"
447+ . "" ,$ node ->asCode ([
448+ 'with-colors ' => false
449+ ]));
450+ $ this ->assertEquals ("<pre style= \"margin:0 \"> \r\n"
451+ . "<div> \r\n"
452+ . " <!--Hello--> \r\n"
453+ . "</div> \r\n"
454+ . "</pre> " ,$ node ->asCode ([
455+ 'with-colors ' => false ,
456+ 'use-pre ' => true
457+ ]));
418458 }
419459 /**
420460 * @test
@@ -510,12 +550,12 @@ public function testChaining03() {
510550 public function testChaining04 () {
511551 $ node = new HTMLNode ('ul ' );
512552 $ node ->li ('Hello ' , ['class ' => 'first-menu-item ' ])
513- ->li ('World ' )
553+ ->li (new Anchor ( 'World ' , ' https://example.com ' ) )
514554 ->li ('From PHP ' );
515555 $ this ->assertEquals (3 , $ node ->childrenCount ());
516556 $ this ->assertEquals ('<ul> '
517557 . '<li class="first-menu-item">Hello</li> '
518- . '<li>World</li> '
558+ . '<li><a href= World target=_self>https://example.com</a> </li> '
519559 . '<li>From PHP</li> '
520560 . '</ul> ' , $ node ->toHTML ());
521561 }
@@ -2325,6 +2365,16 @@ public function testSetText00() {
23252365 $ this ->assertEquals ('Hello & Welcome. Do you know that 1 is < 3 and 7 > 6? '
23262366 .'Also, 0>-100 && 0<8. ' ,$ node ->getTextUnescaped ());
23272367 }
2368+ /**
2369+ *
2370+ * @test
2371+ */
2372+ public function testSetText01 () {
2373+ $ node = new HTMLNode ();
2374+ $ node ->setText ('Hello ' );
2375+ $ this ->assertEquals ('' , $ node ->getText ());
2376+ $ this ->assertEquals ('' , $ node ->getTextUnescaped ());
2377+ }
23282378 /**
23292379 * @test
23302380 */
@@ -2487,6 +2537,17 @@ public function testToHTML11() {
24872537 $ array = TemplateCompiler::htmlAsArray ($ htmlTxt );
24882538 $ this ->assertEquals (count ($ array ),0 );
24892539 }
2540+ /**
2541+ * @test
2542+ */
2543+ public function testToHTML12 () {
2544+ $ node = new HTMLNode ('div ' );
2545+ $ node ->addChild ('div ' )->br ()->text ('Cool ' );
2546+
2547+ $ this ->assertEquals ('<div><div><br>Cool</div></div> ' ,$ node ->toHTML ());
2548+ $ this ->assertEquals ('' , $ node ->getChild (0 )->getChild (0 )->close ());
2549+ $ this ->assertEquals ('' , $ node ->getChild (0 )->getChild (1 )->close ());
2550+ }
24902551 /**
24912552 * @test
24922553 */
0 commit comments