Test::XMLElement - Perl extension for testing element properties using XML Twig
use Test::XMLElement tests => 22; my $elt = "<bar/>"; have_child("<a>abc</a>", "Element 'a' have children"); #FAIL have_child("<a>abc<b/></a>", "Element 'a' have children"); #PASS have_child_name("<a><c/></a>", "b", "Element 'a' contains child b"); #FAIL have_child_name("<a><b/></a>", "b", "Element 'a' contains child b"); #PASS child_count_is("<a></b><c>abc</c></a>", 1, "Element contains N children"); #FAIL child_count_is("<a></b><c>abc</c></a>", 2, "Element contains N children"); #PASS is_empty($elt, "Check empty"); #PASS is_empty("<a></a>", "Check empty"); #FAIL has_attributes($elt, "has Attributes"); #FAIL has_attributes("<a murug='a'/>", "has Attributes"); #PASS has_no_attrib("<a murug='a'/>", "has no attrib"); #FAIL has_no_attrib($elt, "has no attrib"); #PASS number_of_attribs("<a murug='b' c='d' e='f'/>", 1, "Number of attributes 3"); #FAIL number_of_attribs("<a murug='b'/>", 1, "Number of attributes 1"); #PASS attrib_name("<a murug='b' c='d' e='f'/>", "k", "Attribute name k"); #FAIL attrib_name("<a murug='b' c='d' e='f'/>", "c", "Attribute name c"); #PASS attrib_value("<a murug='b' c='d' e='f'/>", "c", "e", "Attribute value c"); #FAIL attrib_value("<a murug='b' c='d' e='f'/>", "c", "d", "Attribute value d"); #PASS nth_child_name("<a><b/><c/><d/></a>", 1, "c", "First child name is c"); #FAIL nth_child_name("<a><b/><c/><d/></a>", 1, "b", "First child name is b"); #PASS all_children_are("<a><b/><c/><d/></a>", "b", "All Children are b"); #FAIL all_children_are("<a><b/><b/><b/></a>", "b", "All Children are b"); #PASS
This test module allows you to check some of the XML element properties. This is useful in testing applications which generate/validates XML. Input for this module is valid XML Element. This module contains wrapper subroutines which acts as testing block for custom XML test tools.
Test passes if the XML string in $xml contains any direct child elements. $desc is description of the test
$xml
$desc
Test passes if the XML string in $xml contains any direct child element with tag or gi value as $name. Name or Describe the test with $desc.
$name
Test passes if the XML string in $xml contains exactly $count number of the child elements. Describe or name the test with $name.
$count
Test passes if the XML string in $xml is empty. $desc is description of the test
Test passes if the XML string in $xml contains any attributes. Describe or name the test with $name.
Test passes if the XML string in $xml does not contain any attributes. Describe or name the test with $name.
Test passes if the XML string in $xml contains exactly $count number of the attributes. Describe or name the test with $name.
Test passes if the XML string in $xml contains attribute with name $name. Describe or name the test with $name.
Test passes if the XML string in $xml contains attribute with name $name and its value as $value. Describe or name the test with $name.
$value
Test passes if the XML string in $xml contains any direct Nth child element with tag or gi value as $name and location at $count. Name or Describe the test with $desc.
Test passes if the XML string in $xml contains all direct child element with tag or gi value as $name. Name or Describe the test with $desc.
Test passes if the XML string in $xml contains any CDATA element as its direct child. Name or Describe the test with $desc.
Test passes if the XML string in $xml matches the XPath expression $xpath. Name or Describe the test with $desc.
$xpath
Test passes if the XML string in $xml matches $count number of XPath expression $xpath. Name or Describe the test with $desc.
Everything in "SUBROUTINES"
Test::More
Test::Builder
XML::Twig
Murugesan Kandasamy, <murugu@cpan dot org>
Copyright (C) 2009 by Murugesan Kandasamy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.
To install Test::XMLElement, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::XMLElement
CPAN shell
perl -MCPAN -e shell install Test::XMLElement
For more information on module installation, please visit the detailed CPAN module installation guide.