remote.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage UnitTester
  6. * @version $Id: remote.php 1723 2008-04-08 00:34:10Z lastcraft $
  7. */
  8. /**#@+
  9. * include other SimpleTest class files
  10. */
  11. require_once(dirname(__FILE__) . '/browser.php');
  12. require_once(dirname(__FILE__) . '/xml.php');
  13. require_once(dirname(__FILE__) . '/test_case.php');
  14. /**#@-*/
  15. /**
  16. * Runs an XML formated test on a remote server.
  17. * @package SimpleTest
  18. * @subpackage UnitTester
  19. */
  20. class RemoteTestCase {
  21. var $_url;
  22. var $_dry_url;
  23. var $_size;
  24. /**
  25. * Sets the location of the remote test.
  26. * @param string $url Test location.
  27. * @param string $dry_url Location for dry run.
  28. * @access public
  29. */
  30. function RemoteTestCase($url, $dry_url = false) {
  31. $this->_url = $url;
  32. $this->_dry_url = $dry_url ? $dry_url : $url;
  33. $this->_size = false;
  34. }
  35. /**
  36. * Accessor for the test name for subclasses.
  37. * @return string Name of the test.
  38. * @access public
  39. */
  40. function getLabel() {
  41. return $this->_url;
  42. }
  43. /**
  44. * Runs the top level test for this class. Currently
  45. * reads the data as a single chunk. I'll fix this
  46. * once I have added iteration to the browser.
  47. * @param SimpleReporter $reporter Target of test results.
  48. * @returns boolean True if no failures.
  49. * @access public
  50. */
  51. function run(&$reporter) {
  52. $browser = &$this->_createBrowser();
  53. $xml = $browser->get($this->_url);
  54. if (! $xml) {
  55. trigger_error('Cannot read remote test URL [' . $this->_url . ']');
  56. return false;
  57. }
  58. $parser = &$this->_createParser($reporter);
  59. if (! $parser->parse($xml)) {
  60. trigger_error('Cannot parse incoming XML from [' . $this->_url . ']');
  61. return false;
  62. }
  63. return true;
  64. }
  65. /**
  66. * Creates a new web browser object for fetching
  67. * the XML report.
  68. * @return SimpleBrowser New browser.
  69. * @access protected
  70. */
  71. function &_createBrowser() {
  72. $browser = &new SimpleBrowser();
  73. return $browser;
  74. }
  75. /**
  76. * Creates the XML parser.
  77. * @param SimpleReporter $reporter Target of test results.
  78. * @return SimpleTestXmlListener XML reader.
  79. * @access protected
  80. */
  81. function &_createParser(&$reporter) {
  82. $parser = &new SimpleTestXmlParser($reporter);
  83. return $parser;
  84. }
  85. /**
  86. * Accessor for the number of subtests.
  87. * @return integer Number of test cases.
  88. * @access public
  89. */
  90. function getSize() {
  91. if ($this->_size === false) {
  92. $browser = &$this->_createBrowser();
  93. $xml = $browser->get($this->_dry_url);
  94. if (! $xml) {
  95. trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']');
  96. return false;
  97. }
  98. $reporter = &new SimpleReporter();
  99. $parser = &$this->_createParser($reporter);
  100. if (! $parser->parse($xml)) {
  101. trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']');
  102. return false;
  103. }
  104. $this->_size = $reporter->getTestCaseCount();
  105. }
  106. return $this->_size;
  107. }
  108. }
  109. ?>