9e320ac8680f0f7cbad892b4e2ff77ca7b54741f.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // $Rev: 169 $
  3. // -----------------------------------------------------------------------------
  4. // setup
  5. error_reporting(E_ALL);
  6. require_once('../simple_html_dom.php');
  7. $dom = new simple_html_dom;
  8. // -----------------------------------------------------------------------------
  9. // comments test
  10. $str = <<<HTML
  11. <div class="class0" id="id0" >
  12. <!--
  13. <input type=submit name="btnG" value="go" onclick='goto("url0")'>
  14. -->
  15. </div>
  16. HTML;
  17. $dom->load($str);
  18. assert(count($dom->find('input'))==0);
  19. // -----------------------------------------------------------------------------
  20. // <code> test
  21. $str = <<<HTML
  22. <div class="class0" id="id0" >
  23. <CODE>
  24. <input type=submit name="btnG" value="go" onclick='goto("url0")'>
  25. </CODE>
  26. </div>
  27. HTML;
  28. $dom->load($str);
  29. assert(count($dom->find('code'))==1);
  30. assert(count($dom->find('input'))==0);
  31. // -----------------------------------------------------------------------------
  32. // <pre> & <code> test
  33. $str = <<<HTML
  34. <PRE><CODE CLASS=Java>
  35. <input type=submit name="btnG" value="go" onclick='goto("url0")'>
  36. </CODE></PRE>
  37. HTML;
  38. $dom->load($str);
  39. assert(count($dom->find('pre'))==1);
  40. assert(count($dom->find('input'))==0);
  41. // -----------------------------------------------------------------------------
  42. // <script> & <style> test
  43. $str = <<<HTML
  44. <script type="text/javascript" src="test.js"></script>
  45. <script type="text/javascript" src="test.js"/>
  46. <style type="text/css">
  47. @import url("style.css");
  48. </style>
  49. <script type="text/javascript">
  50. var foo = "bar";
  51. </script>
  52. HTML;
  53. $dom->load($str);
  54. assert(count($dom->find('style'))==1);
  55. assert(count($dom->find('script'))==3);
  56. // -----------------------------------------------------------------------------
  57. // php short tag test
  58. $str = <<<HTML
  59. <a href="<?=h('ok')?>">hello</a>
  60. <input type=submit name="btnG" value="<?php echoh('ok')?>">
  61. HTML;
  62. $dom->load($str);
  63. assert($dom->find('a', 0)->href==="<?=h('ok')?>");
  64. assert($dom->find('input', 0)->value==="<?php echoh('ok')?>");
  65. // -----------------------------------------------------------------------------
  66. // noise stripping test
  67. $str = <<<HTML
  68. <!--
  69. <img class="class0" id="id0" src="src0">-->
  70. <img class="class1" id="id1" src="src1">
  71. <!--<img class="class2" id="id2" src="src2">
  72. -->
  73. HTML;
  74. $dom->load($str);
  75. assert(count($dom->find('img'))==1);
  76. assert($dom==$str);
  77. // -----------------------------------------------
  78. $str = <<<HTML
  79. <script type="text/javascript" src="test1.js">ss</script>
  80. <script type="text/javascript" src="test2.js"/>
  81. <script type="text/javascript" src="test3.js" />
  82. <script type="text/javascript" src="test4.js"
  83. />
  84. <script type="text/javascript" src="test5.js"/>
  85. <style>
  86. @import url("style1.css");
  87. </style>
  88. <script>
  89. var foo = "bar";
  90. </script>
  91. <style type="text/css">
  92. @import url("style2.css");
  93. </style>
  94. <style>
  95. div,td,.n a,.n a:visited{color:#000}.ts td,.tc{padding:0}.ts,.tb{border-collapse:collapse}.ti,.bl{display:inline}.ti{display:inline-table}.f,.m{color:#666}.flc,a.fl{color:#77c}a,.w,.q:visited,.q:active,.q,.b a,.b a:visited,.mblink:visited{color:#00c}a:visited{color:#551a8b}a:active{color:red}.t{background:#d5ddf3;
  96. color:#000;
  97. padding:5px 1px 4px}.bb{border-bottom:1px solid #36c}.bt{border-top:1px solid #36c}.j{width:34em}.h{color:#36c}.i{color:#a90a08}.a{color:green}.z{display:none}div.n{margin-top:1ex}.n a,.n .i{font-size:10pt}.n .i,.b a{font-weight:bold}.b a{font-size:12pt}.std{font-size:82%}#np,#nn,.nr,#logo span,.ch{cursor:pointer;cursor:hand}.ta{padding:3px 3px 3px 5px}#tpa2,#tpa3{padding-top:9px}#gbar{float:left;height:22px;padding-left:2px}.gbh,.gb2 div{border-top:1px solid #c9d7f1;
  98. </style>
  99. <!-- BEGIN ADVERTPRO ADVANCED CODE BLOCK -->
  100. <script language="JavaScript" type="text/javascript">
  101. <!--
  102. document.write('<SCR'+'IPT src="zone?zid=159&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime()+'" language="JavaScript" type="text/javascript"></SCR'+'IPT>');
  103. //-->
  104. </script>
  105. <!-- END ADVERTPRO ADVANCED CODE BLOCK -->
  106. <script type="text/javascript">
  107. var foo = "bar";
  108. </script>
  109. HTML;
  110. $dom->load($str);
  111. assert(count($dom->find('script'))==8);
  112. assert(count($dom->find('style'))==3);
  113. //echo "\n\n\n\n".$dom->save();
  114. assert($dom==$str);
  115. // -----------------------------------------------------------------------------
  116. // tear down
  117. $dom->clear();
  118. unset($dom);
  119. ?>