test_charset.php
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<?php
require_once('../phpQuery/phpQuery.php');
// phpQuery::$debug = true;
$testName = 'Text node append';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->find('p:first')
->html('żźć');
if (trim($result->html()) == 'żźć')
print "Test '{$testName}' passed :)<br />\n";
else
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print "\n";
$testName = 'Text node HTML entite append';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->find('p:first')
->_empty()
->append('é');
if (trim($result->html()) == 'é')
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print $result->html();
}
print "\n";
$testName = 'DOMElement node HTML entite append';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->find('p:first')
->empty()
->append('<span>é</span>');
if (trim($result->html()) == '<span>é</span>')
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print $result->html();
}
print "\n";
$testName = 'Append and move';
$result = phpQuery::newDocumentFile('test.html');
$li = $result->find('li:first');
$result->find('div')->_empty();
$li->html('test1-é-test1')
->append('test2-é-test2')
->appendTo(
$result->find('div:first')
);
$result = $result->find('div:first li:first');
$expected = 'test1-é-test1test2-é-test2';
if (trim(str_replace("\n", '', $result->html())) == $expected)
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print "'".trim($result->html())."'";
}
print "\n";
$testName = 'Attr charset';
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->attr('test', 'foo é żźć bar');
if (trim($result->attr('test')) == 'foo é żźć bar')
print "Test '{$testName}' passed :)<br />\n";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!!<br />\n";
print $result->attr('test');
}
print "\n";
//$testName = 'Loading document without meta charset';
//$result = phpQuery::newDocumentFile('test.html')
// ->_empty();
////var_dump((string)$result->htmlOuter());
//$result = phpQuery::newDocument($result->htmlOuter());
//$validResult = <<<EOF
//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
//<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>
//EOF;
//$similarity = 0;
//similar_text($result->htmlOuter(), $validResult, $similarity);
//if ( $similarity > 90 )
// print "Test '{$testName}' passed :)<br />\n";
//else
// print "Test '{$testName}' <strong>FAILED</strong> !!! ";
//print "<pre>";
//print $result;
//print "</pre>\n";