コード例 #1
0
 /**
  * Starts the process for the given $url.
  * 
  * @param string $url Requested URL
  * @param array $params Settings array ("bare", "return") which is
  *              melded with the GET and POST params
  * @return mixed The results of the called action
  */
 public function startActionForTest($url, $params = array())
 {
     $default = array('fixturize' => false, 'data' => array(), 'method' => 'get', 'connection' => 'default');
     $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;
     }
     $_SERVER['REQUEST_METHOD'] = strtoupper($params['method']);
     $params = array_diff_key($params, array('data' => null, 'method' => null));
     $Dispatcher = new Dispatcher();
     $url = $Dispatcher->getUrl($url);
     $this->params = array_merge($Dispatcher->parseParams($url), $params);
     $this->here = $this->base . '/' . $url;
     Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
     $this->base = $this->base;
     $this->here = $this->here;
     $this->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null;
     $this->action =& $this->params['action'];
     $this->passedArgs = array_merge($this->params['pass'], $this->params['named']);
     if (!empty($this->params['data'])) {
         $this->data =& $this->params['data'];
     } else {
         $this->data = null;
     }
     if (!empty($this->params['bare'])) {
         $this->autoLayout = false;
     }
     if (isset($this->_testCase) && method_exists($this->_testCase, 'startController')) {
         $this->_testCase->startController($this, $this->params);
     }
     unset($_SESSION);
     $this->constructClasses();
     $this->startupProcess();
 }
コード例 #2
0
 /**
  * testGetUrl method
  *
  * @return void
  * @access public
  */
 function testGetUrl()
 {
     $Dispatcher = new Dispatcher();
     $Dispatcher->base = '/app/webroot/index.php';
     $uri = '/app/webroot/index.php/posts/add';
     $result = $Dispatcher->getUrl($uri);
     $expected = 'posts/add';
     $this->assertEqual($expected, $result);
     Configure::write('App.baseUrl', '/app/webroot/index.php');
     $uri = '/posts/add';
     $result = $Dispatcher->getUrl($uri);
     $expected = 'posts/add';
     $this->assertEqual($expected, $result);
     $_GET['url'] = array();
     Configure::write('App.base', '/control');
     $Dispatcher = new Dispatcher();
     $Dispatcher->baseUrl();
     $uri = '/control/students/browse';
     $result = $Dispatcher->getUrl($uri);
     $expected = 'students/browse';
     $this->assertEqual($expected, $result);
     $_GET['url'] = array();
     $Dispatcher = new Dispatcher();
     $Dispatcher->base = '';
     $uri = '/?/home';
     $result = $Dispatcher->getUrl($uri);
     $expected = '?/home';
     $this->assertEqual($expected, $result);
 }