test_events.php
1.2 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
<?php
require_once('../phpQuery/phpQuery.php');
// phpQuery::$debug = true;
$form = <<<EOF
<form>
<input name='input-example'>
<input name='array[array-example]'>
<textarea name='textarea-example'></textarea>
<select name='select-example'>
<option value='first'></option>
</select>
<input type='radio' name='radio-example' value='foo'>
<input type='checkbox' name='checkbox-example' value='foo'>
</form>
EOF;
$doc = phpQuery::newDocumentHTML($form);
$inputs = $doc['form > *'];
// creates array from input names
// $results = $inputs->get(null,
// create_function('$node', 'return $node->getAttribute("name");')
// );
$results = array();
foreach($inputs as $node) {
$node = pq($node);
$name = $node->attr('name');
$results[$name] = false;
$node->change(
new CallbackReference($results[$name])
);
}
$inputs
->not('select,:checkbox,:radio')
->val('new value')
->end()
->filter('select')
->val('first')
->end()
->filter(':checkbox')
->val(array('foo'))
->end()
->filter(':radio')
->val(array('foo'))
->end()
;
foreach($results as $name => $result) {
print $result
? "Test for '$name' PASSED :)<br />\n"
: "Test for '$name' <strong>FAILED</strong> !!!<br />\n";
}