diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-10-02 18:40:04 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-10-02 18:40:04 +0000 |
commit | 322bb9cd2be9e51422cb2b82684692e825c2bfb7 (patch) | |
tree | 1e8e75c1ff0c47d6eda9db114a13dfa2b83adf72 /vendors/simpletest/remote.php | |
parent | 4ffb02ad9c1b95013a0fbf97cefde827600ecc3f (diff) | |
download | elgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.gz elgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.bz2 |
Added simpletest and start of unit tests.
git-svn-id: http://code.elgg.org/elgg/trunk@3503 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'vendors/simpletest/remote.php')
-rwxr-xr-x | vendors/simpletest/remote.php | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/vendors/simpletest/remote.php b/vendors/simpletest/remote.php new file mode 100755 index 000000000..8889ed7bf --- /dev/null +++ b/vendors/simpletest/remote.php @@ -0,0 +1,117 @@ +<?php +/** + * base include file for SimpleTest + * @package SimpleTest + * @subpackage UnitTester + * @version $Id: remote.php 1723 2008-04-08 00:34:10Z lastcraft $ + */ + +/**#@+ + * include other SimpleTest class files + */ +require_once(dirname(__FILE__) . '/browser.php'); +require_once(dirname(__FILE__) . '/xml.php'); +require_once(dirname(__FILE__) . '/test_case.php'); +/**#@-*/ + +/** + * Runs an XML formated test on a remote server. + * @package SimpleTest + * @subpackage UnitTester + */ +class RemoteTestCase { + var $_url; + var $_dry_url; + var $_size; + + /** + * Sets the location of the remote test. + * @param string $url Test location. + * @param string $dry_url Location for dry run. + * @access public + */ + function RemoteTestCase($url, $dry_url = false) { + $this->_url = $url; + $this->_dry_url = $dry_url ? $dry_url : $url; + $this->_size = false; + } + + /** + * Accessor for the test name for subclasses. + * @return string Name of the test. + * @access public + */ + function getLabel() { + return $this->_url; + } + + /** + * Runs the top level test for this class. Currently + * reads the data as a single chunk. I'll fix this + * once I have added iteration to the browser. + * @param SimpleReporter $reporter Target of test results. + * @returns boolean True if no failures. + * @access public + */ + function run(&$reporter) { + $browser = &$this->_createBrowser(); + $xml = $browser->get($this->_url); + if (! $xml) { + trigger_error('Cannot read remote test URL [' . $this->_url . ']'); + return false; + } + $parser = &$this->_createParser($reporter); + if (! $parser->parse($xml)) { + trigger_error('Cannot parse incoming XML from [' . $this->_url . ']'); + return false; + } + return true; + } + + /** + * Creates a new web browser object for fetching + * the XML report. + * @return SimpleBrowser New browser. + * @access protected + */ + function &_createBrowser() { + $browser = &new SimpleBrowser(); + return $browser; + } + + /** + * Creates the XML parser. + * @param SimpleReporter $reporter Target of test results. + * @return SimpleTestXmlListener XML reader. + * @access protected + */ + function &_createParser(&$reporter) { + $parser = &new SimpleTestXmlParser($reporter); + return $parser; + } + + /** + * Accessor for the number of subtests. + * @return integer Number of test cases. + * @access public + */ + function getSize() { + if ($this->_size === false) { + $browser = &$this->_createBrowser(); + $xml = $browser->get($this->_dry_url); + if (! $xml) { + trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']'); + return false; + } + $reporter = &new SimpleReporter(); + $parser = &$this->_createParser($reporter); + if (! $parser->parse($xml)) { + trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']'); + return false; + } + $this->_size = $reporter->getTestCaseCount(); + } + return $this->_size; + } +} +?>
\ No newline at end of file |