setRequestInfo() public static method

Nested requests will create a stack of requests. You can remove requests using Router::popRequest(). This is done automatically when using Object::requestAction(). Will accept either a CakeRequest object or an array of arrays. Support for accepting arrays may be removed in the future.
public static setRequestInfo ( CakeRequest | array $request ) : void
$request CakeRequest | array Parameters and path information or a CakeRequest object.
return void
Esempio n. 1
0
 public function loadRouter($base = null)
 {
     if ($base === null) {
         $base = Configure::read('App.base');
     }
     if (!class_exists('Router')) {
         App::import('Core', 'Router');
     }
     Router::setRequestInfo(array(array(), array('base' => $base, 'webroot' => $base)));
     if (!defined('FULL_BASE_URL')) {
         $s = null;
         if (env('HTTPS')) {
             $s = 's';
         }
         $httpHost = env('HTTP_HOST');
         if (empty($httpHost)) {
             $httpHost = env('SERVER_NAME');
             if (empty($httpHost)) {
                 if (class_exists('Environment')) {
                     $httpHost = Environment::getHostName();
                 }
             }
         }
         if (!empty($httpHost)) {
             define('FULL_BASE_URL', 'http' . $s . '://' . $httpHost);
         }
     }
 }
Esempio n. 2
0
 /**
  * 指定されたURLに対応しRouterパース済のCakeRequestのインスタンスを返す
  *
  * @param string $url URL
  * @return CakeRequest
  */
 protected function _getRequest($url)
 {
     Router::reload();
     $request = new CakeRequest($url);
     // コンソールからのテストの場合、requestのパラメーターが想定外のものとなってしまうので調整
     if (isConsole()) {
         $baseUrl = Configure::read('App.baseUrl');
         if ($request->url === false) {
             $request->here = $baseUrl . '/';
         } elseif (preg_match('/^' . preg_quote($request->webroot, '/') . '/', $request->here)) {
             $request->here = $baseUrl . '/' . preg_replace('/^' . preg_quote($request->webroot, '/') . '/', '', $request->here);
         }
         if ($baseUrl) {
             if (preg_match('/^\\//', $baseUrl)) {
                 $request->base = $baseUrl;
             } else {
                 $request->base = '/' . $baseUrl;
             }
             $request->webroot = $baseUrl;
         } else {
             $request->base = '';
             $request->webroot = '/';
         }
     }
     Router::setRequestInfo($request);
     $params = Router::parse($request->url);
     $request->addParams($params);
     return $request;
 }
 /**
  * SetUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('Config.language', 'deu');
     Configure::delete('Passwordable');
     Configure::write('Passwordable.auth', 'AuthTest');
     $this->User = ClassRegistry::init('Tools.ToolsUser');
     if (isset($this->User->validate['pwd'])) {
         unset($this->User->validate['pwd']);
     }
     if (isset($this->User->validate['pwd_repeat'])) {
         unset($this->User->validate['pwd_repeat']);
     }
     if (isset($this->User->validate['pwd_current'])) {
         unset($this->User->validate['pwd_current']);
     }
     if (isset($this->User->order)) {
         unset($this->User->order);
     }
     $this->User->create();
     $data = ['id' => '5', 'name' => 'admin', 'password' => Security::hash('somepwd', null, true), 'role_id' => '1'];
     $this->User->set($data);
     $result = $this->User->save();
     $this->assertTrue((bool) $result);
     Router::setRequestInfo(new CakeRequest(null, false));
 }
Esempio n. 4
0
 public function testIs()
 {
     $result = Reveal::is('App.online');
     $expected = !in_array(gethostbyname('google.com'), array('google.com', false));
     $this->assertEqual($result, $expected);
     $result = Reveal::is('DebugKit.loaded');
     $expected = CakePlugin::loaded('DebugKit');
     $this->assertEqual($result, $expected);
     $result = Reveal::is(array('OR' => array('DebugKit.enabled', 'DebugKit.automated')));
     $expected = Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun');
     $this->assertEqual($result, $expected);
     $_GET['debug'] = 'true';
     $this->assertTrue(Reveal::is('DebugKit.requested'));
     $result = Reveal::is('DebugKit.loaded', array('OR' => array('DebugKit.enabled', array('AND' => array('DebugKit.automated', 'DebugKit.requested')))));
     $expected = CakePlugin::loaded('DebugKit') || Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun') && isset($_GET['debug']) && 'true' == $_GET['debug'];
     $this->assertEqual($result, $expected);
     $this->assertEqual(Reveal::is('DebugKit.running'), $expected);
     $request = new CakeRequest();
     Router::setRequestInfo($request->addParams(array('controller' => 'pages', 'action' => 'display', 'pass' => array('home'))));
     $result = Reveal::is('Page.front');
     $this->assertTrue($result);
     Router::reload();
     $request = new CakeRequest();
     Router::setRequestInfo($request->addParams(array('prefix' => 'admin', 'admin' => true)));
     $result = Reveal::is('Page.prefixed');
     $this->assertTrue($result);
     Router::reload();
     $request = new CakeRequest();
     Router::setRequestInfo($request->addParams(array('controller' => 'users', 'action' => 'login')));
     $result = Reveal::is('Page.login');
     $this->assertTrue($result);
     $this->assertTrue(Reveal::is('Page.test'));
 }
Esempio n. 5
0
 /**
  * construct method
  *
  */
 public function __construct($request, $response)
 {
     $request->addParams(Router::parse('/seo_test'));
     $request->here = '/seo_test';
     $request->webroot = '/';
     Router::setRequestInfo($request);
     parent::__construct($request, $response);
 }
 /**
  * test that assets only have one base path attached
  *
  * @return void
  */
 function testIncludeAssets()
 {
     Router::setRequestInfo(array(array('controller' => 'posts', 'action' => 'index', 'plugin' => null), array('base' => '/some/dir', 'webroot' => '/some/dir/', 'here' => '/some/dir/posts')));
     $this->Helper->Html->webroot = '/some/dir/';
     $this->Helper->script('one.js');
     $result = $this->Helper->includeAssets();
     $this->assertPattern('#"/some/dir/asset_compress#', $result, 'double dir set %s');
 }
 /**
  * setup create a request object to get out of router later.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), App::RESET);
     Router::reload();
     $request = new CakeRequest(null, false);
     $request->base = '';
     Router::setRequestInfo($request);
     Configure::write('debug', 2);
 }
 /**
  * setup create a request object to get out of router later.
  *
  * @return void
  */
 public function setUp()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), true);
     Router::reload();
     $request = new CakeRequest(null, false);
     $request->base = '';
     Router::setRequestInfo($request);
     $this->_debug = Configure::read('debug');
     $this->_error = Configure::read('Error');
     Configure::write('debug', 2);
 }
