@@ -12,6 +12,23 @@ public function testLoad()
1212 $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' , $ div ->outerHtml );
1313 }
1414
15+ /**
16+ * @expectedException PHPHtmlParser\Exceptions\NotLoadedException
17+ */
18+ public function testNotLoaded ()
19+ {
20+ $ dom = new Dom ;
21+ $ div = $ dom ->find ('div ' , 0 );
22+ }
23+
24+ public function testIncorrectAccess ()
25+ {
26+ $ dom = new Dom ;
27+ $ dom ->load ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' );
28+ $ div = $ dom ->find ('div ' , 0 );
29+ $ this ->assertEquals (null , $ div ->foo );
30+ }
31+
1532 public function testLoadSelfclosingAttr ()
1633 {
1734 $ dom = new Dom ;
@@ -20,6 +37,14 @@ public function testLoadSelfclosingAttr()
2037 $ this ->assertEquals ('<br foo bar /> ' , $ br ->outerHtml );
2138 }
2239
40+ public function testLoadSelfclosingAttrToString ()
41+ {
42+ $ dom = new Dom ;
43+ $ dom ->load ("<div class='all'><br foo bar />baz</div> " );
44+ $ br = $ dom ->find ('br ' , 0 );
45+ $ this ->assertEquals ('<br foo bar /> ' , (string ) $ br );
46+ }
47+
2348 public function testLoadEscapeQuotes ()
2449 {
2550 $ dom = new Dom ;
@@ -58,6 +83,41 @@ public function testLoadClosingTagOnSelfClosing()
5883 $ this ->assertEquals ('<br /><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p> ' , $ dom ->find ('div ' , 0 )->innerHtml );
5984 }
6085
86+ public function testLoadClosingTagAddSelfClosingTag ()
87+ {
88+ $ dom = new Dom ;
89+ $ dom ->addSelfClosingTag ('mytag ' );
90+ $ dom ->load ('<div class="all"><mytag><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></mytag></div> ' );
91+ $ this ->assertEquals ('<mytag /><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p> ' , $ dom ->find ('div ' , 0 )->innerHtml );
92+ }
93+
94+ public function testLoadClosingTagAddSelfClosingTagArray ()
95+ {
96+ $ dom = new Dom ;
97+ $ dom ->addSelfClosingTag ([
98+ 'mytag ' ,
99+ 'othertag '
100+ ]);
101+ $ dom ->load ('<div class="all"><mytag><p>Hey bro, <a href="google.com" data-quote="\"">click here</a><othertag></div> ' );
102+ $ this ->assertEquals ('<mytag /><p>Hey bro, <a href="google.com" data-quote="\"">click here</a><othertag /></p> ' , $ dom ->find ('div ' , 0 )->innerHtml );
103+ }
104+
105+ public function testLoadClosingTagRemoveSelfClosingTag ()
106+ {
107+ $ dom = new Dom ;
108+ $ dom ->removeSelfClosingTag ('br ' );
109+ $ dom ->load ('<div class="all"><br><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></br></div> ' );
110+ $ this ->assertEquals ('<br><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></br> ' , $ dom ->find ('div ' , 0 )->innerHtml );
111+ }
112+
113+ public function testLoadClosingTagClearSelfClosingTag ()
114+ {
115+ $ dom = new Dom ;
116+ $ dom ->clearSelfClosingTags ();
117+ $ dom ->load ('<div class="all"><br><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></br></div> ' );
118+ $ this ->assertEquals ('<br><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></br> ' , $ dom ->find ('div ' , 0 )->innerHtml );
119+ }
120+
61121 public function testLoadUpperCase ()
62122 {
63123 $ dom = new Dom ;
0 commit comments