示例#1
0
文件: Suite.php 项目: tpc2/phprack
 /**
  * Create new instance of the class, using PHP absolute file name
  *
  * @param $label string ID of the suite, its label
  * @param $runner phpRack_Runner Instance of test runner
  * @return phpRack_Suite
  * @throws phpRack_Exception
  * @see _addSuite()
  * @see phpRack_Runner::getTests()
  */
 public static function factory($label, phpRack_Runner $runner)
 {
     $fileName = $runner->getDir() . '/' . $label;
     if (!file_exists($fileName)) {
         throw new phpRack_Exception("File '{$fileName}' is not found");
     }
     if (!preg_match(phpRack_Runner::SUITE_PATTERN, $fileName)) {
         throw new phpRack_Exception("File '{$fileName}' is not named properly, can't run it");
     }
     $className = pathinfo($fileName, PATHINFO_FILENAME);
     // workaround against ZCA static code analysis
     eval('require_once $fileName;');
     return new $className($runner);
 }
示例#2
0
 /**
  * Checks whether user is authenticated before running any tests
  *
  * @return boolean
  * @see bootstrap.php
  */
 public function isAuthenticated()
 {
     if (!is_null($this->_authResult)) {
         return $this->_authResult->isValid();
     }
     // this is CLI environment, not web -- we don't require any
     // authentication
     if ($this->_runner->isCliEnvironment()) {
         return $this->_validated(true)->isValid();
     }
     // there are a number of possible authentication scenarios
     switch (true) {
         case $result = $this->_tryHttpPost():
             break;
         case $result = $this->_tryHttpGet():
             break;
         case $result = $this->_tryHttpCookie():
             break;
         case $result = $this->_tryPlainAuth():
             break;
         default:
             // no authinfo, chances are that site is not protected
             $result = array('login' => false, 'hash' => false);
     }
     $this->_authResult = $this->authenticate($result['login'], $result['hash'], true);
     return $this->_authResult->isValid();
 }
示例#3
0
 public function testGetParamsAuthenticationWorksProperly()
 {
     global $phpRackConfig;
     $authArray = array('auth' => array('username' => uniqid(), 'password' => uniqid()));
     // Injecting values into config
     $authArray = array_merge($phpRackConfig, $authArray);
     // Removing htaccess authentication in case it is set
     if (array_key_exists('htpasswd', $authArray)) {
         unset($authArray['htpasswd']);
     }
     // Creating instance of Runner to test it with our config
     $runner = new phpRack_Runner($authArray);
     $_GET[phpRack_Runner_Auth::GET_LOGIN] = $authArray['auth']['username'];
     $_GET[phpRack_Runner_Auth::GET_PWD] = $authArray['auth']['password'];
     $this->assertTrue($runner->getAuth()->isAuthenticated(), 'Invalid auth using get parameters (Phing bridge)');
 }
示例#4
0
 public function testHttpGetRequestDeliversValidJSON()
 {
     global $phpRackConfig;
     $runner = new phpRack_Runner($phpRackConfig);
     $tests = $runner->getTests();
     $this->assertTrue(count($tests) > 1, 'too few tests, why?');
     // get one random test
     shuffle($tests);
     $test = array_shift($tests);
     $_GET[PHPRACK_AJAX_TAG] = $test->getFileName();
     $_GET[PHPRACK_AJAX_TOKEN] = 'token';
     ob_start();
     include PHPRACK_PATH . '/bootstrap.php';
     $result = ob_get_clean();
     $this->assertFalse(empty($result));
 }
示例#5
0
     define('PHPRACK_VERSION', '2.0-SNAPSHOT');
 }
 if (!defined('PHPRACK_AJAX_TAG')) {
     define('PHPRACK_AJAX_TAG', 'test');
 }
 if (!defined('PHPRACK_AJAX_TOKEN')) {
     define('PHPRACK_AJAX_TOKEN', 'token');
 }
 if (!defined('PHPRACK_PATH')) {
     define('PHPRACK_PATH', dirname(__FILE__));
 }
 /**
  * @see phpRack_Runner
  */
 require_once PHPRACK_PATH . '/Runner.php';
 $runner = new phpRack_Runner($phpRackConfig);
 /**
  * @see phpRack_View
  */
 require_once PHPRACK_PATH . '/View.php';
 // if it's CLI environment - just show a full test report
 if ($runner->isCliEnvironment()) {
     throw new Exception($runner->runSuite());
 }
 // check whether SSL connection is mandatory?
 if (!$runner->isEnoughSecurityLevel()) {
     throw new Exception('You must use SSL protocol to run integration tests');
 }
 /**
  * Using this tag in GET URL we can get a summary report
  * in plain text format.
示例#6
0
文件: Test.php 项目: tpc2/phprack
 /**
  * Get label of the test
  *
  * @return string
  */
 public function getLabel()
 {
     return ltrim(substr($this->_fileName, strlen($this->_runner->getDir())), '/');
 }