|
1
|
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
|
2
|
|
|
<?php |
|
3
|
|
|
require_once('../PhpQuery/PhpQuery.php'); |
|
4
|
|
|
// PhpQuery::$debug = true; |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
$testName = 'Text node append'; |
|
7
|
|
|
$result = PhpQuery::newDocumentFile('test.html') |
|
|
|
|
|
|
8
|
|
|
->find('li:first') |
|
9
|
|
|
->find('p:first') |
|
10
|
|
|
->html('żźć'); |
|
11
|
|
|
if (trim($result->html()) == 'żźć') |
|
12
|
|
|
print "Test '{$testName}' passed :)<br />\n"; |
|
13
|
|
|
else |
|
14
|
|
|
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n"; |
|
15
|
|
|
print "\n"; |
|
16
|
|
|
|
|
17
|
|
|
$testName = 'Text node HTML entite append'; |
|
18
|
|
|
$result = PhpQuery::newDocumentFile('test.html') |
|
|
|
|
|
|
19
|
|
|
->find('li:first') |
|
20
|
|
|
->find('p:first') |
|
21
|
|
|
->_empty() |
|
22
|
|
|
->append('é'); |
|
23
|
|
View Code Duplication |
if (trim($result->html()) == 'é') |
|
|
|
|
|
|
24
|
|
|
print "Test '{$testName}' passed :)<br />\n"; |
|
25
|
|
|
else { |
|
26
|
|
|
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n"; |
|
27
|
|
|
print $result->html(); |
|
28
|
|
|
} |
|
29
|
|
|
print "\n"; |
|
30
|
|
|
|
|
31
|
|
|
$testName = 'DOMElement node HTML entite append'; |
|
32
|
|
|
$result = PhpQuery::newDocumentFile('test.html') |
|
|
|
|
|
|
33
|
|
|
->find('li:first') |
|
34
|
|
|
->find('p:first') |
|
35
|
|
|
->empty() |
|
36
|
|
|
->append('<span>é</span>'); |
|
37
|
|
View Code Duplication |
if (trim($result->html()) == '<span>é</span>') |
|
|
|
|
|
|
38
|
|
|
print "Test '{$testName}' passed :)<br />\n"; |
|
39
|
|
|
else { |
|
40
|
|
|
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n"; |
|
41
|
|
|
print $result->html(); |
|
42
|
|
|
} |
|
43
|
|
|
print "\n"; |
|
44
|
|
|
|
|
45
|
|
|
$testName = 'Append and move'; |
|
46
|
|
|
$result = PhpQuery::newDocumentFile('test.html'); |
|
|
|
|
|
|
47
|
|
|
$li = $result->find('li:first'); |
|
48
|
|
|
$result->find('div')->_empty(); |
|
49
|
|
|
$li->html('test1-é-test1') |
|
50
|
|
|
->append('test2-é-test2') |
|
51
|
|
|
->appendTo( |
|
52
|
|
|
$result->find('div:first') |
|
53
|
|
|
); |
|
54
|
|
|
$result = $result->find('div:first li:first'); |
|
55
|
|
|
$expected = 'test1-é-test1test2-é-test2'; |
|
56
|
|
|
if (trim(str_replace("\n", '', $result->html())) == $expected) |
|
57
|
|
|
print "Test '{$testName}' passed :)<br />\n"; |
|
58
|
|
|
else { |
|
59
|
|
|
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n"; |
|
60
|
|
|
print "'".trim($result->html())."'"; |
|
61
|
|
|
} |
|
62
|
|
|
print "\n"; |
|
63
|
|
|
|
|
64
|
|
|
$testName = 'Attr charset'; |
|
65
|
|
|
$result = PhpQuery::newDocumentFile('test.html') |
|
|
|
|
|
|
66
|
|
|
->find('li:first') |
|
67
|
|
|
->attr('test', 'foo é żźć bar'); |
|
68
|
|
View Code Duplication |
if (trim($result->attr('test')) == 'foo é żźć bar') |
|
|
|
|
|
|
69
|
|
|
print "Test '{$testName}' passed :)<br />\n"; |
|
70
|
|
|
else { |
|
71
|
|
|
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n"; |
|
72
|
|
|
print $result->attr('test'); |
|
73
|
|
|
} |
|
74
|
|
|
print "\n"; |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
//$testName = 'Loading document without meta charset'; |
|
|
|
|
|
|
78
|
|
|
//$result = PhpQuery::newDocumentFile('test.html') |
|
79
|
|
|
// ->_empty(); |
|
80
|
|
|
////var_dump((string)$result->htmlOuter()); |
|
81
|
|
|
//$result = PhpQuery::newDocument($result->htmlOuter()); |
|
82
|
|
|
//$validResult = <<<EOF |
|
83
|
|
|
//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
84
|
|
|
//<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /></head></html> |
|
85
|
|
|
//EOF; |
|
86
|
|
|
//$similarity = 0; |
|
87
|
|
|
//similar_text($result->htmlOuter(), $validResult, $similarity); |
|
88
|
|
|
//if ( $similarity > 90 ) |
|
89
|
|
|
// print "Test '{$testName}' passed :)<br />\n"; |
|
90
|
|
|
//else |
|
91
|
|
|
// print "Test '{$testName}' <strong>FAILED</strong> !!! "; |
|
92
|
|
|
//print "<pre>"; |
|
93
|
|
|
//print $result; |
|
94
|
|
|
//print "</pre>\n"; |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.