Пример #1
0
 /**
  * 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));
 }
Пример #2
0
 /**
  * Run one test and return JSON result
  *
  * @param string Test file name (absolute name of PHP file)
  * @param string Unique token to return back, if required
  * @param array Associative array of options to be used for setAjaxOptions()
  * @return string JSON
  * @throws Exception
  * @see bootstrap.php
  */
 public function run($fileName, $token = 'token', $options = array())
 {
     if (!$this->getAuth()->isAuthenticated()) {
         //TODO: handle situation when login screen should appear
         throw new Exception("Authentication failed, please login first");
     }
     $test = phpRack_Test::factory($fileName, $this);
     $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));
 }