2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DispatcherTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Dispatcher', 'Routing');
|
2009-03-21 23:55:39 +00:00
|
|
|
|
2010-12-09 05:55:24 +00:00
|
|
|
if (!class_exists('AppController', false)) {
|
2011-04-17 10:35:21 +00:00
|
|
|
require_once CAKE . 'Controller' . DS . 'AppController.php';
|
2009-03-21 23:55:39 +00:00
|
|
|
} elseif (!defined('APP_CONTROLLER_EXISTS')){
|
|
|
|
define('APP_CONTROLLER_EXISTS', true);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-19 04:24:02 +00:00
|
|
|
/**
|
|
|
|
* A testing stub that doesn't send headers.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2010-09-19 04:24:02 +00:00
|
|
|
*/
|
|
|
|
class DispatcherMockCakeResponse extends CakeResponse {
|
|
|
|
protected function _sendHeader($name, $value = null) {
|
|
|
|
return $name . ' ' . $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestDispatcher class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestDispatcher extends Dispatcher {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* invoke method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
|
|
|
* @param mixed $controller
|
2010-12-13 02:02:42 +00:00
|
|
|
* @param mixed $request
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-07-03 18:16:27 +00:00
|
|
|
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
|
2011-07-09 17:56:51 +00:00
|
|
|
$result = parent::_invoke($controller, $request, $response);
|
2008-05-30 11:40:08 +00:00
|
|
|
return $controller;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* MyPluginAppController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class MyPluginAppController extends AppController {
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* MyPluginController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class MyPluginController extends MyPluginAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'MyPlugin'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'MyPlugin';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* add method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function add() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* admin_add method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
|
|
|
* @param mixed $id
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_add($id = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* SomePagesController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class SomePagesController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'SomePages'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SomePages';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* display method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
|
|
|
* @param mixed $page
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function display($page = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $page;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-07-09 18:21:32 +00:00
|
|
|
/**
|
|
|
|
* Test method for returning responses.
|
|
|
|
*
|
|
|
|
* @return CakeResponse
|
|
|
|
*/
|
|
|
|
public function responseGenerator() {
|
|
|
|
return new CakeResponse(array('body' => 'new response'));
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* OtherPagesController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class OtherPagesController extends MyPluginAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'OtherPages'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'OtherPages';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* display method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
|
|
|
* @param mixed $page
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function display($page = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $page;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestDispatchPagesController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestDispatchPagesController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'TestDispatchPages'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestDispatchPages';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* admin_index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-26 18:33:00 +00:00
|
|
|
/**
|
|
|
|
* camelCased method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function camelCased() {
|
2008-08-26 18:33:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ArticlesTestAppController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ArticlesTestAppController extends AppController {
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ArticlesTestController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ArticlesTestController extends ArticlesTestAppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ArticlesTest'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ArticlesTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* admin_index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-04-04 03:32:14 +00:00
|
|
|
/**
|
|
|
|
* fake index method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function index() {
|
2010-04-04 03:32:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* SomePostsController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class SomePostsController extends AppController {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'SomePosts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'SomePosts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* autoRender property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $autoRender = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeFilter method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function beforeFilter() {
|
2008-07-26 20:09:20 +00:00
|
|
|
if ($this->params['action'] == 'index') {
|
|
|
|
$this->params['action'] = 'view';
|
|
|
|
} else {
|
|
|
|
$this->params['action'] = 'change';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->params['pass'] = array('changed');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-26 20:09:20 +00:00
|
|
|
/**
|
|
|
|
* change method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function change() {
|
2008-07-26 20:09:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestCachedPagesController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-09-20 01:26:02 +00:00
|
|
|
class TestCachedPagesController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'TestCachedPages'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestCachedPages';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* helpers property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-09-20 01:26:02 +00:00
|
|
|
public $helpers = array('Cache', 'Html');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cacheAction property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cacheAction = array(
|
2010-01-04 04:51:31 +00:00
|
|
|
'index' => '+2 sec',
|
|
|
|
'test_nocache_tags' => '+2 sec',
|
|
|
|
'view' => '+2 sec'
|
2008-07-30 21:14:22 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-19 04:24:02 +00:00
|
|
|
/**
|
|
|
|
* Mock out the reponse object so it doesn't send headers.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_responseClass = 'DispatcherMockCakeResponse';
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* viewPath property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2011-05-16 00:39:38 +00:00
|
|
|
public $viewPath = 'Posts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->render();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* test_nocache_tags method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function test_nocache_tags() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->render();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 21:14:22 +00:00
|
|
|
/**
|
|
|
|
* view method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function view($id = null) {
|
2008-07-30 21:14:22 +00:00
|
|
|
$this->render('index');
|
|
|
|
}
|
2009-12-13 17:39:39 +00:00
|
|
|
/**
|
|
|
|
* test cached forms / tests view object being registered
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function cache_form() {
|
2009-12-13 17:39:39 +00:00
|
|
|
$this->cacheAction = 10;
|
|
|
|
$this->helpers[] = 'Form';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TimesheetsController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-09-20 01:26:02 +00:00
|
|
|
class TimesheetsController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'Timesheets'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Timesheets';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DispatcherTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Routing
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class DispatcherTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-09 04:28:01 +00:00
|
|
|
public function setUp() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_get = $_GET;
|
|
|
|
$_GET = array();
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->_post = $_POST;
|
|
|
|
$this->_files = $_FILES;
|
|
|
|
$this->_server = $_SERVER;
|
|
|
|
|
|
|
|
$this->_app = Configure::read('App');
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('App.base', false);
|
|
|
|
Configure::write('App.baseUrl', false);
|
|
|
|
Configure::write('App.dir', 'app');
|
|
|
|
Configure::write('App.webroot', 'webroot');
|
2009-03-21 23:55:39 +00:00
|
|
|
|
|
|
|
$this->_cache = Configure::read('Cache');
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('Cache.disable', true);
|
2009-03-21 23:55:39 +00:00
|
|
|
|
|
|
|
$this->_debug = Configure::read('debug');
|
2009-06-03 16:23:35 +00:00
|
|
|
|
2011-03-12 04:59:44 +00:00
|
|
|
App::build();
|
2010-09-19 17:47:31 +00:00
|
|
|
App::objects('plugin', null, false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-09 04:28:01 +00:00
|
|
|
public function tearDown() {
|
2009-03-18 17:55:58 +00:00
|
|
|
$_GET = $this->_get;
|
2009-03-21 23:55:39 +00:00
|
|
|
$_POST = $this->_post;
|
|
|
|
$_FILES = $this->_files;
|
|
|
|
$_SERVER = $this->_server;
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2011-05-09 04:31:00 +00:00
|
|
|
CakePlugin::unload();
|
2009-03-21 23:55:39 +00:00
|
|
|
Configure::write('App', $this->_app);
|
|
|
|
Configure::write('Cache', $this->_cache);
|
|
|
|
Configure::write('debug', $this->_debug);
|
2009-03-18 17:55:58 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParamsWithoutZerosAndEmptyPost method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParamsWithoutZerosAndEmptyPost() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2010-05-01 14:48:30 +00:00
|
|
|
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/params1/params2/params3"));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical($test['controller'], 'testcontroller');
|
|
|
|
$this->assertIdentical($test['action'], 'testaction');
|
|
|
|
$this->assertIdentical($test['pass'][0], 'params1');
|
|
|
|
$this->assertIdentical($test['pass'][1], 'params2');
|
|
|
|
$this->assertIdentical($test['pass'][2], 'params3');
|
|
|
|
$this->assertFalse(!empty($test['form']));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParamsReturnsPostedData method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParamsReturnsPostedData() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_POST['testdata'] = "My Posted Content";
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-05-01 14:48:30 +00:00
|
|
|
|
|
|
|
$test = $Dispatcher->parseParams(new CakeRequest("/"));
|
2011-04-30 18:12:51 +00:00
|
|
|
$this->assertEquals($test['data']['testdata'], "My Posted Content");
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParamsWithSingleZero method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParamsWithSingleZero() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-05-01 14:48:30 +00:00
|
|
|
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/1/0/23"));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical($test['controller'], 'testcontroller');
|
|
|
|
$this->assertIdentical($test['action'], 'testaction');
|
|
|
|
$this->assertIdentical($test['pass'][0], '1');
|
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
|
|
|
|
$this->assertIdentical($test['pass'][2], '23');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParamsWithManySingleZeros method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParamsWithManySingleZeros() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-05-01 14:48:30 +00:00
|
|
|
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/0/0/0/0/0/0"));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]);
|
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
|
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
|
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][3]);
|
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][4]);
|
|
|
|
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][5]);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParamsWithManyZerosInEachSectionOfUrl method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParamsWithManyZerosInEachSectionOfUrl() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-05-01 14:48:30 +00:00
|
|
|
$request = new CakeRequest("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
|
|
|
|
$test = $Dispatcher->parseParams($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
|
|
|
|
$this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
|
|
|
|
$this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
|
|
|
|
$this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][3]);
|
|
|
|
$this->assertPattern('/\\A(?:000000)\\z/', $test['pass'][4]);
|
|
|
|
$this->assertPattern('/\\A(?:0000000)\\z/', $test['pass'][5]);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2010-05-01 14:48:30 +00:00
|
|
|
$request = new CakeRequest("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
|
|
|
|
$test = $Dispatcher->parseParams($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
|
|
|
|
$this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
|
|
|
|
$this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
|
|
|
|
$this->assertPattern('/\\A(?:000002)\\z/', $test['pass'][3]);
|
|
|
|
$this->assertPattern('/\\A(?:000030)\\z/', $test['pass'][4]);
|
|
|
|
$this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testQueryStringOnRoot method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testQueryStringOnRoot() {
|
2008-12-17 16:11:44 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
|
|
|
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
2011-07-17 03:42:46 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2008-12-17 16:11:44 +00:00
|
|
|
|
2008-06-20 20:17:23 +00:00
|
|
|
$_GET = array('coffee' => 'life', 'sleep' => 'sissies');
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-05-01 15:07:32 +00:00
|
|
|
$uri = new CakeRequest('posts/home/?coffee=life&sleep=sissies');
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Dispatcher->parseParams($uri);
|
2008-07-05 12:37:18 +00:00
|
|
|
$this->assertPattern('/posts/', $result['controller']);
|
|
|
|
$this->assertPattern('/home/', $result['action']);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(isset($result['url']['sleep']));
|
|
|
|
$this->assertTrue(isset($result['url']['coffee']));
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
2010-05-01 15:07:32 +00:00
|
|
|
$uri = new CakeRequest('/?coffee=life&sleep=sissy');
|
2010-06-29 03:41:48 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Dispatcher->parseParams($uri);
|
2008-07-05 12:37:18 +00:00
|
|
|
$this->assertPattern('/pages/', $result['controller']);
|
|
|
|
$this->assertPattern('/display/', $result['action']);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(isset($result['url']['sleep']));
|
|
|
|
$this->assertTrue(isset($result['url']['coffee']));
|
|
|
|
$this->assertEqual($result['url']['coffee'], 'life');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingController method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2011-07-03 18:34:33 +00:00
|
|
|
* @expectedException MissingControllerException
|
|
|
|
* @expectedExceptionMessage Controller class SomeControllerController could not be found.
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testMissingController() {
|
2011-07-17 03:42:46 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
|
|
|
|
2011-07-03 18:34:33 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
|
|
|
$url = new CakeRequest('some_controller/home/param:value/param2:value2');
|
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDispatch method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-08-16 03:09:02 +00:00
|
|
|
public function testDispatchBasic() {
|
2010-06-09 04:28:01 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
|
2010-06-09 04:28:01 +00:00
|
|
|
));
|
|
|
|
$Dispatcher = new TestDispatcher();
|
2010-08-16 03:09:02 +00:00
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('pages/home/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = 'Pages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
|
|
|
$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
|
|
|
|
$this->assertIdentical($expected, $controller->passedArgs);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl','/pages/index.php');
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('pages/home');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = 'Pages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('pages/home/');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2009-12-17 15:16:47 +00:00
|
|
|
$this->assertNull($controller->plugin);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = 'Pages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
|
|
|
unset($Dispatcher);
|
2008-07-26 20:09:20 +00:00
|
|
|
|
2011-07-17 03:42:46 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2010-05-02 03:19:47 +00:00
|
|
|
Configure::write('App.baseUrl', '/timesheets/index.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('timesheets');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = 'Timesheets';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('timesheets/');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->assertEqual('Timesheets', $controller->name);
|
2010-11-14 05:29:56 +00:00
|
|
|
$this->assertEqual('/timesheets/index.php', $url->base);
|
2008-08-26 18:33:00 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('test_dispatch_pages/camelCased');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-08-26 18:33:00 +00:00
|
|
|
$this->assertEqual('TestDispatchPages', $controller->name);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('test_dispatch_pages/camelCased/something. .');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2010-04-24 17:42:19 +00:00
|
|
|
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-07-09 18:21:32 +00:00
|
|
|
/**
|
|
|
|
* Test that Dispatcher handles actions that return response objects.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDispatchActionReturnsResponse() {
|
2011-07-17 03:42:46 +00:00
|
|
|
Router::connect('/:controller/:action');
|
2011-07-09 18:21:32 +00:00
|
|
|
$Dispatcher = new Dispatcher();
|
|
|
|
$request = new CakeRequest('some_pages/responseGenerator');
|
|
|
|
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$Dispatcher->dispatch($request, $response);
|
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$this->assertEquals('new response', $result);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAdminDispatch method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAdminDispatch() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_POST = array();
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2009-12-09 04:52:02 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('admin/test_dispatch_pages/index/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-04 03:37:31 +00:00
|
|
|
$this->assertEqual($controller->name, 'TestDispatchPages');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-04 03:37:31 +00:00
|
|
|
$this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($controller->params['admin']);
|
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
|
|
|
|
$this->assertIdentical($expected, $controller->here);
|
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
$this->assertIdentical($expected, $controller->base);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPluginDispatch method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testPluginDispatch() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_POST = array();
|
|
|
|
|
|
|
|
Router::reload();
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2010-04-04 03:32:14 +00:00
|
|
|
Router::connect(
|
2011-04-17 10:35:21 +00:00
|
|
|
'/my_plugin/:controller/*',
|
2010-04-04 03:32:14 +00:00
|
|
|
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$result = $Dispatcher->parseParams($url);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'pass' => array('home'),
|
|
|
|
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
|
2011-04-30 18:12:51 +00:00
|
|
|
'controller'=> 'some_pages', 'action'=> 'display'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2010-05-02 03:19:47 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
$this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
2010-04-04 03:37:31 +00:00
|
|
|
$this->assertIdentical($controller->name, 'SomePages');
|
|
|
|
$this->assertIdentical($controller->params['controller'], 'some_pages');
|
|
|
|
$this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param'=>'value', 'param2'=>'value2'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAutomaticPluginDispatch method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAutomaticPluginDispatch() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_POST = array();
|
2011-02-21 02:52:20 +00:00
|
|
|
$_SERVER['SCRIPT_NAME'] = '/cake/repo/branches/1.2.x.x/index.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2010-04-04 03:32:14 +00:00
|
|
|
Router::connect(
|
|
|
|
'/my_plugin/:controller/:action/*',
|
|
|
|
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('my_plugin/other_pages/index/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
2010-04-04 03:37:31 +00:00
|
|
|
$this->assertIdentical($controller->name, 'OtherPages');
|
|
|
|
$this->assertIdentical($controller->action, 'index');
|
|
|
|
$this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertIdentical($expected, $url->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x';
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertIdentical($expected, $url->base);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAutomaticPluginControllerDispatch method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAutomaticPluginControllerDispatch() {
|
2010-04-04 03:32:14 +00:00
|
|
|
$plugins = App::objects('plugin');
|
|
|
|
$plugins[] = 'MyPlugin';
|
|
|
|
$plugins[] = 'ArticlesTest';
|
|
|
|
|
2011-05-09 04:31:00 +00:00
|
|
|
CakePlugin::load('MyPlugin', array('path' => '/fake/path'));
|
2010-04-04 03:32:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('my_plugin/my_plugin/add/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
2010-01-15 21:18:19 +00:00
|
|
|
$this->assertIdentical($controller->name, 'MyPlugin');
|
|
|
|
$this->assertIdentical($controller->action, 'add');
|
|
|
|
$this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
|
2009-02-13 19:39:52 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:42:46 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2009-02-13 19:39:52 +00:00
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-04-04 03:32:14 +00:00
|
|
|
// Simulates the Route for a real plugin, installed in APP/plugins
|
2009-02-13 19:39:52 +00:00
|
|
|
Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
|
|
|
|
|
|
|
|
$plugin = 'MyPlugin';
|
|
|
|
$pluginUrl = Inflector::underscore($plugin);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest($pluginUrl);
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
2010-04-03 20:29:36 +00:00
|
|
|
$this->assertIdentical($controller->name, 'MyPlugin');
|
|
|
|
$this->assertIdentical($controller->action, 'index');
|
2009-02-13 19:39:52 +00:00
|
|
|
|
|
|
|
$expected = $pluginUrl;
|
|
|
|
$this->assertEqual($controller->params['controller'], $expected);
|
|
|
|
|
|
|
|
|
2009-12-09 04:52:02 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Router::reload();
|
2011-07-17 03:42:46 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('admin/my_plugin/my_plugin/add/5/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-04 03:32:14 +00:00
|
|
|
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
|
|
|
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
|
|
|
$this->assertEqual($controller->params['action'], 'admin_add');
|
|
|
|
$this->assertEqual($controller->params['pass'], array(5));
|
|
|
|
$this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2'));
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
2010-04-03 20:29:36 +00:00
|
|
|
$this->assertIdentical($controller->name, 'MyPlugin');
|
|
|
|
$this->assertIdentical($controller->action, 'admin_add');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2');
|
|
|
|
$this->assertEqual($controller->passedArgs, $expected);
|
|
|
|
|
2010-04-04 03:32:14 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2011-05-25 19:14:23 +00:00
|
|
|
CakePlugin::load('ArticlesTest', array('path' => '/fake/path'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2011-07-17 03:42:46 +00:00
|
|
|
require CAKE . 'Config' . DS . 'routes.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), $response, array('return' => 1));
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'ArticlesTest');
|
2010-04-03 20:29:36 +00:00
|
|
|
$this->assertIdentical($controller->name, 'ArticlesTest');
|
|
|
|
$this->assertIdentical($controller->action, 'admin_index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$expected = array(
|
2010-04-04 03:32:14 +00:00
|
|
|
'pass'=> array(),
|
|
|
|
'named' => array(),
|
|
|
|
'controller' => 'articles_test',
|
|
|
|
'plugin' => 'articles_test',
|
|
|
|
'action' => 'admin_index',
|
|
|
|
'prefix' => 'admin',
|
|
|
|
'admin' => true,
|
|
|
|
'return' => 1
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2010-05-02 03:19:47 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
2011-05-09 04:31:00 +00:00
|
|
|
$this->assertEqual($controller->request[$key], $expected[$key], 'Value mismatch ' . $key);
|
2010-05-02 03:19:47 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-02-13 19:34:25 +00:00
|
|
|
/**
|
|
|
|
* test Plugin dispatching without controller name and using
|
|
|
|
* plugin short form instead.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAutomaticPluginDispatchWithShortAccess() {
|
2011-05-09 04:31:00 +00:00
|
|
|
CakePlugin::load('MyPlugin', array('path' => '/fake/path'));
|
2009-02-13 19:34:25 +00:00
|
|
|
Router::reload();
|
|
|
|
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2009-02-13 19:34:25 +00:00
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('my_plugin/');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2009-12-16 14:41:34 +00:00
|
|
|
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
|
|
|
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
|
|
|
$this->assertEqual($controller->params['action'], 'index');
|
|
|
|
$this->assertFalse(isset($controller->params['pass'][0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test plugin shortcut urls with controllers that need to be loaded,
|
|
|
|
* the above test uses a controller that has already been included.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
|
2009-12-16 14:41:34 +00:00
|
|
|
$loaded = class_exists('TestPluginController', false);
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf($loaded, 'TestPluginController already loaded.');
|
|
|
|
|
2009-12-16 14:41:34 +00:00
|
|
|
Router::reload();
|
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-12-16 14:41:34 +00:00
|
|
|
), true);
|
2011-05-09 04:31:00 +00:00
|
|
|
CakePlugin::loadAll();
|
2010-01-15 21:18:19 +00:00
|
|
|
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2009-12-16 14:41:34 +00:00
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('test_plugin/');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2009-12-16 14:41:34 +00:00
|
|
|
$this->assertEqual($controller->params['controller'], 'test_plugin');
|
|
|
|
$this->assertEqual($controller->params['plugin'], 'test_plugin');
|
|
|
|
$this->assertEqual($controller->params['action'], 'index');
|
|
|
|
$this->assertFalse(isset($controller->params['pass'][0]));
|
2010-01-15 21:18:19 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('/test_plugin/tests/index');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2010-01-15 21:18:19 +00:00
|
|
|
$this->assertEqual($controller->params['controller'], 'tests');
|
|
|
|
$this->assertEqual($controller->params['plugin'], 'test_plugin');
|
|
|
|
$this->assertEqual($controller->params['action'], 'index');
|
|
|
|
$this->assertFalse(isset($controller->params['pass'][0]));
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('/test_plugin/tests/index/some_param');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2010-01-15 21:18:19 +00:00
|
|
|
$this->assertEqual($controller->params['controller'], 'tests');
|
|
|
|
$this->assertEqual($controller->params['plugin'], 'test_plugin');
|
|
|
|
$this->assertEqual($controller->params['action'], 'index');
|
|
|
|
$this->assertEqual($controller->params['pass'][0], 'some_param');
|
|
|
|
|
2009-12-16 14:41:34 +00:00
|
|
|
App::build();
|
2009-02-13 19:34:25 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testAutomaticPluginControllerMissingActionDispatch method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2011-07-03 18:34:33 +00:00
|
|
|
* @expectedException MissingActionException
|
|
|
|
* @expectedExceptionMessage Action MyPluginController::not_here() could not be found.
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAutomaticPluginControllerMissingActionDispatch() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('my_plugin/not_here/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2011-07-03 18:34:33 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
|
|
|
}
|
2009-02-17 23:32:15 +00:00
|
|
|
|
2011-07-03 18:34:33 +00:00
|
|
|
/**
|
|
|
|
* testAutomaticPluginControllerMissingActionDispatch method
|
|
|
|
*
|
|
|
|
* @expectedException MissingActionException
|
|
|
|
* @expectedExceptionMessage Action MyPluginController::param:value() could not be found.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testAutomaticPluginControllerIndexMissingAction() {
|
2009-02-17 23:32:15 +00:00
|
|
|
Router::reload();
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2009-02-17 23:32:15 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('my_plugin/param:value/param2:value2');
|
2011-07-03 18:34:33 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-24 02:19:05 +00:00
|
|
|
/**
|
2009-12-16 14:41:34 +00:00
|
|
|
* Test dispatching into the TestPlugin in the test_app
|
2008-07-24 02:19:05 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testTestPluginDispatch() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-06-11 16:13:16 +00:00
|
|
|
));
|
2011-05-09 04:31:00 +00:00
|
|
|
CakePlugin::loadAll();
|
2009-12-16 14:41:34 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('/test_plugin/tests/index');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
|
|
|
$result = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-07-24 02:19:05 +00:00
|
|
|
$this->assertTrue(class_exists('TestsController'));
|
|
|
|
$this->assertTrue(class_exists('TestPluginAppController'));
|
|
|
|
$this->assertTrue(class_exists('PluginsComponentComponent'));
|
2008-07-26 20:09:20 +00:00
|
|
|
|
2009-12-16 14:41:34 +00:00
|
|
|
$this->assertEqual($result->params['controller'], 'tests');
|
|
|
|
$this->assertEqual($result->params['plugin'], 'test_plugin');
|
|
|
|
$this->assertEqual($result->params['action'], 'index');
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2008-07-24 02:19:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testChangingParamsFromBeforeFilter method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testChangingParamsFromBeforeFilter() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse');
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('some_posts/index/param:value/param2:value2');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-08-28 03:40:22 +00:00
|
|
|
try {
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
2010-08-28 03:40:22 +00:00
|
|
|
$this->fail('No exception.');
|
|
|
|
} catch (MissingActionException $e) {
|
2010-09-08 04:11:11 +00:00
|
|
|
$this->assertEquals('Action SomePostsController::view() could not be found.', $e->getMessage());
|
2010-08-28 03:40:22 +00:00
|
|
|
}
|
2008-07-26 20:09:20 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$url = new CakeRequest('some_posts/something_else/param:value/param2:value2');
|
2011-07-03 18:16:27 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
2008-07-26 20:09:20 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = 'SomePosts';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
2008-07-26 20:09:20 +00:00
|
|
|
$expected = 'change';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $controller->action);
|
|
|
|
|
|
|
|
$expected = array('changed');
|
|
|
|
$this->assertIdentical($expected, $controller->params['pass']);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testStaticAssets method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAssets() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
|
|
|
'vendors' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor'. DS),
|
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
|
2009-06-11 16:13:16 +00:00
|
|
|
));
|
2011-05-09 04:31:00 +00:00
|
|
|
CakePlugin::loadAll();
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2010-08-28 03:40:22 +00:00
|
|
|
try {
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/../webroot/css/test_asset.css'), $response);
|
2010-08-28 03:40:22 +00:00
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (MissingControllerException $e) {
|
2010-09-08 04:11:11 +00:00
|
|
|
$this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage());
|
2010-08-28 03:40:22 +00:00
|
|
|
}
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-08-28 03:40:22 +00:00
|
|
|
try {
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs'), $response);
|
2010-08-28 03:40:22 +00:00
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (MissingControllerException $e) {
|
2010-09-08 04:11:11 +00:00
|
|
|
$this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage());
|
2010-08-28 03:40:22 +00:00
|
|
|
}
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf'), $response);
|
2009-11-25 17:06:28 +00:00
|
|
|
$result = ob_get_clean();
|
2010-05-02 03:19:47 +00:00
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
|
2009-11-25 17:06:28 +00:00
|
|
|
$this->assertEqual($file, $result);
|
|
|
|
$this->assertEqual('this is just a test to load swf file from the theme.', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf'), $response);
|
2009-11-25 17:06:28 +00:00
|
|
|
$result = ob_get_clean();
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
|
2009-11-25 17:06:28 +00:00
|
|
|
$this->assertEqual($file, $result);
|
|
|
|
$this->assertEqual('this is just a test to load pdf file from the theme.', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg'), $response);
|
2009-11-25 17:06:28 +00:00
|
|
|
$result = ob_get_clean();
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
|
2009-11-25 17:06:28 +00:00
|
|
|
$this->assertEqual($file, $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('theme/test_theme/css/test_asset.css', $response);
|
2009-11-25 17:06:28 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('this is the test asset css file', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-27 06:49:20 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('theme/test_theme/js/theme.js', $response);
|
2009-11-27 06:49:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('root theme js file', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-27 06:49:20 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('theme/test_theme/js/one/theme_one.js', $response);
|
2009-11-27 06:49:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('nested theme js file', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2010-02-17 04:18:49 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/root.js', $response);
|
2010-02-17 04:18:49 +00:00
|
|
|
$result = ob_get_clean();
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'root.js');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-02-17 04:18:49 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('test_plugin/flash/plugin_test.swf'), $response);
|
2009-11-25 17:06:28 +00:00
|
|
|
$result = ob_get_clean();
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'flash' . DS . 'plugin_test.swf');
|
2009-11-25 17:06:28 +00:00
|
|
|
$this->assertEqual($file, $result);
|
|
|
|
$this->assertEqual('this is just a test to load swf file from the plugin.', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->dispatch(new CakeRequest('test_plugin/pdfs/plugin_test.pdf'), $response);
|
2009-11-25 17:06:28 +00:00
|
|
|
$result = ob_get_clean();
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'pdfs' . DS . 'plugin_test.pdf');
|
2009-11-25 17:06:28 +00:00
|
|
|
$this->assertEqual($file, $result);
|
|
|
|
$this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-08-12 14:08:31 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/js/test_plugin/test.js', $response);
|
2009-08-12 14:08:31 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('alert("Test App");', $result);
|
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/js/test_plugin/test.js', $response);
|
2009-08-12 14:08:31 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('alert("Test App");', $result);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/css/test_plugin_asset.css', $response);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('this is the test plugin asset css file', $result);
|
|
|
|
|
2008-06-17 04:24:55 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/img/cake.icon.gif', $response);
|
2008-06-17 04:24:55 +00:00
|
|
|
$result = ob_get_clean();
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' .DS . 'webroot' . DS . 'img' . DS . 'cake.icon.gif');
|
2008-06-17 04:24:55 +00:00
|
|
|
$this->assertEqual($file, $result);
|
|
|
|
|
2009-11-03 18:14:38 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('plugin_js/js/plugin_js.js', $response);
|
2009-11-03 18:14:38 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "alert('win sauce');";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-27 06:49:20 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('plugin_js/js/one/plugin_one.js', $response);
|
2009-11-27 06:49:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "alert('plugin one nested js file');";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/css/unknown.extension', $response);
|
2009-12-16 23:32:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('Testing a file with unknown extension to mime mapping.', $result);
|
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$Dispatcher->asset('test_plugin/css/theme_one.htc', $response);
|
2009-12-16 23:32:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('htc file', $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-09-30 02:42:01 +00:00
|
|
|
if (php_sapi_name() == 'cli') {
|
|
|
|
while (ob_get_level()) {
|
|
|
|
ob_get_clean();
|
|
|
|
}
|
2010-09-26 01:50:28 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-02-07 20:19:47 +00:00
|
|
|
/**
|
|
|
|
* test that missing asset processors trigger a 404 with no response body.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMissingAssetProcessor404() {
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2010-02-07 20:19:47 +00:00
|
|
|
Configure::write('Asset.filter', array(
|
|
|
|
'js' => '',
|
|
|
|
'css' => null
|
|
|
|
));
|
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertTrue($Dispatcher->asset('ccss/cake.generic.css', $response));
|
2010-05-02 20:48:35 +00:00
|
|
|
$result = ob_get_clean();
|
2010-02-07 20:19:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 20:48:35 +00:00
|
|
|
/**
|
2011-04-17 10:35:21 +00:00
|
|
|
* test that asset filters work for theme and plugin assets
|
2010-05-02 20:48:35 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAssetFilterForThemeAndPlugins() {
|
2010-06-09 04:28:01 +00:00
|
|
|
$Dispatcher = new TestDispatcher();
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2010-05-02 20:48:35 +00:00
|
|
|
Configure::write('Asset.filter', array(
|
|
|
|
'js' => '',
|
|
|
|
'css' => ''
|
|
|
|
));
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css', $response));
|
2010-05-02 20:48:35 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js', $response));
|
2010-05-02 20:48:35 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css', $response));
|
2010-05-02 20:48:35 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js', $response));
|
2010-05-02 20:48:35 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css', $response));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2011-07-03 18:16:27 +00:00
|
|
|
$this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js', $response));
|
2010-05-02 20:48:35 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testFullPageCachingDispatch method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testFullPageCachingDispatch() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
Configure::write('debug', 2);
|
|
|
|
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
|
2011-07-17 03:42:46 +00:00
|
|
|
Router::connect('/:controller/:action/*');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
2009-06-11 16:13:16 +00:00
|
|
|
), true);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-09 04:28:01 +00:00
|
|
|
$dispatcher = new TestDispatcher();
|
2010-11-14 05:29:56 +00:00
|
|
|
$request = new CakeRequest('/');
|
2011-07-03 18:16:27 +00:00
|
|
|
$response = new CakeResponse();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$dispatcher->dispatch($request, $response);
|
2008-06-12 18:36:08 +00:00
|
|
|
$out = ob_get_clean();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-03-03 02:52:25 +00:00
|
|
|
$dispatcher->cached($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
$cached = ob_get_clean();
|
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
|
|
|
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-06-12 18:36:08 +00:00
|
|
|
|
2011-03-03 02:52:25 +00:00
|
|
|
$filename = $this->__cachePath($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$request = new CakeRequest('test_cached_pages/index');
|
2010-05-02 04:12:53 +00:00
|
|
|
$_POST = array(
|
|
|
|
'slasher' => "Up in your's grill \ '"
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$dispatcher->dispatch($request, $response);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
2011-03-03 02:52:25 +00:00
|
|
|
$dispatcher->cached($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
$cached = ob_get_clean();
|
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
|
|
|
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2011-03-03 02:52:25 +00:00
|
|
|
$filename = $this->__cachePath($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$request = new CakeRequest('TestCachedPages/index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$dispatcher->dispatch($request, $response);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
2011-03-03 02:52:25 +00:00
|
|
|
$dispatcher->cached($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
$cached = ob_get_clean();
|
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
|
|
|
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2011-03-03 02:52:25 +00:00
|
|
|
$filename = $this->__cachePath($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$request = new CakeRequest('TestCachedPages/test_nocache_tags');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$dispatcher->dispatch($request, $response);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
2011-03-03 02:52:25 +00:00
|
|
|
$dispatcher->cached($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
$cached = ob_get_clean();
|
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
|
|
|
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
2008-07-30 21:14:22 +00:00
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2011-03-03 02:52:25 +00:00
|
|
|
$filename = $this->__cachePath($request->here);
|
2008-07-30 21:14:22 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$request = new CakeRequest('test_cached_pages/view/param/param');
|
2008-07-30 21:14:22 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$dispatcher->dispatch($request, $response);
|
2008-07-30 21:14:22 +00:00
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
2011-03-03 02:52:25 +00:00
|
|
|
$dispatcher->cached($request->here);
|
2008-07-30 21:14:22 +00:00
|
|
|
$cached = ob_get_clean();
|
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
|
|
|
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2011-03-03 02:52:25 +00:00
|
|
|
$filename = $this->__cachePath($request->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2010-11-14 05:29:56 +00:00
|
|
|
$request = new CakeRequest('test_cached_pages/view/foo:bar/value:goo');
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-09-17 21:08:50 +00:00
|
|
|
ob_start();
|
2011-07-03 18:16:27 +00:00
|
|
|
$dispatcher->dispatch($request, $response);
|
2008-09-17 21:08:50 +00:00
|
|
|
$out = ob_get_clean();
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-09-17 21:08:50 +00:00
|
|
|
ob_start();
|
2011-03-03 02:52:25 +00:00
|
|
|
$dispatcher->cached($request->here);
|
2008-09-17 21:08:50 +00:00
|
|
|
$cached = ob_get_clean();
|
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
|
|
|
|
$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2011-03-03 02:52:25 +00:00
|
|
|
$filename = $this->__cachePath($request->here);
|
2008-09-17 21:08:50 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
2010-05-02 03:49:22 +00:00
|
|
|
|
2008-09-17 21:08:50 +00:00
|
|
|
unlink($filename);
|
2009-12-13 17:39:39 +00:00
|
|
|
}
|
2010-01-04 04:51:31 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testHttpMethodOverrides method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testHttpMethodOverrides() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::mapResources('Posts');
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
2010-06-09 04:28:01 +00:00
|
|
|
$dispatcher = new Dispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-02 03:49:22 +00:00
|
|
|
$result = $dispatcher->parseParams(new CakeRequest('/posts'));
|
2011-04-30 18:12:51 +00:00
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST');
|
2010-05-02 03:49:22 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
|
|
|
|
|
2010-05-02 03:49:22 +00:00
|
|
|
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
2011-04-30 18:12:51 +00:00
|
|
|
$expected = array(
|
|
|
|
'pass' => array('5'),
|
|
|
|
'named' => array(),
|
|
|
|
'id' => '5',
|
|
|
|
'plugin' => null,
|
|
|
|
'controller' => 'posts',
|
|
|
|
'action' => 'edit',
|
|
|
|
'[method]' => 'PUT'
|
|
|
|
);
|
2010-05-02 03:49:22 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
|
2010-05-02 03:49:22 +00:00
|
|
|
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
2011-04-30 18:12:51 +00:00
|
|
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET');
|
2010-05-02 03:49:22 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_POST['_method'] = 'PUT';
|
|
|
|
|
2010-05-02 03:49:22 +00:00
|
|
|
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
2011-04-30 18:12:51 +00:00
|
|
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
|
2010-05-02 03:49:22 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_POST['_method'] = 'POST';
|
|
|
|
$_POST['data'] = array('Post' => array('title' => 'New Post'));
|
|
|
|
$_POST['extra'] = 'data';
|
|
|
|
$_SERVER = array();
|
|
|
|
|
2010-05-02 03:49:22 +00:00
|
|
|
$result = $dispatcher->parseParams(new CakeRequest('/posts'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
|
2011-04-30 18:12:51 +00:00
|
|
|
'[method]' => 'POST', 'data' => array('extra' => 'data', 'Post' => array('title' => 'New Post')),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2010-05-02 03:49:22 +00:00
|
|
|
foreach ($expected as $key => $value) {
|
|
|
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($_POST['_method']);
|
|
|
|
}
|
2009-05-04 20:36:22 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* backupEnvironment method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access private
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function __backupEnvironment() {
|
|
|
|
return array(
|
|
|
|
'App' => Configure::read('App'),
|
|
|
|
'GET' => $_GET,
|
|
|
|
'POST' => $_POST,
|
|
|
|
'SERVER'=> $_SERVER
|
|
|
|
);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* reloadEnvironment method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access private
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function __reloadEnvironment() {
|
|
|
|
foreach ($_GET as $key => $val) {
|
|
|
|
unset($_GET[$key]);
|
|
|
|
}
|
|
|
|
foreach ($_POST as $key => $val) {
|
|
|
|
unset($_POST[$key]);
|
|
|
|
}
|
|
|
|
foreach ($_SERVER as $key => $val) {
|
|
|
|
unset($_SERVER[$key]);
|
|
|
|
}
|
|
|
|
Configure::write('App', array());
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* loadEnvironment method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
|
|
|
* @param mixed $env
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access private
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function __loadEnvironment($env) {
|
|
|
|
if ($env['reload']) {
|
|
|
|
$this->__reloadEnvironment();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($env['App'])) {
|
|
|
|
Configure::write('App', $env['App']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($env['GET'])) {
|
|
|
|
foreach ($env['GET'] as $key => $val) {
|
|
|
|
$_GET[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($env['POST'])) {
|
|
|
|
foreach ($env['POST'] as $key => $val) {
|
|
|
|
$_POST[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($env['SERVER'])) {
|
|
|
|
foreach ($env['SERVER'] as $key => $val) {
|
|
|
|
$_SERVER[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-12 18:36:08 +00:00
|
|
|
/**
|
|
|
|
* cachePath method
|
|
|
|
*
|
|
|
|
* @param mixed $her
|
|
|
|
* @return string
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access private
|
2008-06-12 18:36:08 +00:00
|
|
|
*/
|
|
|
|
function __cachePath($here) {
|
|
|
|
$path = $here;
|
|
|
|
if ($here == '/') {
|
|
|
|
$path = 'home';
|
|
|
|
}
|
2008-12-22 19:01:17 +00:00
|
|
|
$path = strtolower(Inflector::slug($path));
|
2008-06-12 18:36:08 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . $path . '.php';
|
|
|
|
|
|
|
|
if (!file_exists($filename)) {
|
|
|
|
$filename = CACHE . 'views' . DS . $path . '_index.php';
|
|
|
|
}
|
|
|
|
return $filename;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|