test_4.php
2.3 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
// SLICE1
$testResult = array(
'li#testID',
);
$result = phpQuery::newDocumentFile('test.html')
->find('li')
->slice(1, 2);
if ( $result->whois() == $testResult )
print "Test 'Slice1' PASSED :)";
else {
print "Test 'Slice1' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($result->whois());
print "</pre>\n";
}
print "\n";
// SLICE2
$testResult = array(
'li#testID',
'li',
'li#i_have_nested_list',
'li.nested',
);
$result = phpQuery::newDocumentFile('test.html')
->find('li')
->slice(1, -1);
if ( $result->whois() == $testResult )
print "Test 'Slice2' PASSED :)";
else {
print "Test 'Slice2' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($result->whois());
print "</pre>\n";
}
print "\n";
// Multi-insert
$result = phpQuery::newDocument('<li><span class="field1"></span><span class="field1"></span></li>')
->find('.field1')
->php('longlongtest');
$validResult = '<li><span class="field1"><php>longlongtest</php></span><span class="field1"><php>longlongtest</php></span></li>';
similar_text($result->htmlOuter(), $validResult, $similarity);
if ( $similarity > 80 )
print "Test 'Multi-insert' PASSED :)";
else {
print "Test 'Multi-insert' <strong>FAILED</strong> !!! ";
print "<pre>";
var_dump($result->htmlOuter());
print "</pre>\n";
}
print "\n";
// INDEX
$testResult = 1;
$result = phpQuery::newDocumentFile('test.html')
->find('p')
->index(pq('p.title:first'));
if ( $result == $testResult )
print "Test 'Index' PASSED :)";
else {
print "Test 'Index' <strong>FAILED</strong> !!! ";
}
print "\n";
// CLONE
$testName = 'Clone';
$testResult = 3;
$document;
$p = phpQuery::newDocumentFile('test.html')
->toReference($document)
->find('p:first');
foreach(array(0,1,2) as $i) {
$p->clone()
->addClass("clone-test")
->addClass("class-$i")
->insertBefore($p);
}
if (pq('.clone-test')->size() == $testResult)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
}
print "\n";
// SIBLINGS
$testName = 'Next';
$testResult = 3;
$document;
$result = phpQuery::newDocumentFile('test.html')
->find('li:first')
->next()
->next()
->prev()
->is('#testID');
if ($result)
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
}
print "\n";
?>
<?php die();