use Test::More tests => 33; use strict; use warnings; use pQuery::DOM; my $dom = pQuery::DOM->fromHTML('

Hello world

'); is $dom->nodeType, '1', 'nodeType is 1'; is $dom->nodeName, 'P', 'nodeName is P'; is $dom->getAttribute('id'), 'id1', 'id attribute is correct'; is $dom->id, 'id1', 'id method is correct'; is $dom->getAttribute('class'), 'class1', 'id attribute is correct'; is $dom->className, 'class1', 'className method is correct'; $dom = pQuery::DOM->fromHTML('

I Like

!

'); is $dom->toHTML, '

I Like

!

', 'innerHTML works'; is $dom->innerHTML, 'I Like !', 'innerHTML works'; $dom = pQuery::DOM->fromHTML(<<'...');
Foo Bar Baz
... my $span = $dom->getElementById('span1'); is $span->innerHTML, "Foo", 'getElementById works'; is $span->nodeValue, undef, 'nodeValue is undefined for Element'; is $span->tagName, "SPAN", 'tagName works'; my @spans = $dom->getElementsByTagName('span'); is scalar(@spans), 3, "Found 3 spans"; is $spans[0]->innerHTML, "Foo", '1st value is correct'; is $spans[1]->innerHTML, "Bar", '2nd value is correct'; $span->setAttribute('Foo', 'Bar'); is $span->toHTML, 'Foo', 'setAttribute works'; is (pQuery::DOM->fromHTML('
')->hasAttributes, 0, 'hasAttributes works'); is (pQuery::DOM->fromHTML('
')->hasAttributes, 1, 'hasAttributes works'); $span->removeAttribute('Id'); is $span->toHTML, 'Foo', 'removeAttribute works'; is $span->parentNode->id, 'div2', 'parentNode works'; my $div2 = $dom->getElementById('div2'); my @children = $div2->childNodes; is scalar(@children), 7, 'div2 has 7 children'; is ref($children[0]), '', 'child 1 is text node'; is $div2->firstChild, "\n ", "firstChild works"; is $div2->lastChild, "\n ", "lastChild works"; $dom = pQuery::DOM->fromHTML('
xxxzzz
'); my @elems = pQuery::DOM->fromHTML('
xxxzzz
')->childNodes; my $comment = $elems[1]; is $comment->nodeType, 8, 'Handle comment nodes'; is $comment->nodeValue, ' yyy ', 'Handle comment node value'; is $comment->hasAttributes, 0, "Comments don't have attributes"; is $comment->nodeName, '#comment', 'Comment has proper nodeName'; is $comment->tagName, '', 'Comment has no tagName'; is $comment->parentNode->tagName, 'DIV', 'Comment has parentNode'; is $dom->toHTML, '
xxxzzz
', 'Comments work in toHTML'; is $comment->innerHTML, undef, 'Comments have no innerHTML'; $dom->innerHTML('I Like Pie'); is $dom->toHTML, '
I Like Pie
', 'Setting innerHTML works'; my $div = pQuery::DOM->createElement('div'); $div->id('new-div'); $div->className('classy'); $comment = pQuery::DOM->createComment('I am remarkable'); $div->appendChild('Foo'); $div->appendChild($comment); is $div->toHTML, '
Foo
', 'createElement, createComment and appendChild work';