/** * Run one test and return JSON result. * * @param $label string Test label * @param $token string Unique token to return back, if required * @param $options array Associative array of options to be used for setAjaxOptions() * @return string JSON * @throws phpRack_Exception * @see bootstrap.php */ public function run($label, $token = 'token', $options = array()) { if (!$this->getAuth()->isAuthenticated()) { throw new phpRack_Exception("Authentication failed, please login first"); } // if this is one of our built-in tests if (!empty($options['suiteTest'])) { /** * @see phpRack_Suite */ require_once PHPRACK_PATH . '/Suite/Test.php'; $test = phpRack_Suite_Test::factory($label, $this); if (isset($options['config'])) { $test->setConfig($options['config']); } } else { $test = phpRack_Test::factory($label, $this); } unset($options['config']); unset($options['suiteTest']); $test->setAjaxOptions($options); $result = $test->run(); $options = $test->getAjaxOptions(); /** * @see phpRack_Runner_Logger */ require_once PHPRACK_PATH . '/Runner/Logger.php'; return json_encode(array('success' => $result->wasSuccessful(), 'options' => $options, 'log' => phpRack_Runner_Logger::utf8Encode(phpRack_Runner_Logger::cutLog($result->getLog(), intval($options['logSizeLimit']))), PHPRACK_AJAX_TOKEN => $token)); }
/** * Add test * * Test should be located in our test library, inside "phpRack/Suite/library" * directory, and should be inherited from {@link phpRack_Suite_Test} class. * * @param $testName string Suite name * @param $config array config * @return $this * @throws phpRack_Exception if test can't be found * @see MySuite::_init() * @see phpRack_Suite_Test */ protected function _addTest($testName, array $config = array()) { require_once PHPRACK_PATH . '/Suite/Test.php'; // Exception is possible here $test = phpRack_Suite_Test::factory($testName . 'Test.php', $this->_runner); $test->setConfig($config); $this->_tests[] = $test; return $this; }