Esempio n. 9
0
 /**
  * setup create a request object to get out of router later.
  *
  * @return void
  */
 function setUp()
 {
     App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS)), true);
     Router::reload();
     $request = new CakeRequest(null, false);
     $request->base = '';
     Router::setRequestInfo($request);
     $this->_debug = Configure::read('debug');
     $this->_error = Configure::read('Error');
     Configure::write('debug', 2);
 }
Esempio n. 10
0
 /**
  * setup create a request object to get out of router later.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), App::RESET);
     Router::reload();
     $request = new CakeRequest(NULL, FALSE);
     $request->base = '';
     Router::setRequestInfo($request);
     Configure::write('debug', 2);
     CakeLog::disable('stdout');
     CakeLog::disable('stderr');
 }
Esempio n. 11
0
 /**
  * Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
  * to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
  *
  * Actions in CakePHP can be any public method on a controller, that is not declared in Controller.  If you
  * want controller methods to be public and in-accessible by URL, then prefix them with a `_`.
  * For example `public function _loadPosts() { }` would not be accessible via URL.  Private and protected methods
  * are also not accessible via URL.
  *
  * If no controller of given name can be found, invoke() will throw an exception.
  * If the controller is found, and the action is not found an exception will be thrown.
  *
  * @param CakeRequest $request Request object to dispatch.
  * @param CakeResponse $response Response object to put the results of the dispatch into.
  * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
  * @return boolean Success
  * @throws MissingControllerException When the controller is missing.
  */
 public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array())
 {
     if ($this->asset($request->url, $response) || $this->cached($request->here())) {
         return;
     }
     Router::setRequestInfo($request);
     $request = $this->parseParams($request, $additionalParams);
     $controller = $this->_getController($request, $response);
     if (!$controller instanceof Controller) {
         throw new MissingControllerException(array('class' => Inflector::camelize($request->params['controller']) . 'Controller', 'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin'])));
     }
     return $this->_invoke($controller, $request, $response);
 }
 function testSortLinks()
 {
     Router::reload();
     Router::parse('/');
     Router::setRequestInfo(array(array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())));
     $this->Paginator->options(array('url' => array('param')));
     $result = $this->Paginator->sort('title');
     $this->assertPattern('/\\/accounts\\/index\\/param\\/page:1\\/sort:title\\/direction:asc"\\s*>Title<\\/a>$/', $result);
     $result = $this->Paginator->sort('date');
     $this->assertPattern('/\\/accounts\\/index\\/param\\/page:1\\/sort:date\\/direction:desc"\\s*>Date<\\/a>$/', $result);
     $result = $this->Paginator->numbers(array('modulus' => '2', 'url' => array('controller' => 'projects', 'action' => 'sort'), 'update' => 'list'));
     $this->assertPattern('/\\/projects\\/sort\\/page:2/', $result);
     $this->assertPattern('/<script type="text\\/javascript">Event.observe/', $result);
 }
