public function testAttributes3()
 {
     $str = '<img src="src0"><p>foo</p><img src="src2">';
     $dom = new SimpleHtmlDom();
     $dom->load($str);
     $dom->find('img', 0)->id = "foo";
     $this->assertEquals('<img src="src0" id="foo"><p>foo</p><img src="src2">', $dom);
     $dom->set_callback(function ($e) {
         if ($e->src === 'src0') {
             unset($e->id);
         }
     });
     $this->assertEquals($str, $dom);
 }
 function makeup()
 {
     // text, comment, unknown
     if (isset($this->_[HDOM_INFO_TEXT])) {
         return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
     }
     $ret = '<' . $this->tag;
     $i = -1;
     foreach ($this->attr as $key => $val) {
         ++$i;
         // skip removed attribute
         if ($val === null || $val === false) {
             continue;
         }
         $ret .= $this->_[HDOM_INFO_SPACE][$i][0];
         //no value attr: nowrap, checked selected...
         if ($val === true) {
             $ret .= $key;
         } else {
             switch ($this->_[HDOM_INFO_QUOTE][$i]) {
                 case HDOM_QUOTE_DOUBLE:
                     $quote = '"';
                     break;
                 case HDOM_QUOTE_SINGLE:
                     $quote = '\'';
                     break;
                 default:
                     $quote = '';
             }
             $ret .= $key . $this->_[HDOM_INFO_SPACE][$i][1] . '=' . $this->_[HDOM_INFO_SPACE][$i][2] . $quote . $val . $quote;
         }
     }
     $ret = $this->dom->restore_noise($ret);
     return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>';
 }
 public function testUpperCase2()
 {
     $str = '<IMG CLASS="class0" ID="id0" SRC="src0">';
     $this->dom->load($str, false, true);
     $this->assertCount(0, $this->dom->find('img'));
     $this->assertCount(1, $this->dom->find('IMG'));
     $this->assertTrue(isset($this->dom->find('IMG', 0)->CLASS));
     $this->assertFalse(isset($this->dom->find('IMG', 0)->class));
     $this->assertNotEmpty($this->dom->find('IMG', 0)->CLASS);
     $this->assertEquals($str, $this->dom . '');
 }
    public function testComplexHtml()
    {
        // -----------------------------------------------
        $str = <<<HTML
<script type="text/javascript" src="test1.js">ss</script>
<script type="text/javascript" src="test2.js"/>
<script type="text/javascript" src="test3.js" />
<script type="text/javascript" src="test4.js"
/>

<script type="text/javascript" src="test5.js"/>

<style>
@import url("style1.css");
</style>

<script>
var foo = "bar";
</script>

<style type="text/css">
@import url("style2.css");
</style>

<style>
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;
color:#000;
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;
</style>

<!-- BEGIN ADVERTPRO ADVANCED CODE BLOCK -->

<script language="JavaScript" type="text/javascript">
<!--
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>');
//-->
</script>

<!-- END ADVERTPRO ADVANCED CODE BLOCK -->

<script type="text/javascript">
var foo = "bar";
</script>
HTML;
        $this->dom->load($str, true, false);
        $this->assertCount(8, $this->dom->find('script'));
        $this->assertCount(3, $this->dom->find('style'));
        $this->assertEquals($str, $this->dom . '');
    }
 /**
  * @dataProvider badHtmlTextDataProvider
  * @param $str
  */
 public function testBadHtmlText($str)
 {
     $this->dom->load($str, true, false);
 }
    public function testEmbedTag()
    {
        $dom = new SimpleHtmlDom();
        $str = <<<HTML
<EMBED
   SRC="../graphics/sounds/1812over.mid"
   HEIGHT=60 WIDTH=144>
HTML;
        $dom->load($str, true, false);
        $e = $dom->find('embed', 0);
        $this->assertEquals('../graphics/sounds/1812over.mid', $e->src);
        $this->assertEquals('60', $e->height);
        $this->assertEquals('144', $e->width);
        $this->assertEquals(strtolower($str), $dom);
    }
 /**
  * @iterations 20
  */
 public function loadBigHtmlWithoutLowerCaseAndStripRN()
 {
     $dom = new SimpleHtmlDom();
     $dom->load(self::$htmlString, false, false);
 }
 public function testDash()
 {
     $str = '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
     $this->dom->load($str);
     $this->assertEquals('text/html; charset=utf-8', $this->dom->find('meta[http-equiv=content-type]', 0)->content);
 }