NAME
Test::XMLElement - Perl extension for testing element properties using XML Twig
SYNOPSIS
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
DESCRIPTION
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.
SUBROUTINES
- have_child($xml, $desc);
-
Test passes if the XML string in
$xml
contains any direct child elements.$desc
is description of the test - have_child_name($xml, $name, $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
. - child_count_is($xml, $count, $desc);
-
Test passes if the XML string in
$xml
contains exactly$count
number of the child elements. Describe or name the test with$name
. - is_empty($xml, $desc);
-
Test passes if the XML string in
$xml
is empty.$desc
is description of the test - has_attributes($xml, $desc);
-
Test passes if the XML string in
$xml
contains any attributes. Describe or name the test with$name
. - has_no_attrib($xml, $desc);
-
Test passes if the XML string in
$xml
does not contain any attributes. Describe or name the test with$name
. - number_of_attribs($xml, $count, $desc);
-
Test passes if the XML string in
$xml
contains exactly$count
number of the attributes. Describe or name the test with$name
. - attrib_name($xml, $name, $desc);
-
Test passes if the XML string in
$xml
contains attribute with name$name
. Describe or name the test with$name
. - attrib_value($xml, $name, $value, $desc);
-
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
. - nth_child_name($xml, $count, $name, $desc);
-
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
. - all_children_are($xml, $name, $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
. - child_has_cdata($xml, $desc);
-
Test passes if the XML string in
$xml
contains any CDATA element as its direct child. Name or Describe the test with$desc
. - is_xpath($xml, $xpath, $desc);
-
Test passes if the XML string in
$xml
matches the XPath expression$xpath
. Name or Describe the test with$desc
. - is_xpath_count($xml, $xpath, $count, $desc);
-
Test passes if the XML string in
$xml
matches$count
number of XPath expression$xpath
. Name or Describe the test with$desc
.
EXPORTS
Everything in "SUBROUTINES"
SEE ALSO
AUTHOR
Murugesan Kandasamy, <murugu@cpan dot org>
COPYRIGHT AND LICENSE
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.