test_5.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once('../phpQuery/phpQuery.php');
  3. phpQuery::$debug = true;
  4. // CALLBACKS
  5. class callbackClass {
  6. static function staticMethodCallback($node) {
  7. pq($node)->addClass('newClass');
  8. }
  9. function methodCallback($node) {
  10. pq($node)->addClass('newClass');
  11. }
  12. }
  13. function functionCallback($node) {
  14. pq($node)->addClass('newClass');
  15. }
  16. $testResult = array(
  17. 'li.newClass',
  18. 'li#testID.newClass',
  19. 'li.newClass',
  20. 'li#i_have_nested_list.newClass',
  21. 'li.nested.newClass',
  22. 'li.second.newClass',
  23. );
  24. $tests = array(
  25. 'functionCallback',
  26. array('callbackClass', 'staticMethodCallback'),
  27. array(new callbackClass, 'methodCallback')
  28. );
  29. foreach($tests as $test) {
  30. $result = phpQuery::newDocumentFile('test.html')
  31. ->find('li')
  32. ->each($test);
  33. $testName = is_array($test)
  34. ? $test[1]
  35. : $test;
  36. if ( $result->whois() == $testResult )
  37. print "Test '$testName' PASSED :)";
  38. else {
  39. print "Test '$testName' <strong>FAILED</strong> !!! ";
  40. print "<pre>";
  41. print_r($result->whois());
  42. print "</pre>\n";
  43. }
  44. print "\n";
  45. }
  46. ?>