Ejemplo n.º 1
0
 /**
  * Initialization method installs PHPUnit and loads all plugins
  *
  * @return void
  * @throws Exception
  */
 public function initialize()
 {
     $this->_dispatcher = new CakeTestSuiteDispatcher();
     $success = $this->_dispatcher->loadTestFramework();
     if (!$success) {
         throw new Exception(__d('cake_dev', 'Please install PHPUnit framework v3.7 <info>(http://www.phpunit.de)</info>'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Initialization method installs Simpletest and loads all plugins
  *
  * @return void
  */
 public function initialize()
 {
     require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_dispatcher.php';
     $corePath = App::core('cake');
     if (isset($corePath[0])) {
         define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
     } else {
         define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
     }
     $this->_dispatcher = new CakeTestSuiteDispatcher();
     $this->_dispatcher->loadTestFramework();
     require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_command.php';
 }
Ejemplo n.º 3
0
 /**
  * Executes a Cake URL, and can get (depending on the $params['return'] value):
  *
  * Params:
  * - 'return' has several possible values:
  *   1. 'result': Whatever the action returns (and also specifies $this->params['requested'] for controller)
  *   2. 'view': The rendered view, without the layout
  *   3. 'contents': The rendered view, within the layout.
  *   4. 'vars': the view vars
  *
  * - 'fixturize' - Set to true if you want to copy model data from 'connection' to the test_suite connection
  * - 'data' - The data you want to insert into $this->data in the controller.
  * - 'connection' - Which connection to use in conjunction with fixturize (defaults to 'default')
  * - 'method' - What type of HTTP method to simulate (defaults to post)
  *
  * @param string $url Cake URL to execute (e.g: /articles/view/455)
  * @param mixed $params Parameters (see above), or simply a string of what to return
  * @return mixed Whatever is returned depending of requested result
  * @access public
  */
 function testAction($url, $params = array())
 {
     $default = array('return' => 'result', 'fixturize' => false, 'data' => array(), 'method' => 'post', 'connection' => 'default');
     if (is_string($params)) {
         $params = array('return' => $params);
     }
     $params = array_merge($default, $params);
     $toSave = array('case' => null, 'group' => null, 'app' => null, 'output' => null, 'show' => null, 'plugin' => null);
     $this->__savedGetData = empty($this->__savedGetData) ? array_intersect_key($_GET, $toSave) : $this->__savedGetData;
     $data = !empty($params['data']) ? $params['data'] : array();
     if (strtolower($params['method']) == 'get') {
         $_GET = array_merge($this->__savedGetData, $data);
         $_POST = array();
     } else {
         $_POST = array('data' => $data);
         $_GET = $this->__savedGetData;
     }
     $return = $params['return'];
     $params = array_diff_key($params, array('data' => null, 'method' => null, 'return' => null));
     $dispatcher = new CakeTestDispatcher();
     $dispatcher->testCase($this);
     if ($return != 'result') {
         if ($return != 'contents') {
             $params['layout'] = false;
         }
         ob_start();
         @$dispatcher->dispatch($url, $params);
         $result = ob_get_clean();
         if ($return == 'vars') {
             $view = ClassRegistry::getObject('view');
             $viewVars = $view->getVars();
             $result = array();
             foreach ($viewVars as $var) {
                 $result[$var] = $view->getVar($var);
             }
             if (!empty($view->pageTitle)) {
                 $result = array_merge($result, array('title' => $view->pageTitle));
             }
         }
     } else {
         $params['return'] = 1;
         $params['bare'] = 1;
         $params['requested'] = 1;
         $result = @$dispatcher->dispatch($url, $params);
     }
     if (isset($this->_actionFixtures)) {
         unset($this->_actionFixtures);
     }
     ClassRegistry::flush();
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * testTestDispatcher
  *
  * @access public
  * @return void
  */
 function testTestDispatcher()
 {
     App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS), 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)), true);
     $Dispatcher = new CakeTestDispatcher();
     $Case = new CakeDispatcherMockTestCase();
     $Case->expectOnce('startController');
     $Case->expectOnce('endController');
     $Dispatcher->testCase($Case);
     $this->assertTrue(isset($Dispatcher->testCase));
     $return = $Dispatcher->dispatch('/tests_apps/index', array('autoRender' => 0, 'return' => 1, 'requested' => 1));
 }