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
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, 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
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-03-21 23:55:39 +00:00
|
|
|
require_once CAKE . 'dispatcher.php';
|
|
|
|
|
|
|
|
if (!class_exists('AppController')) {
|
|
|
|
require_once LIBS . 'controller' . DS . 'app_controller.php';
|
|
|
|
} elseif (!defined('APP_CONTROLLER_EXISTS')){
|
|
|
|
define('APP_CONTROLLER_EXISTS', true);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestDispatcher class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
* @param mixed $params
|
|
|
|
* @param mixed $missingAction
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access protected
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-08-25 22:57:24 +00:00
|
|
|
function _invoke(&$controller, $params) {
|
2008-07-26 20:09:20 +00:00
|
|
|
restore_error_handler();
|
2008-08-25 22:57:24 +00:00
|
|
|
if ($result = parent::_invoke($controller, $params)) {
|
2009-02-17 23:32:15 +00:00
|
|
|
if ($result[0] === 'missingAction') {
|
2008-07-26 20:09:20 +00:00
|
|
|
return $result;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-07-26 20:09:20 +00:00
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
return $controller;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cakeError method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
|
|
|
* @param mixed $filename
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2009-02-17 23:32:15 +00:00
|
|
|
function cakeError($filename, $params) {
|
|
|
|
return array($filename, $params);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-17 04:24:55 +00:00
|
|
|
/**
|
|
|
|
* _stop method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access protected
|
2008-06-17 04:24:55 +00:00
|
|
|
*/
|
|
|
|
function _stop() {
|
2010-05-02 20:48:35 +00:00
|
|
|
$this->stopped = true;
|
2008-06-17 04:24:55 +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
|
|
|
/**
|
|
|
|
* MyPluginAppController class
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function add() {
|
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function admin_add($id = null) {
|
|
|
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function display($page = null) {
|
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-26 20:09:20 +00:00
|
|
|
/**
|
|
|
|
* protected method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access protected
|
2008-07-26 20:09:20 +00:00
|
|
|
*/
|
|
|
|
function _protected() {
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-26 20:09:20 +00:00
|
|
|
/**
|
|
|
|
* redirect method overriding
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-07-26 20:09:20 +00:00
|
|
|
*/
|
|
|
|
function redirect() {
|
|
|
|
echo 'this should not be accessible';
|
|
|
|
}
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function display($page = null) {
|
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function admin_index() {
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-26 18:33:00 +00:00
|
|
|
/**
|
|
|
|
* camelCased method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-08-26 18:33:00 +00:00
|
|
|
*/
|
|
|
|
function camelCased() {
|
|
|
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function admin_index() {
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-04 03:32:14 +00:00
|
|
|
/**
|
|
|
|
* fake index method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function index() {
|
|
|
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-26 20:09:20 +00:00
|
|
|
/**
|
|
|
|
* change method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-07-26 20:09:20 +00:00
|
|
|
*/
|
|
|
|
function change() {
|
|
|
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestCachedPagesController 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 'TestCachedPages'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $helpers = array('Cache');
|
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
|
|
|
|
*/
|
2008-07-30 21:14:22 +00:00
|
|
|
var $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
|
|
|
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function test_nocache_tags() {
|
|
|
|
$this->render();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 21:14:22 +00:00
|
|
|
/**
|
|
|
|
* view method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-07-30 21:14:22 +00:00
|
|
|
*/
|
|
|
|
function view($id = null) {
|
|
|
|
$this->render('index');
|
|
|
|
}
|
2009-12-13 17:39:39 +00:00
|
|
|
/**
|
|
|
|
* test cached forms / tests view object being registered
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function cache_form() {
|
|
|
|
$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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TimesheetsController 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 'Timesheets'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
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
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2009-06-03 16:23:35 +00:00
|
|
|
function startTest() {
|
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
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(App::core());
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2009-06-03 16:23:35 +00:00
|
|
|
function endTest() {
|
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();
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParseParamsWithoutZerosAndEmptyPost() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParseParamsReturnsPostedData() {
|
|
|
|
$_POST['testdata'] = "My Posted Content";
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$test = $Dispatcher->parseParams("/");
|
|
|
|
$this->assertTrue($test['form'], "Parsed URL not returning post data");
|
|
|
|
$this->assertIdentical($test['form']['testdata'], "My Posted Content");
|
|
|
|
}
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParseParamsWithSingleZero() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23");
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParseParamsWithManySingleZeros() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$test = $Dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParseParamsWithManyZerosInEachSectionOfUrl() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
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'));
|
|
|
|
|
2008-06-20 20:17:23 +00:00
|
|
|
$_GET = array('coffee' => 'life', 'sleep' => 'sissies');
|
2008-05-30 11:40:08 +00:00
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$uri = 'posts/home/?coffee=life&sleep=sissies';
|
|
|
|
$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
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$uri = '/?coffee=life&sleep=sissy';
|
|
|
|
$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
|
|
|
/**
|
|
|
|
* testFileUploadArrayStructure method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFileUploadArrayStructure() {
|
|
|
|
$_FILES = array('data' => array('name' => array(
|
|
|
|
'File' => array(
|
|
|
|
array('data' => 'cake_mssql_patch.patch'),
|
|
|
|
array('data' => 'controller.diff'),
|
|
|
|
array('data' => ''),
|
|
|
|
array('data' => ''),
|
|
|
|
),
|
|
|
|
'Post' => array('attachment' => 'jquery-1.2.1.js'),
|
|
|
|
),
|
|
|
|
'type' => array(
|
|
|
|
'File' => array(
|
|
|
|
array('data' => ''),
|
|
|
|
array('data' => ''),
|
|
|
|
array('data' => ''),
|
|
|
|
array('data' => ''),
|
|
|
|
),
|
|
|
|
'Post' => array('attachment' => 'application/x-javascript'),
|
|
|
|
),
|
|
|
|
'tmp_name' => array(
|
|
|
|
'File' => array(
|
|
|
|
array('data' => '/private/var/tmp/phpy05Ywj'),
|
|
|
|
array('data' => '/private/var/tmp/php7MBztY'),
|
|
|
|
array('data' => ''),
|
|
|
|
array('data' => ''),
|
|
|
|
),
|
|
|
|
'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
|
|
|
|
),
|
|
|
|
'error' => array(
|
|
|
|
'File' => array(
|
|
|
|
array('data' => 0),
|
|
|
|
array('data' => 0),
|
|
|
|
array('data' => 4),
|
|
|
|
array('data' => 4)
|
|
|
|
),
|
|
|
|
'Post' => array('attachment' => 0)
|
|
|
|
),
|
|
|
|
'size' => array(
|
|
|
|
'File' => array(
|
|
|
|
array('data' => 6271),
|
|
|
|
array('data' => 350),
|
|
|
|
array('data' => 0),
|
|
|
|
array('data' => 0),
|
|
|
|
),
|
|
|
|
'Post' => array('attachment' => 80469)
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$result = $Dispatcher->parseParams('/');
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'File' => array(
|
|
|
|
array('data' => array(
|
|
|
|
'name' => 'cake_mssql_patch.patch',
|
|
|
|
'type' => '',
|
|
|
|
'tmp_name' => '/private/var/tmp/phpy05Ywj',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 6271,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array('data' => array(
|
|
|
|
'name' => 'controller.diff',
|
|
|
|
'type' => '',
|
|
|
|
'tmp_name' => '/private/var/tmp/php7MBztY',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 350,
|
|
|
|
)),
|
|
|
|
array('data' => array(
|
|
|
|
'name' => '',
|
|
|
|
'type' => '',
|
|
|
|
'tmp_name' => '',
|
|
|
|
'error' => 4,
|
|
|
|
'size' => 0,
|
|
|
|
)),
|
|
|
|
array('data' => array(
|
|
|
|
'name' => '',
|
|
|
|
'type' => '',
|
|
|
|
'tmp_name' => '',
|
|
|
|
'error' => 4,
|
|
|
|
'size' => 0,
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
'Post' => array('attachment' => array(
|
|
|
|
'name' => 'jquery-1.2.1.js',
|
|
|
|
'type' => 'application/x-javascript',
|
|
|
|
'tmp_name' => '/private/var/tmp/phpEwlrIo',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 80469,
|
|
|
|
)));
|
|
|
|
$this->assertEqual($result['data'], $expected);
|
2008-08-25 22:57:24 +00:00
|
|
|
|
2008-08-24 16:44:33 +00:00
|
|
|
$_FILES = array(
|
|
|
|
'data' => array(
|
|
|
|
'name' => array(
|
|
|
|
'Document' => array(
|
|
|
|
1 => array(
|
|
|
|
'birth_cert' => 'born on.txt',
|
|
|
|
'passport' => 'passport.txt',
|
|
|
|
'drivers_license' => 'ugly pic.jpg'
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'birth_cert' => 'aunt betty.txt',
|
|
|
|
'passport' => 'betty-passport.txt',
|
|
|
|
'drivers_license' => 'betty-photo.jpg'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'type' => array(
|
|
|
|
'Document' => array(
|
|
|
|
1 => array(
|
|
|
|
'birth_cert' => 'application/octet-stream',
|
|
|
|
'passport' => 'application/octet-stream',
|
|
|
|
'drivers_license' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'birth_cert' => 'application/octet-stream',
|
|
|
|
'passport' => 'application/octet-stream',
|
|
|
|
'drivers_license' => 'application/octet-stream',
|
|
|
|
)
|
2008-08-25 22:57:24 +00:00
|
|
|
)
|
2008-08-24 16:44:33 +00:00
|
|
|
),
|
|
|
|
'tmp_name' => array(
|
|
|
|
'Document' => array(
|
|
|
|
1 => array(
|
|
|
|
'birth_cert' => '/private/var/tmp/phpbsUWfH',
|
|
|
|
'passport' => '/private/var/tmp/php7f5zLt',
|
|
|
|
'drivers_license' => '/private/var/tmp/phpMXpZgT',
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'birth_cert' => '/private/var/tmp/php5kHZt0',
|
|
|
|
'passport' => '/private/var/tmp/phpnYkOuM',
|
|
|
|
'drivers_license' => '/private/var/tmp/php9Rq0P3',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'error' => array(
|
|
|
|
'Document' => array(
|
|
|
|
1 => array(
|
|
|
|
'birth_cert' => 0,
|
|
|
|
'passport' => 0,
|
|
|
|
'drivers_license' => 0,
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'birth_cert' => 0,
|
|
|
|
'passport' => 0,
|
|
|
|
'drivers_license' => 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'size' => array(
|
|
|
|
'Document' => array(
|
|
|
|
1 => array(
|
|
|
|
'birth_cert' => 123,
|
|
|
|
'passport' => 458,
|
|
|
|
'drivers_license' => 875,
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'birth_cert' => 876,
|
|
|
|
'passport' => 976,
|
|
|
|
'drivers_license' => 9783,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2008-08-25 22:57:24 +00:00
|
|
|
);
|
|
|
|
$Dispatcher =& new Dispatcher();
|
2008-08-24 16:44:33 +00:00
|
|
|
$result = $Dispatcher->parseParams('/');
|
|
|
|
$expected = array(
|
|
|
|
'Document' => array(
|
|
|
|
1 => array(
|
|
|
|
'birth_cert' => array(
|
|
|
|
'name' => 'born on.txt',
|
|
|
|
'tmp_name' => '/private/var/tmp/phpbsUWfH',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 123,
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
'passport' => array(
|
|
|
|
'name' => 'passport.txt',
|
|
|
|
'tmp_name' => '/private/var/tmp/php7f5zLt',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 458,
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
'drivers_license' => array(
|
|
|
|
'name' => 'ugly pic.jpg',
|
|
|
|
'tmp_name' => '/private/var/tmp/phpMXpZgT',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 875,
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'birth_cert' => array(
|
|
|
|
'name' => 'aunt betty.txt',
|
|
|
|
'tmp_name' => '/private/var/tmp/php5kHZt0',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 876,
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
'passport' => array(
|
|
|
|
'name' => 'betty-passport.txt',
|
|
|
|
'tmp_name' => '/private/var/tmp/phpnYkOuM',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 976,
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
'drivers_license' => array(
|
|
|
|
'name' => 'betty-photo.jpg',
|
|
|
|
'tmp_name' => '/private/var/tmp/php9Rq0P3',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 9783,
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result['data'], $expected);
|
2009-08-13 15:29:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
$_FILES = array(
|
|
|
|
'data' => array(
|
|
|
|
'name' => array('birth_cert' => 'born on.txt'),
|
|
|
|
'type' => array('birth_cert' => 'application/octet-stream'),
|
|
|
|
'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
|
|
|
|
'error' => array('birth_cert' => 0),
|
|
|
|
'size' => array('birth_cert' => 123)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$result = $Dispatcher->parseParams('/');
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'birth_cert' => array(
|
|
|
|
'name' => 'born on.txt',
|
|
|
|
'type' => 'application/octet-stream',
|
|
|
|
'tmp_name' => '/private/var/tmp/phpbsUWfH',
|
|
|
|
'error' => 0,
|
|
|
|
'size' => 123
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEqual($result['data'], $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testGetUrl method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testGetUrl() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$Dispatcher->base = '/app/webroot/index.php';
|
|
|
|
$uri = '/app/webroot/index.php/posts/add';
|
|
|
|
$result = $Dispatcher->getUrl($uri);
|
|
|
|
$expected = 'posts/add';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/app/webroot/index.php');
|
|
|
|
|
|
|
|
$uri = '/posts/add';
|
|
|
|
$result = $Dispatcher->getUrl($uri);
|
|
|
|
$expected = 'posts/add';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
$_GET['url'] = array();
|
|
|
|
Configure::write('App.base', '/control');
|
|
|
|
$Dispatcher =& new Dispatcher();
|
2008-08-25 22:57:24 +00:00
|
|
|
$Dispatcher->baseUrl();
|
2008-05-30 11:40:08 +00:00
|
|
|
$uri = '/control/students/browse';
|
|
|
|
$result = $Dispatcher->getUrl($uri);
|
|
|
|
$expected = 'students/browse';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
$_GET['url'] = array();
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$Dispatcher->base = '';
|
|
|
|
$uri = '/?/home';
|
|
|
|
$result = $Dispatcher->getUrl($uri);
|
|
|
|
$expected = '?/home';
|
|
|
|
$this->assertEqual($expected, $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-11-23 20:13:10 +00:00
|
|
|
$_GET['url'] = array();
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$Dispatcher->base = '/shop';
|
|
|
|
$uri = '/shop/fr/pages/shop';
|
|
|
|
$result = $Dispatcher->getUrl($uri);
|
|
|
|
$expected = 'fr/pages/shop';
|
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBaseUrlAndWebrootWithModRewrite method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testBaseUrlAndWebrootWithModRewrite() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/1.2.x.x';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/1.2.x.x/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/index.php';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/test/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/webroot/index.php';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
2009-07-01 02:56:15 +00:00
|
|
|
$Dispatcher->base = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/some/apps/where/app/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/some/apps/where/app/webroot/index.php';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/some/apps/where';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/some/apps/where/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
|
|
|
|
Configure::write('App.dir', 'auth');
|
|
|
|
|
2009-07-01 02:56:15 +00:00
|
|
|
$Dispatcher->base = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
|
|
|
|
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/demos/auth';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/demos/auth/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.dir', 'code');
|
|
|
|
|
2009-07-01 02:56:15 +00:00
|
|
|
$Dispatcher->base = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/clients/PewterReport/code';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/clients/PewterReport/code/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBaseUrlwithModRewriteAlias method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testBaseUrlwithModRewriteAlias() {
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/control/index.php';
|
|
|
|
|
|
|
|
Configure::write('App.base', '/control');
|
|
|
|
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/control';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/control/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.base', false);
|
|
|
|
Configure::write('App.dir', 'affiliate');
|
|
|
|
Configure::write('App.webroot', 'newaffiliate');
|
|
|
|
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
|
|
|
|
$_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/newaffiliate';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/newaffiliate/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBaseUrlAndWebrootWithBaseUrl method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testBaseUrlAndWebrootWithBaseUrl() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
|
|
|
|
Configure::write('App.dir', 'app');
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/app/webroot/index.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/app/webroot/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/app/webroot/test.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/app/webroot/test.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/app/index.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/app/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
2011-02-17 03:08:20 +00:00
|
|
|
$expectedWebroot = '/app/webroot/';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/CakeBB/app/webroot/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/CakeBB/app/index.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/CakeBB/app/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/CakeBB/index.php');
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/CakeBB/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/dbhauser/index.php');
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/dbhauser/index.php';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/dbhauser/app/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-23 22:08:09 +00:00
|
|
|
/**
|
|
|
|
* test baseUrl with no rewrite and using the top level index.php.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testBaseUrlNoRewriteTopLevelIndex() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/index.php';
|
|
|
|
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$this->assertEqual('/index.php', $result);
|
|
|
|
$this->assertEqual('/app/webroot/', $Dispatcher->webroot);
|
|
|
|
$this->assertEqual('', $Dispatcher->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testBaseUrlNoRewriteWebrootIndex() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
|
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev/app/webroot';
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/app/webroot/index.php';
|
|
|
|
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$this->assertEqual('/index.php', $result);
|
|
|
|
$this->assertEqual('/', $Dispatcher->webroot);
|
|
|
|
$this->assertEqual('', $Dispatcher->base);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBaseUrlAndWebrootWithBase method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testBaseUrlAndWebrootWithBase() {
|
|
|
|
$Dispatcher =& new Dispatcher();
|
|
|
|
$Dispatcher->base = '/app';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/app';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/app/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
$Dispatcher->base = '';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
|
|
|
|
Configure::write('App.dir', 'testbed');
|
|
|
|
$Dispatcher->base = '/cake/testbed/webroot';
|
|
|
|
$result = $Dispatcher->baseUrl();
|
|
|
|
$expected = '/cake/testbed/webroot';
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$expectedWebroot = '/cake/testbed/webroot/';
|
|
|
|
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
|
|
|
|
}
|
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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingController() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
2010-01-27 16:08:04 +00:00
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$url = 'some_controller/home/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
2009-02-17 23:32:15 +00:00
|
|
|
$expected = array('missingController', array(array(
|
|
|
|
'className' => 'SomeControllerController',
|
2011-02-17 03:08:20 +00:00
|
|
|
'webroot' => '/app/webroot/',
|
2009-02-17 23:32:15 +00:00
|
|
|
'url' => 'some_controller/home/param:value/param2:value2',
|
|
|
|
'base' => '/index.php'
|
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $controller);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPrivate method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPrivate() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Configure::write('App.baseUrl','/index.php');
|
2008-07-26 20:09:20 +00:00
|
|
|
$url = 'some_pages/_protected/param:value/param2:value2';
|
2009-02-17 23:32:15 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
2009-02-17 23:32:15 +00:00
|
|
|
$expected = array('privateAction', array(array(
|
|
|
|
'className' => 'SomePagesController',
|
|
|
|
'action' => '_protected',
|
2011-02-17 03:08:20 +00:00
|
|
|
'webroot' => '/app/webroot/',
|
2009-02-17 23:32:15 +00:00
|
|
|
'url' => 'some_pages/_protected/param:value/param2:value2',
|
|
|
|
'base' => '/index.php'
|
|
|
|
)));
|
2008-09-12 02:06:53 +00:00
|
|
|
$this->assertEqual($controller, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMissingAction method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingAction() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
2010-01-27 16:08:04 +00:00
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
2008-05-30 11:40:08 +00:00
|
|
|
$url = 'some_pages/home/param:value/param2:value2';
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
2009-02-17 23:32:15 +00:00
|
|
|
|
|
|
|
$expected = array('missingAction', array(array(
|
|
|
|
'className' => 'SomePagesController',
|
|
|
|
'action' => 'home',
|
2011-02-17 03:08:20 +00:00
|
|
|
'webroot' => '/app/webroot/',
|
2009-02-17 23:32:15 +00:00
|
|
|
'url' => '/index.php/some_pages/home/param:value/param2:value2',
|
|
|
|
'base' => '/index.php'
|
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $controller);
|
2008-07-26 20:09:20 +00:00
|
|
|
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Configure::write('App.baseUrl','/index.php');
|
|
|
|
$url = 'some_pages/redirect/param:value/param2:value2';
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
2009-02-17 23:32:15 +00:00
|
|
|
|
|
|
|
$expected = array('missingAction', array(array(
|
|
|
|
'className' => 'SomePagesController',
|
|
|
|
'action' => 'redirect',
|
2011-02-17 03:08:20 +00:00
|
|
|
'webroot' => '/app/webroot/',
|
2009-02-17 23:32:15 +00:00
|
|
|
'url' => '/index.php/some_pages/redirect/param:value/param2:value2',
|
|
|
|
'base' => '/index.php'
|
|
|
|
)));
|
2008-07-26 20:09:20 +00:00
|
|
|
$this->assertEqual($expected, $controller);
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDispatch() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Configure::write('App.baseUrl','/index.php');
|
|
|
|
$url = 'pages/home/param:value/param2:value2';
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$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');
|
|
|
|
|
|
|
|
$url = 'pages/home';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
|
|
|
$expected = 'Pages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
|
|
|
$url = 'pages/home/';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
2009-12-17 15:16:47 +00:00
|
|
|
$this->assertNull($controller->plugin);
|
|
|
|
$this->assertNull($Dispatcher->params['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
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Configure::write('App.baseUrl','/timesheets/index.php');
|
|
|
|
|
|
|
|
$url = 'timesheets';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
|
|
|
$expected = 'Timesheets';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
|
|
|
$url = 'timesheets/';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
|
|
|
$this->assertEqual('Timesheets', $controller->name);
|
|
|
|
$this->assertEqual('/timesheets/index.php', $Dispatcher->base);
|
2008-08-26 18:33:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
$url = 'test_dispatch_pages/camelCased';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$this->assertEqual('TestDispatchPages', $controller->name);
|
2010-11-23 20:13:10 +00:00
|
|
|
|
2010-04-24 17:42:19 +00:00
|
|
|
$url = 'test_dispatch_pages/camelCased/something. .';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
|
2010-11-23 20:13:10 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-02-25 01:36:13 +00:00
|
|
|
/**
|
|
|
|
* testDispatchWithArray method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2009-02-25 01:36:13 +00:00
|
|
|
*/
|
|
|
|
function testDispatchWithArray() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$url = 'pages/home/param:value/param2:value2';
|
|
|
|
|
|
|
|
$url = array('controller' => 'pages', 'action' => 'display');
|
2010-08-05 03:44:48 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, array(
|
|
|
|
'pass' => array('home'),
|
|
|
|
'named' => array('param' => 'value', 'param2' => 'value2'),
|
|
|
|
'return' => 1
|
|
|
|
));
|
2009-02-25 01:36:13 +00:00
|
|
|
$expected = 'Pages';
|
|
|
|
$this->assertEqual($expected, $controller->name);
|
|
|
|
|
|
|
|
$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
|
|
|
|
$this->assertIdentical($expected, $controller->passedArgs);
|
2010-11-23 20:13:10 +00:00
|
|
|
|
2010-08-05 03:44:48 +00:00
|
|
|
$this->assertEqual($Dispatcher->base . '/pages/display/home/param:value/param2:value2', $Dispatcher->here);
|
2009-02-25 01:36:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-21 21:02:33 +00:00
|
|
|
/**
|
|
|
|
* test that a garbage url doesn't cause errors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testDispatchWithGarbageUrl() {
|
|
|
|
Configure::write('App.baseUrl', '/index.php');
|
|
|
|
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$url = 'http://google.com';
|
|
|
|
$result = $Dispatcher->dispatch($url);
|
|
|
|
$expected = array('missingController', array(array(
|
|
|
|
'className' => 'Controller',
|
2011-02-17 03:08:20 +00:00
|
|
|
'webroot' => '/app/webroot/',
|
2011-01-21 21:02:33 +00:00
|
|
|
'url' => 'http://google.com',
|
|
|
|
'base' => '/index.php'
|
|
|
|
)));
|
|
|
|
$this->assertEqual($expected, $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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAdminDispatch() {
|
|
|
|
$_POST = array();
|
|
|
|
$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');
|
|
|
|
$url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$Router =& Router::getInstance();
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPluginDispatch() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
2010-04-04 03:32:14 +00:00
|
|
|
Router::connect(
|
2010-11-23 20:13:10 +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
|
|
|
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
$url = 'my_plugin/some_pages/home/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
|
|
|
$result = $Dispatcher->parseParams($url);
|
|
|
|
$expected = array(
|
|
|
|
'pass' => array('home'),
|
|
|
|
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
|
|
|
|
'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null,
|
|
|
|
'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
|
|
|
|
);
|
|
|
|
ksort($expected);
|
|
|
|
ksort($result);
|
|
|
|
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
2010-04-04 03:37:31 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'my_plugin');
|
|
|
|
$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
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
|
|
|
|
$this->assertIdentical($expected, $controller->here);
|
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x';
|
|
|
|
$this->assertIdentical($expected, $controller->base);
|
|
|
|
}
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAutomaticPluginDispatch() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$url = 'my_plugin/other_pages/index/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
2010-04-04 03:37:31 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'my_plugin');
|
|
|
|
$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';
|
|
|
|
$this->assertIdentical($expected, $controller->here);
|
|
|
|
|
|
|
|
$expected = '/cake/repo/branches/1.2.x.x';
|
|
|
|
$this->assertIdentical($expected, $controller->base);
|
|
|
|
}
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAutomaticPluginControllerDispatch() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
|
2010-04-04 03:32:14 +00:00
|
|
|
$plugins = App::objects('plugin');
|
|
|
|
$plugins[] = 'MyPlugin';
|
|
|
|
$plugins[] = 'ArticlesTest';
|
|
|
|
|
|
|
|
$app = App::getInstance();
|
|
|
|
$app->__objects['plugin'] = $plugins;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-04-11 01:14:18 +00:00
|
|
|
$url = 'my_plugin/my_plugin/add/param:value/param2:value2';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
2010-01-15 21:18:19 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'my_plugin');
|
|
|
|
$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();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$url = $pluginUrl;
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
2010-04-03 20:29:36 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'my_plugin');
|
|
|
|
$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();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2010-04-11 01:14:18 +00:00
|
|
|
$url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2';
|
2008-05-30 11:40:08 +00:00
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
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'));
|
2010-04-03 20:29:36 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'my_plugin');
|
|
|
|
$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'));
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
|
|
|
$controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
|
2010-04-03 20:29:36 +00:00
|
|
|
$this->assertIdentical($controller->plugin, 'articles_test');
|
|
|
|
$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,
|
2010-11-23 20:13:10 +00:00
|
|
|
'form' => array(),
|
2010-04-04 03:32:14 +00:00
|
|
|
'url' => array('url' => 'admin/articles_test'),
|
|
|
|
'return' => 1
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$this->assertEqual($controller->params, $expected);
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
*/
|
2009-02-13 19:34:25 +00:00
|
|
|
function testAutomaticPluginDispatchWithShortAccess() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
2010-04-04 02:24:31 +00:00
|
|
|
$plugins = App::objects('plugin');
|
|
|
|
$plugins[] = 'MyPlugin';
|
|
|
|
|
|
|
|
$app = App::getInstance();
|
|
|
|
$app->__objects['plugin'] = $plugins;
|
2009-02-13 19:34:25 +00:00
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
|
2009-02-16 00:18:59 +00:00
|
|
|
$Dispatcher =& new TestDispatcher();
|
2009-02-13 19:34:25 +00:00
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2009-12-16 14:41:34 +00:00
|
|
|
$url = 'my_plugin/';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$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
|
|
|
|
*/
|
|
|
|
function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
|
|
|
|
$loaded = class_exists('TestPluginController', false);
|
|
|
|
if ($this->skipIf($loaded, 'TestPluginController already loaded, this test will always pass, skipping %s')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Router::reload();
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
|
|
|
), true);
|
2010-01-15 21:18:19 +00:00
|
|
|
App::objects('plugin', null, false);
|
|
|
|
|
2009-12-16 14:41:34 +00:00
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
|
|
|
$url = 'test_plugin/';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$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
|
|
|
|
|
|
|
$url = '/test_plugin/tests/index';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$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]));
|
|
|
|
|
|
|
|
$url = '/test_plugin/tests/index/some_param';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$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
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAutomaticPluginControllerMissingActionDispatch() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2009-02-17 23:32:15 +00:00
|
|
|
$url = 'my_plugin/not_here/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
|
|
|
|
|
|
|
$expected = array('missingAction', array(array(
|
|
|
|
'className' => 'MyPluginController',
|
|
|
|
'action' => 'not_here',
|
|
|
|
'webroot' => '/cake/repo/branches/1.2.x.x/',
|
|
|
|
'url' => '/cake/repo/branches/1.2.x.x/my_plugin/not_here/param:value/param2:value2',
|
|
|
|
'base' => '/cake/repo/branches/1.2.x.x'
|
|
|
|
)));
|
|
|
|
$this->assertIdentical($expected, $controller);
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$url = 'my_plugin/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
|
|
|
|
2009-02-17 23:32:15 +00:00
|
|
|
$expected = array('missingAction', array(array(
|
|
|
|
'className' => 'MyPluginController',
|
|
|
|
'action' => 'param:value',
|
|
|
|
'webroot' => '/cake/repo/branches/1.2.x.x/',
|
|
|
|
'url' => '/cake/repo/branches/1.2.x.x/my_plugin/param:value/param2:value2',
|
|
|
|
'base' => '/cake/repo/branches/1.2.x.x'
|
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical($expected, $controller);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testPrefixProtection 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 public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPrefixProtection() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/admin/:controller/:action/*', array('prefix'=>'admin'), array('controller', 'action'));
|
|
|
|
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
|
|
|
|
$url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
2009-02-17 23:32:15 +00:00
|
|
|
$expected = array('privateAction', array(array(
|
|
|
|
'className' => 'TestDispatchPagesController',
|
|
|
|
'action' => 'admin_index',
|
|
|
|
'webroot' => '/cake/repo/branches/1.2.x.x/',
|
|
|
|
'url' => 'test_dispatch_pages/admin_index/param:value/param2:value2',
|
|
|
|
'base' => '/cake/repo/branches/1.2.x.x'
|
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertIdentical($expected, $controller);
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
*/
|
2008-07-24 02:19:05 +00:00
|
|
|
function testTestPluginDispatch() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
|
|
|
));
|
2009-12-16 14:41:34 +00:00
|
|
|
App::objects('plugin', null, false);
|
|
|
|
Router::reload();
|
|
|
|
Router::parse('/');
|
|
|
|
|
2008-07-24 02:19:05 +00:00
|
|
|
$url = '/test_plugin/tests/index';
|
|
|
|
$result = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$this->assertTrue(class_exists('TestsController'));
|
|
|
|
$this->assertTrue(class_exists('TestPluginAppController'));
|
|
|
|
$this->assertTrue(class_exists('OtherComponentComponent'));
|
|
|
|
$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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testChangingParamsFromBeforeFilter() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
$url = 'some_posts/index/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
2009-02-17 23:32:15 +00:00
|
|
|
$expected = array('missingAction', array(array(
|
|
|
|
'className' => 'SomePostsController',
|
|
|
|
'action' => 'view',
|
|
|
|
'webroot' => '/cake/repo/branches/1.2.x.x/',
|
|
|
|
'url' => '/cake/repo/branches/1.2.x.x/some_posts/index/param:value/param2:value2',
|
|
|
|
'base' => '/cake/repo/branches/1.2.x.x'
|
|
|
|
)));
|
2008-07-26 20:09:20 +00:00
|
|
|
$this->assertEqual($expected, $controller);
|
|
|
|
|
|
|
|
$url = 'some_posts/something_else/param:value/param2:value2';
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2009-12-16 23:32:20 +00:00
|
|
|
function testAssets() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Router::reload();
|
2010-03-06 02:41:48 +00:00
|
|
|
$Configure =& Configure::getInstance();
|
2008-05-30 11:40:08 +00:00
|
|
|
$Configure->__objects = null;
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
2009-11-25 17:06:28 +00:00
|
|
|
'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
2009-06-11 16:13:16 +00:00
|
|
|
));
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Dispatcher =& new TestDispatcher();
|
2009-11-25 17:06:28 +00:00
|
|
|
$debug = Configure::read('debug');
|
|
|
|
Configure::write('debug', 0);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 18:41:19 +00:00
|
|
|
ob_start();
|
|
|
|
$Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
|
|
|
|
$result = ob_get_clean();
|
2009-12-16 23:32:20 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$Dispatcher->dispatch('theme/test_theme/pdfs');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
|
|
|
$Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
|
|
|
|
$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();
|
|
|
|
$Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
|
|
|
|
$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();
|
|
|
|
$Dispatcher->dispatch('theme/test_theme/img/test.jpg');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
|
|
|
|
$this->assertEqual($file, $result);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('theme/test_theme/css/test_asset.css');
|
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
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/theme.js');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('theme/test_theme/js/theme.js');
|
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
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/one/theme_one.js');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('theme/test_theme/js/one/theme_one.js');
|
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();
|
|
|
|
$Dispatcher->asset('test_plugin/root.js');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'root.js');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2009-11-25 17:06:28 +00:00
|
|
|
ob_start();
|
|
|
|
$Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'flash' . DS . 'plugin_test.swf');
|
|
|
|
$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();
|
|
|
|
$Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'pdfs' . DS . 'plugin_test.pdf');
|
|
|
|
$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();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('test_plugin/js/test_plugin/test.js');
|
2009-08-12 14:08:31 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('alert("Test App");', $result);
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('test_plugin/js/test_plugin/test.js');
|
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
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('test_plugin/css/test_plugin_asset.css');
|
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
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('test_plugin/img/cake.icon.gif');
|
2008-06-17 04:24:55 +00:00
|
|
|
$result = ob_get_clean();
|
2009-11-25 07:51:25 +00:00
|
|
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .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
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('plugin_js/js/plugin_js.js');
|
2009-11-03 18:14:38 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "alert('win sauce');";
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-12-16 23:32:20 +00:00
|
|
|
|
2009-11-27 06:49:20 +00:00
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/one/plugin_one.js');
|
|
|
|
ob_start();
|
2009-12-16 23:32:20 +00:00
|
|
|
$Dispatcher->asset('plugin_js/js/one/plugin_one.js');
|
2009-11-27 06:49:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "alert('plugin one nested js file');";
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
Configure::write('debug', $debug);
|
|
|
|
//reset the header content-type without page can render as plain text.
|
|
|
|
header('Content-type: text/html');
|
2009-12-16 23:32:20 +00:00
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
|
|
|
|
ob_start();
|
|
|
|
$Dispatcher->asset('test_plugin/css/unknown.extension');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('Testing a file with unknown extension to mime mapping.', $result);
|
|
|
|
header('Content-type: text/html');
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/theme_one.htc');
|
|
|
|
ob_start();
|
|
|
|
$Dispatcher->asset('test_plugin/css/theme_one.htc');
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual('htc file', $result);
|
|
|
|
header('Content-type: text/html');
|
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
|
|
|
|
*/
|
|
|
|
function testMissingAssetProcessor404() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Configure::write('Asset.filter', array(
|
|
|
|
'js' => '',
|
|
|
|
'css' => null
|
|
|
|
));
|
|
|
|
$this->assertNoErrors();
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$Dispatcher->asset('ccss/cake.generic.css');
|
2010-05-02 20:48:35 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertTrue($Dispatcher->stopped);
|
2010-02-07 20:19:47 +00:00
|
|
|
|
|
|
|
header('HTTP/1.1 200 Ok');
|
|
|
|
}
|
|
|
|
|
2010-05-02 20:48:35 +00:00
|
|
|
/**
|
2010-11-23 20:13:10 +00:00
|
|
|
* test that asset filters work for theme and plugin assets
|
2010-05-02 20:48:35 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testAssetFilterForThemeAndPlugins() {
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Configure::write('Asset.filter', array(
|
|
|
|
'js' => '',
|
|
|
|
'css' => ''
|
|
|
|
));
|
|
|
|
$Dispatcher->asset('theme/test_theme/ccss/cake.generic.css');
|
|
|
|
$this->assertTrue($Dispatcher->stopped);
|
|
|
|
|
|
|
|
$Dispatcher->stopped = false;
|
|
|
|
$Dispatcher->asset('theme/test_theme/cjs/debug_kit.js');
|
|
|
|
$this->assertTrue($Dispatcher->stopped);
|
|
|
|
|
|
|
|
$Dispatcher->stopped = false;
|
|
|
|
$Dispatcher->asset('test_plugin/ccss/cake.generic.css');
|
|
|
|
$this->assertTrue($Dispatcher->stopped);
|
|
|
|
|
|
|
|
$Dispatcher->stopped = false;
|
|
|
|
$Dispatcher->asset('test_plugin/cjs/debug_kit.js');
|
|
|
|
$this->assertTrue($Dispatcher->stopped);
|
|
|
|
|
|
|
|
$Dispatcher->stopped = false;
|
|
|
|
$Dispatcher->asset('css/ccss/debug_kit.css');
|
|
|
|
$this->assertFalse($Dispatcher->stopped);
|
2010-11-23 20:13:10 +00:00
|
|
|
|
2010-05-02 20:48:35 +00:00
|
|
|
$Dispatcher->stopped = false;
|
|
|
|
$Dispatcher->asset('js/cjs/debug_kit.js');
|
|
|
|
$this->assertFalse($Dispatcher->stopped);
|
|
|
|
}
|
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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFullPageCachingDispatch() {
|
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
Configure::write('debug', 2);
|
|
|
|
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
|
|
|
|
), true);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-15 21:18:19 +00:00
|
|
|
$dispatcher =& new TestDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
$dispatcher->base = false;
|
|
|
|
|
|
|
|
$url = '/';
|
|
|
|
|
|
|
|
ob_start();
|
2008-06-12 18:36:08 +00:00
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-06-12 18:36:08 +00:00
|
|
|
|
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
$dispatcher->base = false;
|
|
|
|
$url = 'test_cached_pages/index';
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-06-12 18:36:08 +00:00
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
$url = 'TestCachedPages/index';
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-06-12 18:36:08 +00:00
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
$url = 'TestCachedPages/test_nocache_tags';
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
$url = 'test_cached_pages/view/param/param';
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-06-12 18:36:08 +00:00
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
2008-05-30 11:40:08 +00:00
|
|
|
unlink($filename);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-09-17 21:08:50 +00:00
|
|
|
$url = '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();
|
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-09-17 21:08:50 +00:00
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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
|
|
|
|
2008-09-17 21:08:50 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
unlink($filename);
|
2009-12-13 17:39:39 +00:00
|
|
|
}
|
2010-01-04 04:51:31 +00:00
|
|
|
|
2009-12-13 17:39:39 +00:00
|
|
|
/**
|
|
|
|
* test that cached() registers a view and un-registers it. Tests
|
|
|
|
* that helpers using ClassRegistry::getObject('view'); don't fail
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCachedRegisteringViewObject() {
|
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
Configure::write('debug', 2);
|
|
|
|
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/';
|
|
|
|
|
|
|
|
Router::reload();
|
2010-01-04 04:35:17 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
2009-12-13 17:39:39 +00:00
|
|
|
|
2010-01-15 21:18:19 +00:00
|
|
|
$dispatcher =& new TestDispatcher();
|
2009-12-13 17:39:39 +00:00
|
|
|
$dispatcher->base = false;
|
|
|
|
|
|
|
|
$url = 'test_cached_pages/cache_form';
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->dispatch($url);
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
ClassRegistry::flush();
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$dispatcher->cached($url);
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
$filename = $this->__cachePath($dispatcher->here);
|
2010-01-15 21:18:19 +00:00
|
|
|
@unlink($filename);
|
2009-12-13 17:39:39 +00:00
|
|
|
ClassRegistry::flush();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +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
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testHttpMethodOverrides() {
|
|
|
|
Router::reload();
|
|
|
|
Router::mapResources('Posts');
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$dispatcher->base = false;
|
|
|
|
|
|
|
|
$result = $dispatcher->parseParams('/posts');
|
|
|
|
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array(), 'url' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
|
|
|
|
|
|
|
|
$result = $dispatcher->parseParams('/posts/5');
|
|
|
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
|
|
|
|
$result = $dispatcher->parseParams('/posts/5');
|
|
|
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array(), 'url' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$_POST['_method'] = 'PUT';
|
|
|
|
|
|
|
|
$result = $dispatcher->parseParams('/posts/5');
|
|
|
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array(), 'url' => array());
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$_POST['_method'] = 'POST';
|
|
|
|
$_POST['data'] = array('Post' => array('title' => 'New Post'));
|
|
|
|
$_POST['extra'] = 'data';
|
|
|
|
$_SERVER = array();
|
|
|
|
|
|
|
|
$result = $dispatcher->parseParams('/posts');
|
|
|
|
$expected = array(
|
|
|
|
'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
|
|
|
|
'[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')),
|
|
|
|
'url' => array()
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
unset($_POST['_method']);
|
|
|
|
}
|
2009-05-04 20:36:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that invalid characters cannot be injected into the application base path.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2009-05-04 20:36:22 +00:00
|
|
|
*/
|
|
|
|
function testBasePathInjection() {
|
|
|
|
$self = $_SERVER['PHP_SELF'];
|
|
|
|
$_SERVER['PHP_SELF'] = urldecode(
|
|
|
|
"/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E"
|
|
|
|
);
|
|
|
|
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
$result = $dispatcher->baseUrl();
|
|
|
|
$expected = '/index.php/h1 onclick=alert(xss);heya';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testEnvironmentDetection 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 public
|
2008-06-05 15:20:45 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testEnvironmentDetection() {
|
|
|
|
$dispatcher =& new Dispatcher();
|
|
|
|
|
|
|
|
$environments = array(
|
|
|
|
'IIS' => array(
|
|
|
|
'No rewrite base path' => array(
|
|
|
|
'App' => array('base' => false, 'baseUrl' => '/index.php?', 'server' => 'IIS'),
|
2011-01-23 22:08:09 +00:00
|
|
|
'SERVER' => array('HTTPS' => 'off', 'SCRIPT_NAME' => '/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '', 'REMOTE_ADDR' => '127.0.0.1', 'REMOTE_HOST' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'APPL_PHYSICAL_PATH' => 'C:\\Inetpub\\wwwroot\\', 'REQUEST_URI' => '/index.php', 'URL' => '/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', 'ORIG_PATH_INFO' => '/index.php', 'PATH_INFO' => '', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/index.php', 'HTTP_HOST' => 'localhost', 'argv' => array(), 'argc' => 0),
|
2008-05-30 11:40:08 +00:00
|
|
|
'reload' => true,
|
|
|
|
'path' => ''
|
|
|
|
),
|
|
|
|
'No rewrite with path' => array(
|
|
|
|
'SERVER' => array('QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', 'URL' => '/index.php?/posts/add', 'argv' => array('/posts/add'), 'argc' => 1),
|
|
|
|
'reload' => false,
|
|
|
|
'path' => '/posts/add'
|
|
|
|
),
|
|
|
|
'No rewrite sub dir 1' => array(
|
|
|
|
'GET' => array(),
|
|
|
|
'SERVER' => array('QUERY_STRING' => '', 'REQUEST_URI' => '/index.php', 'URL' => '/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', 'ORIG_PATH_INFO' => '/index.php', 'PATH_INFO' => '', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/index.php', 'argv' => array(), 'argc' => 0),
|
|
|
|
'reload' => false,
|
|
|
|
'path' => ''
|
|
|
|
),
|
|
|
|
'No rewrite sub dir 1 with path' => array(
|
|
|
|
'GET' => array('/posts/add' => ''),
|
|
|
|
'SERVER' => array('QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/index.php?/posts/add', 'URL' => '/index.php?/posts/add', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php', 'argv' => array('/posts/add'), 'argc' => 1),
|
|
|
|
'reload' => false,
|
|
|
|
'path' => '/posts/add'
|
|
|
|
),
|
|
|
|
'No rewrite sub dir 2' => array(
|
|
|
|
'App' => array('base' => false, 'baseUrl' => '/site/index.php?', 'dir' => 'app', 'webroot' => 'webroot', 'server' => 'IIS'),
|
|
|
|
'GET' => array(),
|
|
|
|
'POST' => array(),
|
|
|
|
'SERVER' => array('SCRIPT_NAME' => '/site/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '', 'REQUEST_URI' => '/site/index.php', 'URL' => '/site/index.php', 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\site\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/site/index.php', 'argv' => array(), 'argc' => 0),
|
|
|
|
'reload' => false,
|
|
|
|
'path' => ''
|
|
|
|
),
|
|
|
|
'No rewrite sub dir 2 with path' => array(
|
|
|
|
'GET' => array('/posts/add' => ''),
|
|
|
|
'SERVER' => array('SCRIPT_NAME' => '/site/index.php', 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot', 'QUERY_STRING' => '/posts/add', 'REQUEST_URI' => '/site/index.php?/posts/add', 'URL' => '/site/index.php?/posts/add', 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\site\\index.php', 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot', 'PHP_SELF' => '/site/index.php', 'argv' => array('/posts/add'), 'argc' => 1),
|
|
|
|
'reload' => false,
|
|
|
|
'path' => '/posts/add'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Apache' => array(
|
|
|
|
'No rewrite base path' => array(
|
|
|
|
'App' => array('base' => false, 'baseUrl' => '/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
|
2011-01-23 22:08:09 +00:00
|
|
|
'SERVER' => array(
|
|
|
|
'SERVER_NAME' => 'localhost',
|
|
|
|
'SERVER_ADDR' => '::1',
|
|
|
|
'SERVER_PORT' => '80',
|
|
|
|
'REMOTE_ADDR' => '::1',
|
|
|
|
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
|
|
|
|
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
|
|
|
|
'QUERY_STRING' => '',
|
|
|
|
'REQUEST_URI' => '/',
|
|
|
|
'SCRIPT_NAME' => '/index.php',
|
|
|
|
'PHP_SELF' => '/index.php',
|
|
|
|
'argv' => array(),
|
|
|
|
'argc' => 0
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'reload' => true,
|
|
|
|
'path' => ''
|
|
|
|
),
|
|
|
|
'No rewrite with path' => array(
|
2011-01-23 22:08:09 +00:00
|
|
|
'SERVER' => array(
|
|
|
|
'HTTP_HOST' => 'localhost',
|
|
|
|
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/officespace/app/webroot',
|
|
|
|
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/officespace/app/webroot/index.php',
|
|
|
|
'QUERY_STRING' => '',
|
|
|
|
'REQUEST_URI' => '/index.php/posts/add',
|
|
|
|
'SCRIPT_NAME' => '/index.php',
|
|
|
|
'PATH_INFO' => '/posts/add',
|
|
|
|
'PHP_SELF' => '/index.php/posts/add',
|
|
|
|
'argv' => array(),
|
|
|
|
'argc' => 0),
|
2008-05-30 11:40:08 +00:00
|
|
|
'reload' => false,
|
|
|
|
'path' => '/posts/add'
|
|
|
|
),
|
|
|
|
'GET Request at base domain' => array(
|
|
|
|
'App' => array('base' => false, 'baseUrl' => null, 'dir' => 'app', 'webroot' => 'webroot'),
|
2011-01-23 22:08:09 +00:00
|
|
|
'SERVER' => array(
|
|
|
|
'HTTP_HOST' => 'cake.1.2',
|
|
|
|
'SERVER_NAME' => 'cake.1.2',
|
|
|
|
'SERVER_ADDR' => '127.0.0.1',
|
|
|
|
'SERVER_PORT' => '80',
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1',
|
|
|
|
'DOCUMENT_ROOT' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot',
|
|
|
|
'SCRIPT_FILENAME' => '/Volumes/Home/htdocs/cake/repo/branches/1.2.x.x/app/webroot/index.php',
|
|
|
|
'REMOTE_PORT' => '53550',
|
|
|
|
'QUERY_STRING' => 'a=b',
|
|
|
|
'REQUEST_URI' => '/?a=b',
|
|
|
|
'SCRIPT_NAME' => '/index.php',
|
|
|
|
'PHP_SELF' => '/index.php'
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'GET' => array('a' => 'b'),
|
|
|
|
'POST' => array(),
|
|
|
|
'reload' => true,
|
|
|
|
'path' => '',
|
2008-06-03 11:38:20 +00:00
|
|
|
'urlParams' => array('a' => 'b'),
|
|
|
|
'environment' => array('CGI_MODE' => false)
|
|
|
|
),
|
|
|
|
'New CGI no mod_rewrite' => array(
|
|
|
|
'App' => array('base' => false, 'baseUrl' => '/limesurvey20/index.php', 'dir' => 'app', 'webroot' => 'webroot'),
|
2011-01-23 22:08:09 +00:00
|
|
|
'SERVER' => array(
|
|
|
|
'DOCUMENT_ROOT' => '/home/.sites/110/site313/web',
|
|
|
|
'PATH_INFO' => '/installations',
|
|
|
|
'PATH_TRANSLATED' => '/home/.sites/110/site313/web/limesurvey20/index.php',
|
|
|
|
'PHPRC' => '/home/.sites/110/site313',
|
|
|
|
'QUERY_STRING' => '',
|
|
|
|
'REQUEST_URI' => '/limesurvey20/index.php/installations',
|
|
|
|
'SCRIPT_FILENAME' => '/home/.sites/110/site313/web/limesurvey20/index.php',
|
|
|
|
'SCRIPT_NAME' => '/limesurvey20/index.php',
|
|
|
|
'SCRIPT_URI' => 'http://www.gisdat-umfragen.at/limesurvey20/index.php/installations',
|
|
|
|
'PHP_SELF' => '/limesurvey20/index.php/installations',
|
|
|
|
'CGI_MODE' => true
|
|
|
|
),
|
2008-06-03 11:38:20 +00:00
|
|
|
'GET' => array(),
|
|
|
|
'POST' => array(),
|
|
|
|
'reload' => true,
|
|
|
|
'path' => '/installations',
|
|
|
|
'urlParams' => array(),
|
|
|
|
'environment' => array('CGI_MODE' => true)
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$backup = $this->__backupEnvironment();
|
|
|
|
|
|
|
|
foreach ($environments as $name => $env) {
|
|
|
|
foreach ($env as $descrip => $settings) {
|
|
|
|
if ($settings['reload']) {
|
|
|
|
$this->__reloadEnvironment();
|
|
|
|
}
|
|
|
|
$this->__loadEnvironment($settings);
|
|
|
|
$this->assertEqual($dispatcher->uri(), $settings['path'], "%s on environment: {$name}, on setting: {$descrip}");
|
2008-06-03 11:38:20 +00:00
|
|
|
|
|
|
|
if (isset($settings['urlParams'])) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($_GET, $settings['urlParams'], "%s on environment: {$name}, on setting: {$descrip}");
|
|
|
|
}
|
2008-06-03 11:38:20 +00:00
|
|
|
if (isset($settings['environment'])) {
|
|
|
|
foreach ($settings['environment'] as $key => $val) {
|
|
|
|
$this->assertEqual(env($key), $val, "%s on key {$key} on environment: {$name}, on setting: {$descrip}");
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->__loadEnvironment(array_merge(array('reload' => true), $backup));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-17 15:17:23 +00:00
|
|
|
/**
|
|
|
|
* Tests that the Dispatcher does not return an empty action
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
* @access public
|
2008-09-17 15:17:23 +00:00
|
|
|
*/
|
|
|
|
function testTrailingSlash() {
|
|
|
|
$_POST = array();
|
|
|
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
|
|
|
|
|
|
|
Router::reload();
|
|
|
|
$Dispatcher =& new TestDispatcher();
|
|
|
|
Router::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null));
|
|
|
|
|
|
|
|
$Dispatcher->base = false;
|
|
|
|
$url = 'myalias/'; //Fails
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$result = $Dispatcher->parseParams($url);
|
|
|
|
$this->assertEqual('index', $result['action']);
|
|
|
|
|
|
|
|
$url = 'myalias'; //Passes
|
|
|
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
|
|
|
$result = $Dispatcher->parseParams($url);
|
|
|
|
$this->assertEqual('index', $result['action']);
|
|
|
|
}
|
2009-07-24 19:18:37 +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
|
|
|
}
|