33declare (strict_types=1 );
44
55use PHPHtmlParser \Dom ;
6+ use PHPHtmlParser \Exceptions \NotLoadedException ;
67use PHPHtmlParser \Options ;
78use PHPUnit \Framework \TestCase ;
89
@@ -25,31 +26,6 @@ public function testParsingCData()
2526 $ this ->assertSame ($ html , $ dom ->root ->outerHtml ());
2627 }
2728
28- public function testloadStr ()
29- {
30- $ dom = new Dom ();
31- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' );
32- $ div = $ dom ->find ('div ' , 0 );
33- $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' , $ div ->outerHtml );
34- }
35-
36- /**
37- * @expectedException \PHPHtmlParser\Exceptions\NotLoadedException
38- */
39- public function testNotLoaded ()
40- {
41- $ dom = new Dom ();
42- $ div = $ dom ->find ('div ' , 0 );
43- }
44-
45- public function testIncorrectAccess ()
46- {
47- $ dom = new Dom ();
48- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' );
49- $ div = $ dom ->find ('div ' , 0 );
50- $ this ->assertEquals (null , $ div ->foo );
51- }
52-
5329 public function testLoadSelfclosingAttr ()
5430 {
5531 $ dom = new Dom ();
@@ -66,44 +42,13 @@ public function testLoadSelfclosingAttrToString()
6642 $ this ->assertEquals ('<br foo bar /> ' , (string ) $ br );
6743 }
6844
69- public function testLoadEscapeQuotes ()
70- {
71- $ dom = new Dom ();
72- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></div> ' );
73- $ div = $ dom ->find ('div ' , 0 );
74- $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></div> ' , $ div ->outerHtml );
75- }
76-
7745 public function testLoadNoOpeningTag ()
7846 {
7947 $ dom = new Dom ();
8048 $ dom ->loadStr ('<div class="all"><font color="red"><strong>PR Manager</strong></font></b><div class="content">content</div></div> ' );
8149 $ this ->assertEquals ('content ' , $ dom ->find ('.content ' , 0 )->text );
8250 }
8351
84- public function testLoadNoClosingTag ()
85- {
86- $ dom = new Dom ();
87- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></div><br /> ' );
88- $ root = $ dom ->find ('div ' , 0 )->getParent ();
89- $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></div><br /> ' , $ root ->outerHtml );
90- }
91-
92- public function testLoadAttributeOnSelfClosing ()
93- {
94- $ dom = new Dom ();
95- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></div><br class="both" /> ' );
96- $ br = $ dom ->find ('br ' , 0 );
97- $ this ->assertEquals ('both ' , $ br ->getAttribute ('class ' ));
98- }
99-
100- public function testLoadClosingTagOnSelfClosing ()
101- {
102- $ dom = new Dom ();
103- $ dom ->loadStr ('<div class="all"><br><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></br></div> ' );
104- $ this ->assertEquals ('<br /><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p> ' , $ dom ->find ('div ' , 0 )->innerHtml );
105- }
106-
10752 public function testLoadNoValueAttribute ()
10853 {
10954 $ dom = new Dom ();
@@ -223,55 +168,6 @@ public function testLoadFromUrl()
223168 $ this ->assertEquals ('VonBurgermeister ' , $ dom ->find ('.post-row div .post-user font ' , 0 )->text );
224169 }
225170
226- public function testToStringMagic ()
227- {
228- $ dom = new Dom ();
229- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' );
230- $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' , (string ) $ dom );
231- }
232-
233- public function testGetMagic ()
234- {
235- $ dom = new Dom ();
236- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' );
237- $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' , $ dom ->innerHtml );
238- }
239-
240- public function testFirstChild ()
241- {
242- $ dom = new Dom ();
243- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></div><br /> ' );
244- $ this ->assertEquals ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></p></div> ' , $ dom ->firstChild ()->outerHtml );
245- }
246-
247- public function testLastChild ()
248- {
249- $ dom = new Dom ();
250- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" data-quote="\"">click here</a></div><br /> ' );
251- $ this ->assertEquals ('<br /> ' , $ dom ->lastChild ()->outerHtml );
252- }
253-
254- public function testGetElementById ()
255- {
256- $ dom = new Dom ();
257- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" id="78">click here</a></div><br /> ' );
258- $ this ->assertEquals ('<a href="google.com" id="78">click here</a> ' , $ dom ->getElementById ('78 ' )->outerHtml );
259- }
260-
261- public function testGetElementsByTag ()
262- {
263- $ dom = new Dom ();
264- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" id="78">click here</a></div><br /> ' );
265- $ this ->assertEquals ('<p>Hey bro, <a href="google.com" id="78">click here</a></p> ' , $ dom ->getElementsByTag ('p ' )[0 ]->outerHtml );
266- }
267-
268- public function testGetElementsByClass ()
269- {
270- $ dom = new Dom ();
271- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com" id="78">click here</a></div><br /> ' );
272- $ this ->assertEquals ('<p>Hey bro, <a href="google.com" id="78">click here</a></p> ' , $ dom ->getElementsByClass ('all ' )[0 ]->innerHtml );
273- }
274-
275171 public function testScriptCleanerScriptTag ()
276172 {
277173 $ dom = new Dom ();
@@ -321,16 +217,6 @@ public function testCodeTag()
321217 $ this ->assertEquals ('<strong>hello</strong><code class="language-php">$foo = "bar";</code> ' , (string ) $ dom );
322218 }
323219
324- public function testDeleteNode ()
325- {
326- $ dom = new Dom ();
327- $ dom ->loadStr ('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div> ' );
328- $ a = $ dom ->find ('a ' )[0 ];
329- $ a ->delete ();
330- unset($ a );
331- $ this ->assertEquals ('<div class="all"><p>Hey bro, <br /> :)</p></div> ' , (string ) $ dom );
332- }
333-
334220 public function testCountChildren ()
335221 {
336222 $ dom = new Dom ();
@@ -619,4 +505,15 @@ public function testXMLOpeningToken()
619505
620506 $ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8" ?><p>fun time</p> ' , $ dom ->outerHtml );
621507 }
508+
509+ /**
510+ * Test to cover issue found in ticket #221
511+ */
512+ public function testRandomTagInMiddleOfText ()
513+ {
514+ $ dom = new Dom ();
515+ $ dom ->loadStr ('<p>Hello, this is just a test in which <55 names with some other text > should be interpreted as text</p> ' );
516+
517+ $ this ->assertEquals ('<p>Hello, this is just a test in which <55 names with some other text> should be interpreted as text</55></p> ' , $ dom ->outerHtml );
518+ }
622519}
0 commit comments