3
3
declare (strict_types=1 );
4
4
5
5
use PHPHtmlParser \Dom ;
6
+ use PHPHtmlParser \Exceptions \NotLoadedException ;
6
7
use PHPHtmlParser \Options ;
7
8
use PHPUnit \Framework \TestCase ;
8
9
@@ -25,31 +26,6 @@ public function testParsingCData()
25
26
$ this ->assertSame ($ html , $ dom ->root ->outerHtml ());
26
27
}
27
28
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
-
53
29
public function testLoadSelfclosingAttr ()
54
30
{
55
31
$ dom = new Dom ();
@@ -66,44 +42,13 @@ public function testLoadSelfclosingAttrToString()
66
42
$ this ->assertEquals ('<br foo bar /> ' , (string ) $ br );
67
43
}
68
44
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
-
77
45
public function testLoadNoOpeningTag ()
78
46
{
79
47
$ dom = new Dom ();
80
48
$ dom ->loadStr ('<div class="all"><font color="red"><strong>PR Manager</strong></font></b><div class="content">content</div></div> ' );
81
49
$ this ->assertEquals ('content ' , $ dom ->find ('.content ' , 0 )->text );
82
50
}
83
51
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
-
107
52
public function testLoadNoValueAttribute ()
108
53
{
109
54
$ dom = new Dom ();
@@ -223,55 +168,6 @@ public function testLoadFromUrl()
223
168
$ this ->assertEquals ('VonBurgermeister ' , $ dom ->find ('.post-row div .post-user font ' , 0 )->text );
224
169
}
225
170
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
-
275
171
public function testScriptCleanerScriptTag ()
276
172
{
277
173
$ dom = new Dom ();
@@ -321,16 +217,6 @@ public function testCodeTag()
321
217
$ this ->assertEquals ('<strong>hello</strong><code class="language-php">$foo = "bar";</code> ' , (string ) $ dom );
322
218
}
323
219
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
-
334
220
public function testCountChildren ()
335
221
{
336
222
$ dom = new Dom ();
@@ -619,4 +505,15 @@ public function testXMLOpeningToken()
619
505
620
506
$ this ->assertEquals ('<?xml version="1.0" encoding="UTF-8" ?><p>fun time</p> ' , $ dom ->outerHtml );
621
507
}
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
+ }
622
519
}
0 commit comments