Esempio n. 13
0
 /**
  * setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->request = new CakeRequest('posts/index', false);
     Router::setRequestInfo($this->request);
     $this->Collection = new ComponentCollection();
     $this->Collection->load('Cookie');
     $this->Collection->load('Session');
     $this->auth = new CookieAuthenticate($this->Collection, array('fields' => array('username' => 'user', 'password' => 'password'), 'userModel' => 'MultiUser'));
     $password = Security::hash('password', null, true);
     $User = ClassRegistry::init('MultiUser');
     $User->updateAll(array('password' => $User->getDataSource()->value($password)));
     $this->response = $this->getMock('CakeResponse');
 }
Esempio n. 14
0
 /**
  * testGetUrl
  *
  * $param string $host ホスト名
  * $param string $ua ユーザーエージェント名
  * @param string $url 変換前URL
  * @param boolean $full フルURLで出力するかどうか
  * @param boolean $useSubDomain サブドメインを利用するかどうか
  * @param string $expects 期待するURL
  * @dataProvider getUrlDataProvider
  */
 public function testGetUrl($host, $ua, $url, $full, $useSubDomain, $expects)
 {
     $siteUrl = Configure::read('BcEnv.siteUrl');
     Configure::write('BcEnv.siteUrl', 'http://main.com');
     if ($ua) {
         $_SERVER['HTTP_USER_AGENT'] = $ua;
     }
     if ($host) {
         $_SERVER['HTTP_HOST'] = $host;
     }
     Router::setRequestInfo($this->_getRequest('/m/'));
     $result = $this->Content->getUrl($url, $full, $useSubDomain);
     $this->assertEquals($result, $expects);
     Configure::write('BcEnv.siteUrl', $siteUrl);
 }
