test_replace.php 803 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. require_once('../phpQuery/phpQuery.php');
  3. phpQuery::$debug = true;
  4. $testName = 'ReplaceWith';
  5. phpQuery::newDocumentFile('test.html')
  6. ->find('p:eq(1)')
  7. ->replaceWith("<p class='newTitle'>
  8. this is example title
  9. </p>");
  10. $result = pq('p:eq(1)');
  11. if ( $result->hasClass('newTitle') )
  12. print "Test '{$testName}' PASSED :)";
  13. else
  14. print "Test '{$testName}' <strong>FAILED</strong> !!! ";
  15. $result->dump();
  16. print "\n";
  17. $testName = 'ReplaceAll';
  18. $testResult = 3;
  19. phpQuery::newDocumentFile('test.html');
  20. pq('<div class="replacer">')
  21. ->replaceAll('li:first p');
  22. $result = pq('.replacer');
  23. if ( $result->size() == $testResult )
  24. print "Test '{$testName}' PASSED :)";
  25. else
  26. print "Test '{$testName}' <strong>FAILED</strong> !!! ";
  27. $result->dump();
  28. print "\n";