123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
-
- require_once 'Sweety/Runner/AbstractTestRunner.php';
-
-
- class Sweety_Runner_HtmlRunner extends Sweety_Runner_AbstractTestRunner
- {
-
-
-
- private $_template;
-
-
-
- private $_name;
-
-
-
- public function __construct(array $dirs, $template, $name)
- {
- $this->_dirs = $dirs;
- $this->_template = $template;
- $this->_name = $name;
- }
-
-
-
- public function runAllTests($dirs = array())
- {
-
- header("Cache-Control: no-cache, must-revalidate");
- header("Pragma: no-cache");
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-
- if (empty($dirs))
- {
- $dirs = $this->_dirs;
- }
-
- $testCases = $this->findTests($dirs);
- foreach ($testCases as $k => $testCase)
- {
- if (preg_match($this->getIgnoredClassRegex(), $testCase))
- {
- unset($testCases[$k]);
- }
- }
-
- usort($testCases, array($this, '_sort'));
-
- $vars = array(
-
- 'testCases' => $testCases,
-
- 'suiteName' => $this->_name,
-
- 'runTests' => array(),
-
- 'caseCount' => 0,
-
- 'runCount' => 0,
-
- 'passCount' => 0,
-
- 'failCount' => 0,
-
- 'exceptionCount' => 0,
-
- 'messages' => array(),
-
- 'result' => 'idle'
- );
-
- if (isset($_REQUEST['runtests']))
- {
- $reporter = $this->getReporter();
- $reporter->setTemplateVars($vars);
-
- if (!$reporter->isStarted())
- {
- $reporter->start();
- }
-
- $this->_runTestList((array)$_REQUEST['runtests'], $reporter);
-
- $reporter->finish();
- }
- else
- {
- foreach ($testCases as $testCase)
- {
- $vars['runTests'][$testCase] = 'idle';
- }
- }
-
- $this->_render($vars);
- }
-
-
-
- protected function _runTestList(array $tests, Sweety_Reporter $reporter)
- {
- $protocol = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
-
-
- $server = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '127.0.0.1';
-
- $path = '/';
- if (!empty($_SERVER['REQUEST_URI']))
- {
- $path = preg_replace('/\?.*$/sD', '', $_SERVER['REQUEST_URI']);
- }
-
- $baseUrl = $protocol . $server . $path;
-
- foreach ($tests as $testCase)
- {
- $url = $baseUrl . '?test=' . $testCase . '&format=xml';
- $xml = file_get_contents($url);
- $this->parseXml($xml, $testCase);
- }
-
- return 0;
- }
-
-
-
- protected function _render($vars = array())
- {
- foreach ($vars as $k => $v)
- {
- $$k = $v;
- }
-
- require_once $this->_template;
- }
-
- }
|