Esempio n. 15
0
 /**
  * Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
  * to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
  *
  * Actions in CakePHP can be any public method on a controller, that is not declared in Controller.  If you
  * want controller methods to be public and in-accesible by URL, then prefix them with a `_`.  
  * For example `public function _loadPosts() { }` would not be accessible via URL.  Private and protected methods
  * are also not accessible via URL.
  *
  * If no controller of given name can be found, invoke() will throw an exception.
  * If the controller is found, and the action is not found an exception will be thrown.
  *
  * @param CakeRequest $request Request object to dispatch.
  * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
  * @return boolean Success
  * @throws MissingControllerException, MissingActionException, PrivateActionException if any of those error states
  *    are encountered.
  */
 public function dispatch(CakeRequest $request, $additionalParams = array())
 {
     if ($this->asset($request->url) || $this->cached($request->here)) {
         return;
     }
     $request = $this->parseParams($request, $additionalParams);
     Router::setRequestInfo($request);
     $controller = $this->_getController($request);
     if (!$controller instanceof Controller) {
         throw new MissingControllerException(array('controller' => Inflector::camelize($request->params['controller']) . 'Controller'));
     }
     if ($this->_isPrivateAction($request)) {
         throw new PrivateActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action']));
     }
     return $this->_invoke($controller, $request);
 }
 /**
  * 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();
 }
 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
  *
  * @param CakeEvent $event containing the request, response and additional params
  * @return void
  */
 public function parseParams($event)
 {
     $request = $event->data['request'];
     Router::setRequestInfo($request);
     $params = Router::parse($request->url);
     $request->addParams($params);
     if (!empty($event->data['additionalParams'])) {
         $request->addParams($event->data['additionalParams']);
     }
 }
Esempio n. 18
0
 /**
  * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set).
  *
  * If no controller of given name can be found, invoke() shows error messages in
  * the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
  * Actions).
  *
  * @param string $url URL information to work on
  * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
  * @return boolean Success
  * @access public
  */
 function dispatch($url = null, $additionalParams = array())
 {
     if ($this->base === false) {
         $this->base = $this->baseUrl();
     }
     if (is_array($url)) {
         $url = $this->__extractParams($url, $additionalParams);
     } else {
         if ($url) {
             $_GET['url'] = $url;
         }
         $url = $this->getUrl();
         $this->params = array_merge($this->parseParams($url), $additionalParams);
     }
     $this->here = $this->base . '/' . $url;
     if ($this->cached($url)) {
         $this->_stop();
     }
     $controller =& $this->__getController();
     if (!is_object($controller)) {
         Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
         return $this->cakeError('missingController', array(array('className' => Inflector::camelize($this->params['controller']) . 'Controller', 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base)));
     }
     $privateAction = $this->params['action'][0] === '_';
     $prefixes = Router::prefixes();
     if (!empty($prefixes)) {
         if (isset($this->params['prefix'])) {
             $this->params['action'] = $this->params['prefix'] . '_' . $this->params['action'];
         } elseif (strpos($this->params['action'], '_') > 0) {
             list($prefix, $action) = explode('_', $this->params['action']);
             $privateAction = in_array($prefix, $prefixes);
         }
     }
     Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
     if ($privateAction) {
         return $this->cakeError('privateAction', array(array('className' => Inflector::camelize($this->params['controller'] . "Controller"), 'action' => $this->params['action'], 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base)));
     }
     $controller->base = $this->base;
     $controller->here = $this->here;
     $controller->webroot = $this->webroot;
     $controller->plugin = $this->plugin;
     $controller->params =& $this->params;
     $controller->action =& $this->params['action'];
     $controller->passedArgs = array_merge($this->params['pass'], $this->params['named']);
     if (!empty($this->params['data'])) {
         $controller->data =& $this->params['data'];
     } else {
         $controller->data = null;
     }
     if (array_key_exists('return', $this->params) && $this->params['return'] == 1) {
         $controller->autoRender = false;
     }
     if (!empty($this->params['bare'])) {
         $controller->autoLayout = false;
     }
     if (array_key_exists('layout', $this->params)) {
         if (empty($this->params['layout'])) {
             $controller->autoLayout = false;
         } else {
             $controller->layout = $this->params['layout'];
         }
     }
     if (isset($this->params['viewPath'])) {
         $controller->viewPath = $this->params['viewPath'];
     }
     return $this->_invoke($controller, $this->params);
 }
