load(''); $e = $html->root; assert($e->first_child()==null); assert($e->last_child()==null); assert($e->next_sibling()==null); assert($e->prev_sibling()==null); // ----------------------------------------------- $str = '
'; $html->load($str); $e = $html->root; assert($e->first_child()->id=='div1'); assert($e->last_child()->id=='div1'); assert($e->next_sibling()==null); assert($e->prev_sibling()==null); assert($e->plaintext==''); assert($e->innertext=='
'); assert($e->outertext==$str); // ----------------------------------------------- $str = <<
HTML; $html->load($str); assert($html==$str); $e = $html->find('div#div1', 0); assert(isset($e->id)==true); assert(isset($e->_not_exist)==false); assert($e->first_child()->id=='div10'); assert($e->last_child()->id=='div12'); assert($e->next_sibling()==null); assert($e->prev_sibling()==null); // ----------------------------------------------- $str = <<
HTML; $html->load($str); assert($html==$str); $e = $html->find('div#div1', 0); assert($e->first_child()->id=='div10'); assert($e->last_child()->id=='div12'); assert($e->next_sibling()->id=='div2'); assert($e->prev_sibling()->id=='div0'); $e = $html->find('div#div2', 0); assert($e->first_child()==null); assert($e->last_child()==null); $e = $html->find('div#div0 div#div00', 0); assert($e->first_child()==null); assert($e->last_child()==null); assert($e->next_sibling()==null); assert($e->prev_sibling()==null); // ----------------------------------------------- $str = <<
HTML; $html->load($str); assert($html==$str); assert($html->find("#div1", 0)->id=='div1'); assert($html->find("#div1", 0)->children(0)->id=='div10'); assert($html->find("#div1", 0)->children(1)->children(1)->id=='div111'); assert($html->find("#div1", 0)->children(1)->children(1)->children(2)->id=='div1112'); // ----------------------------------------------------------------------------- // no value attr test $str = << aaa
bbb
ccc
HTML; $html->load($str); assert($html==$str); $counter = 0; foreach($html->find('input[type=checkbox]') as $checkbox) { if (isset($checkbox->checked)) { assert($checkbox->value=="checkbox$counter"); $counter += 2; } } $counter = 0; foreach($html->find('input[type=checkbox]') as $checkbox) { if ($checkbox->checked) { assert($checkbox->value=="checkbox$counter"); $counter += 2; } } $es = $html->find('input[type=checkbox]'); $es[1]->checked = true; assert($es[1]->outertext==''); $es[0]->checked = false; assert($es[0]==''); $es[0]->checked = true; assert($es[0]->outertext==''); // ----------------------------------------------------------------------------- // remove attr test $str = << HTML; $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox0]', 0); $e->name = null; assert($e==''); $e->type = null; assert($e==''); // ----------------------------------------------- $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox0]', 0); $e->name = null; assert($e==''); $e->type = null; assert($e==''); // ----------------------------------------------- $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox1]', 0); $e->value = null; assert($e==""); $e->type = null; assert($e==""); $e->name = null; assert($e==''); $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox1]', 0); $e->type = null; assert($e==""); $e->name = null; assert($e==''); $e->value = null; assert($e==''); // ----------------------------------------------------------------------------- // remove no value attr test $str = << HTML; $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox1]', 0); $e->type = NULL; assert($e==""); $e->name = null; assert($e==""); $e->checked = NULL; assert($e==""); // ----------------------------------------------- $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox0]', 0); $e->type = NULL; assert($e==""); $e->name = NULL; assert($e==''); $e->checked = NULL; assert($e==''); $html->load($str); assert($html==$str); $e = $html->find('[name=checkbox0]', 0); $e->checked = NULL; assert($e==""); $e->name = NULL; assert($e==''); $e->type = NULL; assert($e==""); // ----------------------------------------------------------------------------- // extract text $str = <<okok HTML; $html->load($str); assert($html==$str); assert($html->plaintext=='okok'); $str = <<okok HTML; $html->load($str); assert($html==$str); assert($html->plaintext=='okok'); $str = <<okok HTML; $html->load($str); assert($html==$str); assert($html->plaintext=='okok'); $str = <<okok HTML; $html->load($str); assert($html==$str); assert($html->plaintext=='okok'); // ----------------------------------------------------------------------------- // old fashion camel naming conventions test $str = << HTML; $html->load($str); assert($html==$str); assert($html->getElementByTagName('input')->hasAttribute('checked')==true); assert($html->getElementsByTagName('input', 1)->hasAttribute('checked')==false); assert($html->getElementsByTagName('input', 1)->hasAttribute('not_exist')==false); assert($html->find('input', 0)->value==$html->getElementByTagName('input')->getAttribute('value')); assert($html->find('input', 1)->value==$html->getElementsByTagName('input', 1)->getAttribute('value')); assert($html->find('#checkbox1', 0)->value==$html->getElementById('checkbox1')->getAttribute('value')); assert($html->find('#checkbox2', 0)->value==$html->getElementsById('checkbox2', 0)->getAttribute('value')); $e = $html->find('[name=checkbox]', 0); assert($e->getAttribute('value')=='checkbox'); assert($e->getAttribute('checked')==true); assert($e->getAttribute('not_exist')==''); $e->setAttribute('value', 'okok'); assert($e==''); $e->setAttribute('checked', false); assert($e==''); $e->setAttribute('checked', true); assert($e==''); $e->removeAttribute('value'); assert($e==''); $e->removeAttribute('checked'); assert($e==''); // ----------------------------------------------- $str = <<
HTML; $html->load($str); assert($html==$str); $e = $html->find('div#div1', 0); assert($e->firstChild()->getAttribute('id')=='div10'); assert($e->lastChild()->getAttribute('id')=='div12'); assert($e->nextSibling()==null); assert($e->previousSibling()==null); // ----------------------------------------------- $str = <<
HTML; $html->load($str); assert($html==$str); assert($html->getElementById("div1")->hasAttribute('id')==true); assert($html->getElementById("div1")->hasAttribute('not_exist')==false); assert($html->getElementById("div1")->getAttribute('id')=='div1'); assert($html->getElementById("div1")->childNodes(0)->getAttribute('id')=='div10'); assert($html->getElementById("div1")->childNodes(1)->childNodes(1)->getAttribute('id')=='div111'); assert($html->getElementById("div1")->childNodes(1)->childNodes(1)->childNodes(2)->getAttribute('id')=='div1112'); assert($html->getElementsById("div1", 0)->childNodes(1)->id=='div11'); assert($html->getElementsById("div1", 0)->childNodes(1)->childNodes(1)->getAttribute('id')=='div111'); assert($html->getElementsById("div1", 0)->childNodes(1)->childNodes(1)->childNodes(1)->getAttribute('id')=='div1111'); // ----------------------------------------------- $str = << HTML; $html->load($str); $ul = $html->find('ul', 0); assert($ul->first_child()->tag==='ul'); // ----------------------------------------------- $str = <<
  • Item 1
  • Item 2
  • HTML; $html->load($str); assert($html==$str); $ul = $html->find('ul', 0); assert($ul->first_child()->tag==='li'); assert($ul->first_child()->next_sibling()->tag==='li'); // ----------------------------------------------------------------------------- // tear down $html->clear(); unset($html); ?>