Source for file xml.php
Documentation is available at xml.php
* base include file for SimpleTest
* @version $Id: xml.php 1787 2008-04-26 20:35:39Z pp11 $
* include other SimpleTest class files
require_once(dirname(__FILE__
) .
'/scorer.php');
* Creates the XML needed for remote communication
* Sets up indentation and namespace.
* @param string $namespace Namespace to add to each tag.
* @param string $indent Indenting to add on each nesting.
function __construct($namespace =
false, $indent =
' ') {
$this->namespace =
($namespace ?
$namespace .
':' :
'');
* Calculates the pretty printing indent level
* from the current level of nesting.
* @param integer $offset Extra indenting level.
* @return string Leading space.
* Converts character string to parsed XML
* @param string text Unparsed character data.
* @return string Parsed character data.
array('&', '<', '>', '"', '\''),
array('&', '<', '>', '"', '''),
* Paints the start of a group test.
* @param string $test_name Name of test that is starting.
* @param integer $size Number of test cases starting.
print
"<" .
$this->namespace .
"group size=\"$size\">\n";
print
"<" .
$this->namespace .
"name>" .
"</" .
$this->namespace .
"name>\n";
* Paints the end of a group test.
* @param string $test_name Name of test that is ending.
print
"</" .
$this->namespace .
"group>\n";
* Paints the start of a test case.
* @param string $test_name Name of test that is starting.
print
"<" .
$this->namespace .
"case>\n";
print
"<" .
$this->namespace .
"name>" .
"</" .
$this->namespace .
"name>\n";
* Paints the end of a test case.
* @param string $test_name Name of test that is ending.
print
"</" .
$this->namespace .
"case>\n";
* Paints the start of a test method.
* @param string $test_name Name of test that is starting.
print
"<" .
$this->namespace .
"test>\n";
print
"<" .
$this->namespace .
"name>" .
"</" .
$this->namespace .
"name>\n";
* Paints the end of a test method.
* @param string $test_name Name of test that is ending.
* @param integer $progress Number of test cases ending.
print
"</" .
$this->namespace .
"test>\n";
* @param string $message Message to encode.
parent::paintPass($message);
print
"<" .
$this->namespace .
"pass>";
print
"</" .
$this->namespace .
"pass>\n";
* @param string $message Message to encode.
parent::paintFail($message);
print
"<" .
$this->namespace .
"fail>";
print
"</" .
$this->namespace .
"fail>\n";
* @param string $message Message to encode.
parent::paintError($message);
print
"<" .
$this->namespace .
"exception>";
print
"</" .
$this->namespace .
"exception>\n";
* Paints exception as XML.
* @param Exception $exception Exception to encode.
parent::paintException($exception);
print
"<" .
$this->namespace .
"exception>";
$message =
'Unexpected exception of type [' .
get_class($exception) .
'] with message ['.
$exception->getMessage() .
'] in ['.
$exception->getFile() .
' line ' .
$exception->getLine() .
']';
print
"</" .
$this->namespace .
"exception>\n";
* Paints the skipping message and tag.
* @param string $message Text to display in skip tag.
parent::paintSkip($message);
print
"<" .
$this->namespace .
"skip>";
print
"</" .
$this->namespace .
"skip>\n";
* Paints a simple supplementary message.
* @param string $message Text to display.
parent::paintMessage($message);
print
"<" .
$this->namespace .
"message>";
print
"</" .
$this->namespace .
"message>\n";
* Paints a formatted ASCII message such as a
* @param string $message Text to display.
parent::paintFormattedMessage($message);
print
"<" .
$this->namespace .
"formatted>";
print
"<![CDATA[$message]]>";
print
"</" .
$this->namespace .
"formatted>\n";
* Serialises the event object.
* @param string $type Event type as text.
* @param mixed $payload Message or object.
parent::paintSignal($type, $payload);
print
"<" .
$this->namespace .
"signal type=\"$type\">";
print
"<![CDATA[" .
serialize($payload) .
"]]>";
print
"</" .
$this->namespace .
"signal>\n";
* Paints the test document header.
* @param string $test_name First test top level
header('Content-type: text/xml');
print
"<?xml version=\"1.0\"";
print
" xmlns:" .
$this->namespace .
"=\"www.lastcraft.com/SimpleTest/Beta3/Report\"";
print
"<" .
$this->namespace .
"run>\n";
* Paints the test document footer.
* @param string $test_name The top level test.
print
"</" .
$this->namespace .
"run>\n";
* Accumulator for incoming tag. Holds the
* incoming test structure information for
* later dispatch to the reporter.
* Sets the basic test information except
* @param hash $attributes Name value pairs.
$this->attributes =
$attributes;
* Sets the test case/method name.
* @param string $name Name of test.
* @return string Name of test.
* Accessor for attributes.
* @return hash All attributes.
return $this->attributes;
* Accumulator for incoming method tag. Holds the
* incoming test structure information for
* later dispatch to the reporter.
* Sets the basic test information except
* @param hash $attributes Name value pairs.
* Signals the appropriate start event on the
* @param SimpleReporter $listener Target for events.
$listener->paintMethodStart($this->getName());
* Signals the appropriate end event on the
* @param SimpleReporter $listener Target for events.
$listener->paintMethodEnd($this->getName());
* Accumulator for incoming case tag. Holds the
* incoming test structure information for
* later dispatch to the reporter.
* Sets the basic test information except
* @param hash $attributes Name value pairs.
* Signals the appropriate start event on the
* @param SimpleReporter $listener Target for events.
$listener->paintCaseStart($this->getName());
* Signals the appropriate end event on the
* @param SimpleReporter $listener Target for events.
$listener->paintCaseEnd($this->getName());
* Accumulator for incoming group tag. Holds the
* incoming test structure information for
* later dispatch to the reporter.
* Sets the basic test information except
* @param hash $attributes Name value pairs.
* Signals the appropriate start event on the
* @param SimpleReporter $listener Target for events.
* Signals the appropriate end event on the
* @param SimpleReporter $listener Target for events.
$listener->paintGroupEnd($this->getName());
* The size in the attributes.
* @return integer Value of size attribute or zero.
if (isset
($attributes['SIZE'])) {
return (integer)
$attributes['SIZE'];
* Parser for importing the output of the XmlReporter.
* Dispatches that output to another reporter.
* Loads a listener with the SimpleReporter
* @param SimpleReporter $listener Listener of tag events.
$this->listener =
&$listener;
$this->tag_stack =
array();
$this->in_content_tag =
false;
$this->attributes =
array();
* Parses a block of XML sending the results to
* @param string $chunk Block of text to read.
* @return boolean True if valid XML.
* Sets up expat as the XML parser.
* @return resource Expat handle.
* Opens a new test nesting level.
* @return NestedXmlTag The group, case or method tag
* Accessor for current test structure tag.
* @return NestedXmlTag The group, case or method tag
return $this->tag_stack[0];
* @return NestedXmlTag The group, case or method tag
* Test if tag is a leaf node with only text content.
* @param string $tag XML tag name.
* @return @boolean True if leaf, false if nesting.
protected function isLeaf($tag) {
'NAME', 'PASS', 'FAIL', 'EXCEPTION', 'SKIP', 'MESSAGE', 'FORMATTED', 'SIGNAL'));
* Handler for start of event element.
* @param resource $expat Parser handle.
* @param string $tag Element name.
* @param hash $attributes Name value pairs.
* Attributes without content
protected function startElement($expat, $tag, $attributes) {
$this->attributes =
$attributes;
} elseif ($tag ==
'CASE') {
} elseif ($tag ==
'TEST') {
} elseif ($this->isLeaf($tag)) {
$this->in_content_tag =
true;
* @param resource $expat Parser handle.
* @param string $tag Element name.
$this->in_content_tag =
false;
if (in_array($tag, array('GROUP', 'CASE', 'TEST'))) {
$nesting_tag->paintEnd($this->listener);
} elseif ($tag ==
'NAME') {
$nesting_tag->setName($this->content);
$nesting_tag->paintStart($this->listener);
} elseif ($tag ==
'PASS') {
$this->listener->paintPass($this->content);
} elseif ($tag ==
'FAIL') {
$this->listener->paintFail($this->content);
} elseif ($tag ==
'EXCEPTION') {
$this->listener->paintError($this->content);
} elseif ($tag ==
'SKIP') {
$this->listener->paintSkip($this->content);
} elseif ($tag ==
'SIGNAL') {
$this->listener->paintSignal(
$this->attributes['TYPE'],
} elseif ($tag ==
'MESSAGE') {
$this->listener->paintMessage($this->content);
} elseif ($tag ==
'FORMATTED') {
$this->listener->paintFormattedMessage($this->content);
* Content between start and end elements.
* @param resource $expat Parser handle.
* @param string $text Usually output messages.
if ($this->in_content_tag) {
* XML and Doctype handler. Discards all such content.
* @param resource $expat Parser handle.
* @param string $default Text of default content.
Documentation generated on Sun, 31 Oct 2010 16:33:11 -0500 by phpDocumentor 1.4.3