test_5.php
1.0 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
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
// CALLBACKS
class callbackClass {
static function staticMethodCallback($node) {
pq($node)->addClass('newClass');
}
function methodCallback($node) {
pq($node)->addClass('newClass');
}
}
function functionCallback($node) {
pq($node)->addClass('newClass');
}
$testResult = array(
'li.newClass',
'li#testID.newClass',
'li.newClass',
'li#i_have_nested_list.newClass',
'li.nested.newClass',
'li.second.newClass',
);
$tests = array(
'functionCallback',
array('callbackClass', 'staticMethodCallback'),
array(new callbackClass, 'methodCallback')
);
foreach($tests as $test) {
$result = phpQuery::newDocumentFile('test.html')
->find('li')
->each($test);
$testName = is_array($test)
? $test[1]
: $test;
if ( $result->whois() == $testResult )
print "Test '$testName' PASSED :)";
else {
print "Test '$testName' <strong>FAILED</strong> !!! ";
print "<pre>";
print_r($result->whois());
print "</pre>\n";
}
print "\n";
}
?>