test_2.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. require_once('../phpQuery/phpQuery.php');
  3. phpQuery::$debug = true;
  4. $testName = 'Filter with pseudoclass';
  5. $testResult = array(
  6. 'p.body',
  7. );
  8. $result = phpQuery::newDocumentFile('test.html');
  9. $result = $result->find('p')
  10. ->filter('.body:gt(1)');
  11. if ( $result->whois() == $testResult )
  12. print "Test '{$testName}' PASSED :)";
  13. else
  14. print "Test '{$testName}' <strong>FAILED</strong> !!! ";
  15. print_r($result->whois());
  16. print "\n";
  17. $testName = 'Filter with multiplie selectors';
  18. $testResult = array(
  19. 'p.body',
  20. );
  21. $testDOM = phpQuery::newDocumentFile('test.html');
  22. $single = $testDOM->find('p')->filter('.body')
  23. ->add(
  24. $testDOM->find('p')->filter('.title')
  25. )
  26. ;
  27. $double = $testDOM->find('p')
  28. ->filter('.body, .title');
  29. if ($single->length == count($double))
  30. print "Test '{$testName}' PASSED :)";
  31. else
  32. print "Test '{$testName}' <strong>FAILED</strong> !!! ";
  33. print "\n";
  34. print_r($single->whois());
  35. print "\n";
  36. print_r($double->whois());
  37. print "\n";
  38. $testName = 'Attributes in HTML element';
  39. $validResult = 'testValue';
  40. $result = phpQuery::newDocumentFile('test.html')->find('html')
  41. ->empty()
  42. ->attr('test', $validResult);
  43. $result = phpQuery::newDocument($result->htmlOuter())->find('html')
  44. ->attr('test');
  45. //similar_text($result->htmlOuter(), $validResult, $similarity);
  46. if ( $result == $validResult )
  47. print "Test '{$testName}' PASSED :)";
  48. else {
  49. print "Test '{$testName}' <strong>FAILED</strong> !!! ";
  50. print "<pre>";
  51. print $result;
  52. print "</pre>\n";
  53. }