c1edd394217c21c5fd26d5a4a9909d4077021350.svn-base 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // $Rev: 133 $
  3. // -----------------------------------------------------------------------------
  4. // setup
  5. error_reporting(E_ALL);
  6. require_once('../simple_html_dom.php');
  7. $dom = new simple_html_dom;
  8. // -----------------------------------------------------------------------------
  9. // test problem of last emelemt not found
  10. $str = <<<HTML
  11. <img class="class0" id="id0" src="src0">
  12. <img class="class1" id="id1" src="src1">
  13. <img class="class2" id="id2" src="src2">
  14. HTML;
  15. $dom->load($str);
  16. $es = $dom->find('img');
  17. assert(count($es)==3);
  18. assert($es[0]->src=='src0');
  19. assert($es[1]->src=='src1');
  20. assert($es[2]->src=='src2');
  21. assert($es[0]->innertext=='');
  22. assert($es[1]->innertext=='');
  23. assert($es[2]->innertext=='');
  24. assert($es[0]->outertext=='<img class="class0" id="id0" src="src0">');
  25. assert($es[1]->outertext=='<img class="class1" id="id1" src="src1">');
  26. assert($es[2]->outertext=='<img class="class2" id="id2" src="src2">');
  27. assert($dom->find('img', 0)->src=='src0');
  28. assert($dom->find('img', 1)->src=='src1');
  29. assert($dom->find('img', 2)->src=='src2');
  30. assert($dom->find('img', 3)===null);
  31. assert($dom->find('img', 99)===null);
  32. assert($dom->save()==$str);
  33. // -----------------------------------------------------------------------------
  34. // test error tag
  35. $str = <<<HTML
  36. <img class="class0" id="id0" src="src0"><p>p1</p>
  37. <img class="class1" id="id1" src="src1"><p>
  38. <img class="class2" id="id2" src="src2"></a></div>
  39. HTML;
  40. $dom = str_get_html($str);
  41. $es = $dom->find('img');
  42. assert(count($es)==3);
  43. assert($es[0]->src=='src0');
  44. assert($es[1]->src=='src1');
  45. assert($es[2]->src=='src2');
  46. $es = $dom->find('p');
  47. assert($es[0]->innertext=='p1');
  48. assert($dom==$str);
  49. // -----------------------------------------------------------------------------
  50. // tear down
  51. $dom->clear();
  52. unset($dom);
  53. ?>