test_2.php
1.4 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
<?php
require_once('../phpQuery/phpQuery.php');
phpQuery::$debug = true;
$testName = 'Filter with pseudoclass';
$testResult = array(
'p.body',
);
$result = phpQuery::newDocumentFile('test.html');
$result = $result->find('p')
->filter('.body:gt(1)');
if ( $result->whois() == $testResult )
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print_r($result->whois());
print "\n";
$testName = 'Filter with multiplie selectors';
$testResult = array(
'p.body',
);
$testDOM = phpQuery::newDocumentFile('test.html');
$single = $testDOM->find('p')->filter('.body')
->add(
$testDOM->find('p')->filter('.title')
)
;
$double = $testDOM->find('p')
->filter('.body, .title');
if ($single->length == count($double))
print "Test '{$testName}' PASSED :)";
else
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print "\n";
print_r($single->whois());
print "\n";
print_r($double->whois());
print "\n";
$testName = 'Attributes in HTML element';
$validResult = 'testValue';
$result = phpQuery::newDocumentFile('test.html')->find('html')
->empty()
->attr('test', $validResult);
$result = phpQuery::newDocument($result->htmlOuter())->find('html')
->attr('test');
//similar_text($result->htmlOuter(), $validResult, $similarity);
if ( $result == $validResult )
print "Test '{$testName}' PASSED :)";
else {
print "Test '{$testName}' <strong>FAILED</strong> !!! ";
print "<pre>";
print $result;
print "</pre>\n";
}