#!/usr/bin/perl -w
use Test::More tests => 18;
BEGIN {
use_ok ('XML::LibXML')
};
my $doc = new XML::LibXML::Document;
ok (defined $doc, 'Document constructed');
ok ($doc->isa ('XML::LibXML::Document'), 'Document: correct object class');
my $par = $doc->createElement ('Paragraph');
ok (defined $par, 'XML Element constructed via Document');
ok ($par->isa ('XML::LibXML::Element'), 'Element: correct object class');
is ($par->ownerDocument (), $doc, 'Element has correct owner');
#explicitly set owner document
$par->setOwnerDocument ($doc);
is ($par->ownerDocument (), $doc, 'Element has correct owner after explicitly setting it');
#add text to Element
$par->appendText ('Some text');
is ($par->toString (), 'Some text', 'Text added to Element');
#construct Element from scratch
$par2 = new XML::LibXML::Element ('Paragraph');
ok (defined $par2, 'XML Element constructed from scratch');
ok ($par2->isa ('XML::LibXML::Element'), 'new Element: correct object class');
#add text to Element
$par2->appendText ('Other text');
is ($par2->toString (), 'Other text', 'Text added to Element before setting owner document');
#explicitly set owner document
$par2->setOwnerDocument ($doc);
is ($par2->ownerDocument (), $doc, 'Element has correct owner after explicitly setting it');
#add text to Element after setting owner document
$par2->appendText ('Other text');
is ($par2->toString (), 'Other text', 'Text added to Element after setting owner document');
#add paragraph to document
$doc->appendChild ($par);
is ($doc->hasChildNodes (), 1, 'Element added to document');
is ($doc->toString (), '
Some text', '$doc->toString () works OK');
#attempt with appendChild
eval {$doc->insertBefore ($par);};
is ($@, '', '$doc->insertBefore(): OK');
is ($doc->hasChildNodes (), 1, 'Element added to document with appendBefore');
#attempt to insert DocumentFragment into Document
eval {$doc->appendChild ($par->ownerDocument ());};
is ($@, '', 'insert Document Fragment: OK');