Esempio n. 19
0
 /**
  * test create() with automatic url generation
  *
  * @return void
  */
 public function testCreateAutoUrl()
 {
     Router::setRequestInfo(array(array(), array('base' => '/base_url')));
     $this->Form->request->here = '/base_url/contacts/add/Contact:1';
     $this->Form->request->base = '/base_url';
     $result = $this->Form->create('Contact');
     $expected = array('form' => array('id' => 'ContactAddForm', 'method' => 'post', 'action' => '/base_url/contacts/add/Contact:1', 'accept-charset' => 'utf-8'), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div');
     $this->assertTags($result, $expected);
     $this->Form->request['action'] = 'delete';
     $this->Form->request->here = '/base_url/contacts/delete/10/User:42';
     $this->Form->request->base = '/base_url';
     $result = $this->Form->create('Contact');
     $expected = array('form' => array('id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/base_url/contacts/delete/10/User:42', 'accept-charset' => 'utf-8'), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div');
     $this->assertTags($result, $expected);
 }
Esempio n. 20
0
 /**
  * testLoginActionRedirect method
  *
  * @return void
  */
 public function testLoginActionRedirect()
 {
     $admin = Configure::read('Routing.prefixes');
     Configure::write('Routing.prefixes', array('admin'));
     Router::reload();
     require CAKE . 'Config' . DS . 'routes.php';
     $url = '/admin/auth_test/login';
     $this->Auth->request->addParams(Router::parse($url));
     $this->Auth->request->url = ltrim($url, '/');
     Router::setRequestInfo(array(array('pass' => array(), 'action' => 'admin_login', 'plugin' => null, 'controller' => 'auth_test', 'admin' => true), array('base' => null, 'here' => $url, 'webroot' => '/', 'passedArgs' => array())));
     $this->Auth->initialize($this->Controller);
     $this->Auth->loginAction = array('admin' => true, 'controller' => 'auth_test', 'action' => 'login');
     $this->Auth->startup($this->Controller);
     $this->assertNull($this->Controller->testUrl);
     Configure::write('Routing.prefixes', $admin);
 }
Esempio n. 21
0
 /**
  * Test that Router::url() uses the first request
  */
 public function testUrlWithRequestAction()
 {
     $firstRequest = new CakeRequest('/posts/index');
     $firstRequest->addParams(array('plugin' => null, 'controller' => 'posts', 'action' => 'index'))->addPaths(array('base' => ''));
     $secondRequest = new CakeRequest('/posts/index');
     $secondRequest->addParams(array('requested' => 1, 'plugin' => null, 'controller' => 'comments', 'action' => 'listing'))->addPaths(array('base' => ''));
     Router::setRequestInfo($firstRequest);
     Router::setRequestInfo($secondRequest);
     $result = Router::url(array('base' => false));
     $this->assertEquals('/comments/listing', $result, 'with second requests, the last should win.');
     Router::popRequest();
     $result = Router::url(array('base' => false));
     $this->assertEquals('/posts', $result, 'with second requests, the last should win.');
 }
Esempio n. 22
0
 /**
  * test that the proper names and variable values are set by Scaffold
  *
  * @return void
  **/
 function testEditScaffoldWithScaffoldFields()
 {
     $this->Controller = new ScaffoldMockControllerWithFields();
     $this->Controller->action = 'edit';
     $this->Controller->here = '/scaffold_mock';
     $this->Controller->webroot = '/';
     $params = array('plugin' => null, 'pass' => array(1), 'form' => array(), 'named' => array(), 'url' => array('url' => 'scaffold_mock'), 'controller' => 'scaffold_mock', 'action' => 'edit');
     //set router.
     Router::reload();
     Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
     $this->Controller->params = $params;
     $this->Controller->controller = 'scaffold_mock';
     $this->Controller->base = '/';
     $this->Controller->constructClasses();
     ob_start();
     new Scaffold($this->Controller, $params);
     $result = ob_get_clean();
     $this->assertNoPattern('/textarea name="data\\[ScaffoldMock\\]\\[body\\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
 }
Esempio n. 23
0
 /**
  * test that the proper names and variable values are set by Scaffold
  *
  * @return void
  */
 public function testEditScaffoldWithScaffoldFields()
 {
     $request = new CakeRequest(null, false);
     $this->Controller = new ScaffoldMockControllerWithFields($request);
     $this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
     $params = array('plugin' => null, 'pass' => array(1), 'form' => array(), 'named' => array(), 'url' => array('url' => 'scaffold_mock/edit'), 'controller' => 'scaffold_mock', 'action' => 'edit');
     $this->Controller->request->base = '';
     $this->Controller->request->webroot = '/';
     $this->Controller->request->here = '/scaffold_mock/edit';
     $this->Controller->request->addParams($params);
     //set router.
     Router::reload();
     Router::setRequestInfo($this->Controller->request);
     $this->Controller->constructClasses();
     ob_start();
     new Scaffold($this->Controller, $this->Controller->request);
     $this->Controller->response->send();
     $result = ob_get_clean();
     $this->assertNotRegExp('/textarea name="data\\[ScaffoldMock\\]\\[body\\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
 }
 /**
  * test that the returned URL doesn't contain the base URL.
  *
  * @see https://cakephp.lighthouseapp.com/projects/42648/tickets/3922-authcomponentredirecturl-prepends-appbaseurl
  *
  * @return void This test method doesn't return anything.
  */
 public function testRedirectUrlWithBaseSet()
 {
     $App = Configure::read('App');
     Configure::write('App', array('dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'base' => false, 'baseUrl' => '/cake/index.php'));
     $url = '/users/login';
     $this->Auth->request = $this->Controller->request = new CakeRequest($url);
     $this->Auth->request->addParams(Router::parse($url));
     $this->Auth->request->url = Router::normalize($url);
     Router::setRequestInfo($this->Auth->request);
     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
     $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
     $result = $this->Auth->redirectUrl();
     $this->assertEquals('/users/home', $result);
     $this->assertFalse($this->Auth->Session->check('Auth.redirect'));
     Configure::write('App', $App);
     Router::reload();
 }
Esempio n. 25
0
 /**
  * Test Admin Index Scaffolding.
  *
  * @return void
  */
 public function testMultiplePrefixScaffold()
 {
     $_backAdmin = Configure::read('Routing.prefixes');
     Configure::write('Routing.prefixes', array('admin', 'member'));
     $params = array('plugin' => null, 'pass' => array(), 'form' => array(), 'named' => array(), 'prefix' => 'member', 'url' => array('url' => 'member/scaffold_mock'), 'controller' => 'scaffold_mock', 'action' => 'member_index', 'member' => 1);
     $this->Controller->request->base = '';
     $this->Controller->request->webroot = '/';
     $this->Controller->request->here = '/member/scaffold_mock';
     $this->Controller->request->addParams($params);
     //reset, and set router.
     Router::reload();
     Router::setRequestInfo($this->Controller->request);
     $this->Controller->scaffold = 'member';
     $this->Controller->constructClasses();
     ob_start();
     new Scaffold($this->Controller, $this->Controller->request);
     $this->Controller->response->send();
     $result = ob_get_clean();
     $this->assertRegExp('/<h2>Scaffold Mock<\\/h2>/', $result);
     $this->assertRegExp('/<table cellpadding="0" cellspacing="0">/', $result);
     $this->assertRegExp('/<li><a href="\\/member\\/scaffold_mock\\/add">New Scaffold Mock<\\/a><\\/li>/', $result);
     Configure::write('Routing.prefixes', $_backAdmin);
 }
Esempio n. 26
0
 /**
  * testLoginActionRedirect method
  *
  * @access public
  * @return void
  */
 function testLoginActionRedirect()
 {
     $admin = Configure::read('Routing.admin');
     Configure::write('Routing.admin', 'admin');
     Router::reload();
     $url = '/admin/auth_test/login';
     $this->Controller->params = Router::parse($url);
     $this->Controller->params['url']['url'] = ltrim($url, '/');
     Router::setRequestInfo(array(array('pass' => array(), 'action' => 'admin_login', 'plugin' => null, 'controller' => 'auth_test', 'admin' => true, 'url' => array('url' => $this->Controller->params['url']['url'])), array('base' => null, 'here' => $url, 'webroot' => '/', 'passedArgs' => array())));
     $this->Controller->Auth->initialize($this->Controller);
     $this->Controller->Auth->loginAction = array('admin' => true, 'controller' => 'auth_test', 'action' => 'login');
     $this->Controller->Auth->userModel = 'AuthUser';
     $this->Controller->Auth->startup($this->Controller);
     $this->assertNull($this->Controller->testUrl);
     Configure::write('Routing.admin', $admin);
 }
 /**
  * testNextLinkUsingDotNotation method
  *
  * @return void
  */
 public function testNextLinkUsingDotNotation()
 {
     Router::reload();
     Router::parse('/');
     Router::setRequestInfo(array(array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')), array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())));
     $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
     $this->Paginator->request->params['paging']['Article']['page'] = 1;
     $test = array('url' => array('page' => '1', 'sort' => 'Article.title', 'direction' => 'asc'));
     $this->Paginator->options($test);
     $result = $this->Paginator->next('Next');
     $expected = array('span' => array('class' => 'next'), 'a' => array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc', 'rel' => 'next'), 'Next', '/a', '/span');
     $this->assertTags($result, $expected);
 }
Esempio n. 28
0
 /**
  * test that error400 doesn't expose XSS
  *
  * @return void
  */
 public function testError400NoInjection()
 {
     Router::reload();
     $request = new CakeRequest('pages/<span id=333>pink</span></id><script>document.body.style.background = t=document.getElementById(333).innerHTML;window.alert(t);</script>', false);
     Router::setRequestInfo($request);
     $exception = new NotFoundException('Custom message');
     $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));
     ob_start();
     $ExceptionRenderer->render();
     $result = ob_get_clean();
     $this->assertNoPattern('#<script>document#', $result);
     $this->assertNoPattern('#alert\\(t\\);</script>#', $result);
 }
Esempio n. 29
0
 /**
  * testGetParams
  *
  * @return void
  * @access public
  */
 function testGetParams()
 {
     $paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot');
     $params = array('param1' => '1', 'param2' => '2');
     Router::setRequestInfo(array($params, $paths));
     $expected = array('plugin' => false, 'controller' => false, 'action' => false, 'param1' => '1', 'param2' => '2');
     $this->assertEqual(Router::getparams(), $expected);
     $this->assertEqual(Router::getparam('controller'), false);
     $this->assertEqual(Router::getparam('param1'), '1');
     $this->assertEqual(Router::getparam('param2'), '2');
     Router::reload();
     $params = array('controller' => 'pages', 'action' => 'display');
     Router::setRequestInfo(array($params, $paths));
     $expected = array('plugin' => false, 'controller' => 'pages', 'action' => 'display');
     $this->assertEqual(Router::getparams(), $expected);
     $this->assertEqual(Router::getparams(true), $expected);
 }
 /**
  * test that the beforeRedirect callback properly converts
  * array urls into their correct string ones, and adds base => false so
  * the correct urls are generated.
  *
  * @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
  * @return void
  */
 function testBeforeRedirectCallbackWithArrayUrl()
 {
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
     Router::setRequestInfo(array(array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')), array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')));
     $RequestHandler =& new NoStopRequestHandler();
     ob_start();
     $RequestHandler->beforeRedirect($this->Controller, array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second'));
     $result = ob_get_clean();
     $this->assertEqual($result, 'one: first two: second');
 }