Permalink
Browse files

bring test coverage up to 100%

git-svn-id: http://svn.php.net/repository/pear/packages/XML_Util/trunk@260454 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent fd49542 commit 7a2e789170404275a2267b631612ec3f8cd94575 Chuck Burgess committed May 30, 2008
@@ -19,13 +19,26 @@ echo XML_Util::createStartElement(
array("foo" => "bar")
) . PHP_EOL . PHP_EOL;
+echo "TEST: tag only, passing '' as attribute arg" . PHP_EOL;
+echo XML_Util::createStartElement(
+ 'myNs:myTag',
+ ''
+) . PHP_EOL . PHP_EOL;
+
echo "TEST: tag with attributes and namespace" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar"),
"http://www.w3c.org/myNs#"
) . PHP_EOL . PHP_EOL;
+echo "TEST: tag with empty attributes, whose namespaceUri is not a full namespace" . PHP_EOL;
+echo XML_Util::createStartElement(
+ 'myTag',
+ '',
+ 'foo'
+) . PHP_EOL . PHP_EOL;
+
echo "TEST: tag with attributes, namespace, and multiline = true" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
@@ -84,9 +97,15 @@ TEST: tag only
TEST: tag with attributes
<myNs:myTag foo="bar">
+TEST: tag only, passing '' as attribute arg
+<myNs:myTag>
+
TEST: tag with attributes and namespace
<myNs:myTag foo="bar" xmlns:myNs="http://www.w3c.org/myNs#">
+TEST: tag with empty attributes, whose namespaceUri is not a full namespace
+<myTag xmlns="foo">
+
TEST: tag with attributes, namespace, and multiline = true
<myNs:myTag foo="bar"
xmlns:myNs="http://www.w3c.org/myNs#">
@@ -45,6 +45,30 @@ $tag7 = array(
"content" => "I'm inside the tag",
);
+$tag8 = array(
+ 'content' => array('foo', 'bar')
+);
+
+$tag9 = array(
+ 'qname' => 'foo:bar',
+ 'namespaces' => array('ns1' => 'uri1', 'ns2' => 'uri2')
+);
+
+$tag10 = array(
+ 'namespace' => 'http://foo.org',
+ 'localPart' => 'bar'
+);
+
+$tag11 = array(
+ 'namespace' => '',
+ 'localPart' => 'bar'
+);
+
+$tag12 = array(
+ 'localPart' => 'foo',
+ 'namespaceUri' => 'http://bar.org'
+);
+
echo "TEST: basic usage with an invalid array" . PHP_EOL;
echo XML_Util::createTagFromArray($bad) . PHP_EOL . PHP_EOL;
@@ -92,6 +116,21 @@ echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true, ' ',
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = false" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true, ' ', '^', false) . PHP_EOL . PHP_EOL;
+
+echo 'TEST: cause a non-scalar error on the content tag' . PHP_EOL;
+echo XML_Util::createTagFromArray($tag8) . PHP_EOL . PHP_EOL;
+
+echo 'TEST: handle an array of namespaces being passed' . PHP_EOL;
+echo XML_Util::createTagFromArray($tag9) . PHP_EOL . PHP_EOL;
+
+echo 'TEST: qname is derived from namespace + localPart' . PHP_EOL;
+echo XML_Util::createTagFromArray($tag10) . PHP_EOL . PHP_EOL;
+
+echo 'TEST: qname is derived from localPart only' . PHP_EOL;
+echo XML_Util::createTagFromArray($tag11) . PHP_EOL . PHP_EOL;
+
+echo 'TEST: namespaceUri is given, but namespace is not' . PHP_EOL;
+echo XML_Util::createTagFromArray($tag12) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createTagFromArray() basic tests=====
@@ -147,3 +186,18 @@ TEST: basic usage with a valid array (qname, namespaceUri, attributes, and cont
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = false
<foo:bar key="value"^ argh="fruit&amp;vegetable"^ xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
+
+TEST: cause a non-scalar error on the content tag
+Supplied non-scalar value as tag content
+
+TEST: handle an array of namespaces being passed
+<foo:bar xmlns:ns1="uri1" xmlns:ns2="uri2" />
+
+TEST: qname is derived from namespace + localPart
+<http://foo.org:bar />
+
+TEST: qname is derived from localPart only
+<bar />
+
+TEST: namespaceUri is given, but namespace is not
+<foo xmlns="http://bar.org" />
@@ -23,6 +23,15 @@ if (is_a($result, 'PEAR_Error')) {
} else {
print "Valid XML name." . PHP_EOL . PHP_EOL;
}
+
+echo "TEST: invalid tag that doesn't start with a letter" . PHP_EOL;
+$result = XML_Util::isValidName("1234five");
+if (is_a($result, 'PEAR_Error')) {
+ print "Invalid XML name: " . $result->getMessage() . PHP_EOL . PHP_EOL;
+} else {
+ print "Valid XML name." . PHP_EOL . PHP_EOL;
+}
+
?>
--EXPECT--
=====XML_Util::isValidName() basic tests=====
@@ -32,3 +41,6 @@ Valid XML name.
TEST: invalid tag
Invalid XML name: XML names may only contain alphanumeric chars, period, hyphen, colon and underscores
+
+TEST: invalid tag that doesn't start with a letter
+Invalid XML name: XML names may only start with letter or underscore

0 comments on commit 7a2e789

Please sign in to comment.