Merge remote branch 'origin/1.3' into 2.0

Conflicts:
	cake/dispatcher.php
	cake/libs/model/behaviors/acl.php
	cake/libs/model/behaviors/containable.php
	cake/libs/model/behaviors/tree.php
	cake/libs/router.php
	cake/tests/cases/libs/validation.test.php
This commit is contained in:
predominant 2010-04-09 22:05:00 +10:00
commit 52cdef900b
25 changed files with 309 additions and 175 deletions

View file

@ -52,6 +52,7 @@ if (!function_exists('clone')) {
* `config('config1', 'config2');`
*
* @return boolean Success
* @link http://book.cakephp.org/view/1125/config
*/
function config() {
$args = func_get_args();
@ -82,6 +83,7 @@ if (!function_exists('clone')) {
*
* @param string $name Filename without the .php part
* @deprecated Will be removed in 2.0
* @link http://book.cakephp.org/view/1140/uses
*/
function uses() {
$args = func_get_args();
@ -99,6 +101,7 @@ if (!function_exists('clone')) {
* @param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way.
* @param boolean $showFrom If set to true, the method prints from where the function was called.
* @link http://book.cakephp.org/view/1190/Basic-Debugging
* @link http://book.cakephp.org/view/1128/debug
*/
function debug($var = false, $showHtml = false, $showFrom = true) {
if (Configure::read() > 0) {

View file

@ -28,7 +28,7 @@ App::import('Model', 'CakeSchema', false);
*
* @package cake
* @subpackage cake.cake.console.libs
* @link http://book.cakephp.org/view/1523s/Schema-management-and-migrations
* @link http://book.cakephp.org/view/1523/Schema-management-and-migrations
*/
class SchemaShell extends Shell {

View file

@ -362,28 +362,6 @@ class Dispatcher extends Object {
}
return $base . $file;
}
/**
* Restructure params in case we're serving a plugin.
*
* @param array $params Array on where to re-set 'controller', 'action', and 'pass' indexes
* @param boolean $reverse If true all the params are shifted one forward, so plugin becomes
* controller, controller becomes action etc. If false, plugin is made equal to controller
* @return array Restructured array
*/
protected function _restructureParams($params, $reverse = false) {
if ($reverse === true) {
extract(Router::getArgs($params['action']));
$params = array_merge($params, array(
'controller'=> $params['plugin'],
'action'=> $params['controller'],
'pass' => array_merge($pass, $params['pass']),
'named' => array_merge($named, $params['named'])
));
} else {
$params['plugin'] = $params['controller'];
}
return $params;
}
/**
* Get controller to use, either plugin controller or application controller
@ -393,32 +371,14 @@ class Dispatcher extends Object {
* @access private
*/
function &__getController() {
$original = $params = $this->params;
$controller = false;
$ctrlClass = $this->__loadController($params);
$ctrlClass = $this->__loadController($this->params);
if (!$ctrlClass) {
if (!isset($params['plugin'])) {
$params = $this->_restructureParams($params);
} else {
$params = $this->_restructureParams($params, true);
}
$ctrlClass = $this->__loadController($params);
if (!$ctrlClass) {
$this->params = $original;
return $controller;
}
}
$name = $ctrlClass;
$ctrlClass .= 'Controller';
if (class_exists($ctrlClass)) {
if (
empty($params['plugin']) &&
strtolower(get_parent_class($ctrlClass)) === strtolower($name . 'AppController')
) {
$params = $this->_restructureParams($params);
}
$this->params = $params;
$controller =& new $ctrlClass();
}
return $controller;

View file

@ -432,7 +432,7 @@ class Configure extends Object {
/**
* Class/file loader and path management.
*
* @link http://book.cakephp.org/view/499/The-App-Class
* @link http://book.cakephp.org/view/933/The-App-Class
* @since CakePHP(tm) v 1.2.0.6001
* @package cake
* @subpackage cake.cake.libs

View file

@ -30,6 +30,7 @@
*
* @package cake
* @subpackage cake.cake.libs.controller
* @link http://book.cakephp.org/view/957/The-App-Controller
*/
class AppController extends Controller {
}

View file

@ -27,6 +27,7 @@
*
* @package cake
* @subpackage cake.cake.libs.controller
* @link http://book.cakephp.org/view/958/The-Pages-Controller
*/
class PagesController extends AppController {

View file

@ -25,6 +25,7 @@
*
* @package cake
* @subpackage cake.cake.libs.model.behaviors
* @link http://book.cakephp.org/view/1320/ACL
*/
class AclBehavior extends ModelBehavior {
@ -67,6 +68,7 @@ class AclBehavior extends ModelBehavior {
*
* @param mixed $ref
* @return array
* @link http://book.cakephp.org/view/1322/node
*/
public function node(&$model, $ref = null) {
$type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])];

View file

@ -26,6 +26,7 @@
*
* @package cake
* @subpackage cake.cake.console.libs
* @link http://book.cakephp.org/view/1323/Containable
*/
class ContainableBehavior extends ModelBehavior {
@ -230,6 +231,7 @@ class ContainableBehavior extends ModelBehavior {
*
* @param object $Model Model on which binding restriction is being applied
* @return void
* @link http://book.cakephp.org/view/1323/Containable#Using-Containable-1324
*/
public function contain(&$Model) {
$args = func_get_args();

View file

@ -23,6 +23,7 @@
*
* @package cake
* @subpackage cake.cake.libs.model.behaviors
* @link http://book.cakephp.org/view/1328/Translate
*/
class TranslateBehavior extends ModelBehavior {

View file

@ -28,6 +28,7 @@
* @see http://en.wikipedia.org/wiki/Tree_traversal
* @package cake
* @subpackage cake.cake.libs.model.behaviors
* @link http://book.cakephp.org/view/1339/Tree
*/
class TreeBehavior extends ModelBehavior {
@ -201,6 +202,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $id The ID of the record to read or false to read all top level nodes
* @param boolean $direct whether to count direct, or all, children
* @return integer number of child nodes
* @link http://book.cakephp.org/view/1347/Counting-children
*/
public function childcount(&$Model, $id = null, $direct = false) {
if (is_array($id)) {
@ -246,6 +248,7 @@ class TreeBehavior extends ModelBehavior {
* @param integer $page Page number, for accessing paged data
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of child nodes
* @link http://book.cakephp.org/view/1346/Children
*/
public function children(&$Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
if (is_array($id)) {
@ -302,6 +305,7 @@ class TreeBehavior extends ModelBehavior {
* @param string $spacer The character or characters which will be repeated
* @param integer $recursive The number of levels deep to fetch associated records
* @return array An associative array of records, where the id is the key, and the display field is the value
* @link http://book.cakephp.org/view/1348/generatetreelist
*/
public function generatetreelist(&$Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
$overrideRecursive = $recursive;
@ -356,6 +360,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $id The ID of the record to read
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of data for the parent node
* @link http://book.cakephp.org/view/1349/getparentnode
*/
public function getparentnode(&$Model, $id = null, $fields = null, $recursive = null) {
if (is_array($id)) {
@ -388,6 +393,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $fields Either a single string of a field name, or an array of field names
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of nodes from top most parent to current node
* @link http://book.cakephp.org/view/1350/getpath
*/
public function getpath(&$Model, $id = null, $fields = null, $recursive = null) {
if (is_array($id)) {
@ -424,6 +430,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $id The ID of the record to move
* @param mixed $number how many places to move the node or true to move to last position
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/view/1352/moveDown
*/
public function movedown(&$Model, $id = null, $number = 1) {
if (is_array($id)) {
@ -481,6 +488,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $id The ID of the record to move
* @param mixed $number how many places to move the node, or true to move to first position
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/view/1353/moveUp
*/
public function moveup(&$Model, $id = null, $number = 1) {
if (is_array($id)) {
@ -544,6 +552,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to
* delete, or the id of the parent to set as the parent_id
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/view/1628/Recover
*/
public function recover(&$Model, $mode = 'parent', $missingParentAction = null) {
if (is_array($mode)) {
@ -622,6 +631,8 @@ class TreeBehavior extends ModelBehavior {
* @param AppModel $Model Model instance
* @param array $options array of options to use in reordering.
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/view/1355/reorder
* @link http://book.cakephp.org/view/1629/Reorder
*/
function reorder(&$Model, $options = array()) {
$options = array_merge(array('id' => null, 'field' => $Model->displayField, 'order' => 'ASC', 'verify' => true), $options);
@ -660,6 +671,7 @@ class TreeBehavior extends ModelBehavior {
* @param mixed $id The ID of the record to remove
* @param boolean $delete whether to delete the node after reparenting children (if any)
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/view/1354/removeFromTree
*/
public function removefromtree(&$Model, $id = null, $delete = false) {
if (is_array($id)) {
@ -727,6 +739,7 @@ class TreeBehavior extends ModelBehavior {
* @param AppModel $Model Model instance
* @return mixed true if the tree is valid or empty, otherwise an array of (error type [index, node],
* [incorrect left/right index,node id], message)
* @link http://book.cakephp.org/view/1630/Verify
*/
public function verify(&$Model) {
extract($this->settings[$Model->alias]);

View file

@ -492,7 +492,7 @@ class DboPostgres extends DboSource {
$match[1] = trim(str_replace('DISTINCT', '', $match[1]));
}
if (strpos($match[1], '.') === false) {
$match[1] = $this->name($alias . '.' . $match[1]);
$match[1] = $this->name($match[1]);
} else {
$parts = explode('.', $match[1]);
if (!Set::numeric($parts)) {

View file

@ -41,7 +41,7 @@ if (!class_exists('Overloadable')) {
*
* @package cake
* @subpackage cake.cake.libs.model
* @link http://book.cakephp.org/view/66/Models
* @link http://book.cakephp.org/view/1000/Models
*/
class Model extends Overloadable {

View file

@ -540,17 +540,29 @@ class Router {
* Connects the default, built-in routes, including prefix and plugin routes. The following routes are created
* in the order below:
*
* For each of the Routing.prefixes the following routes are created. Routes containing `:plugin` are only
* created when your application has one or more plugins.
*
* - `/:prefix/:plugin` a plugin shortcut route.
* - `/:prefix/:plugin/:action/*` a plugin shortcut route.
* - `/:prefix/:plugin/:controller`
* - `/:prefix/:plugin/:controller/:action/*`
* - `/:prefix/:controller`
* - `/:prefix/:controller/:action/*`
*
* If plugins are found in your application the following routes are created:
*
* - `/:plugin` a plugin shortcut route.
* - `/:plugin/:action/*` a plugin shortcut route.
* - `/:plugin/:controller`
* - `/:plugin/:controller/:action/*`
*
* And lastly the following catch-all routes are connected.
*
* - `/:controller'
* - `/:controller/:action/*'
*
* A prefix route is generated for each Routing.prefixes declared in core.php. You can disable the
* connection of default routes with Router::defaults().
* You can disable the connection of default routes with Router::defaults().
*
* @return void
* @access private
@ -560,7 +572,8 @@ class Router {
foreach ($plugins as $key => $value) {
$plugins[$key] = Inflector::underscore($value);
}
$match = array('plugin' => implode('|', $plugins));
$pluginPattern = implode('|', $plugins);
$match = array('plugin' => $pluginPattern);
foreach ($this->__prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
@ -568,6 +581,8 @@ class Router {
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
$shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern);
$this->connect('/:plugin', array('action' => 'index'), $shortParams);
$this->connect('/:plugin/:controller', array('action' => 'index'), $match);
$this->connect('/:plugin/:controller/:action/*', array(), $match);
}
@ -907,7 +922,7 @@ class Router {
$urlOut = array_filter(array($url['controller'], $url['action']));
if (isset($url['plugin']) && $url['plugin'] != $url['controller']) {
if (isset($url['plugin'])) {
array_unshift($urlOut, $url['plugin']);
}
@ -1406,6 +1421,7 @@ class CakeRoute {
$route['pass'] = $route['named'] = array();
$route += $this->defaults;
//move numerically indexed elements from the defaults into pass.
foreach ($route as $key => $value) {
if (is_integer($key)) {
$route['pass'][] = $value;
@ -1523,10 +1539,6 @@ class CakeRoute {
* @return string Composed route string.
*/
protected function _writeUrl($params) {
if (isset($params['plugin'], $params['controller']) && $params['plugin'] === $params['controller']) {
unset($params['controller']);
}
if (isset($params['prefix'], $params['action'])) {
$params['action'] = str_replace($params['prefix'] . '_', '', $params['action']);
unset($params['prefix']);
@ -1568,4 +1580,47 @@ class CakeRoute {
return $out;
}
}
/**
* Plugin short route, that copies the plugin param to the controller parameters
* It is used for supporting /:plugin routes.
*
* @package cake.libs
*/
class PluginShortRoute extends CakeRoute {
/**
* Parses a string url into an array. If a plugin key is found, it will be copied to the
* controller parameter
*
* @param string $url The url to parse
* @return mixed false on failure, or an array of request parameters
*/
public function parse($url) {
$params = parent::parse($url);
if (!$params) {
return false;
}
$params['controller'] = $params['plugin'];
return $params;
}
/**
* Reverse route plugin shortcut urls. If the plugin and controller
* are not the same the match is an auto fail.
*
* @param array $url Array of parameters to convert to a string.
* @return mixed either false or a string url.
*/
public function match($url) {
if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] != $url['controller']) {
return false;
}
$this->defaults['controller'] = $url['controller'];
$result = parent::match($url);
unset($this->defaults['controller']);
return $result;
}
}
?>

View file

@ -241,7 +241,8 @@ class Helper {
Configure::read('Asset.timestamp') === 'force'
);
if (strpos($path, '?') === false && $timestampEnabled) {
$path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
$filepath = preg_replace('/^' . preg_quote($this->webroot, '/') . '/', '', $path);
$path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $filepath));
}
return $path;
}

View file

@ -1406,6 +1406,9 @@ class FormHelper extends AppHelper {
$escapeOptions = $attributes['escape'];
unset($attributes['escape']);
}
if (isset($attributes['secure'])) {
$secure = $attributes['secure'];
}
if (isset($attributes['empty'])) {
$showEmpty = $attributes['empty'];
unset($attributes['empty']);
@ -1446,7 +1449,9 @@ class FormHelper extends AppHelper {
}
if (!empty($tag) || isset($template)) {
if (!isset($secure) || $secure == true) {
$this->__secure();
}
$select[] = sprintf($tag, $attributes['name'], $this->_parseAttributes(
$attributes, array('name', 'value'))
);

View file

@ -357,7 +357,7 @@ class HtmlHelper extends AppHelper {
$path .= '.css';
}
}
$url = $this->webroot($this->assetTimestamp($path));
$url = $this->assetTimestamp($this->webroot($path));
if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL);
@ -433,7 +433,7 @@ class HtmlHelper extends AppHelper {
if (strpos($url, '?') === false && strpos($url, '.js') === false) {
$url .= '.js';
}
$url = $this->webroot($this->assetTimestamp($url));
$url = $this->assetTimestamp($this->webroot($url));
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
@ -606,7 +606,7 @@ class HtmlHelper extends AppHelper {
if ($path[0] !== '/') {
$path = IMAGES_URL . $path;
}
$path = $this->webroot($this->assetTimestamp($path));
$path = $this->assetTimestamp($this->webroot($path));
}
if (!isset($options['alt'])) {

View file

@ -264,7 +264,7 @@ class JavascriptHelper extends AppHelper {
$url .= '.js';
}
}
$url = $this->webroot($this->assetTimestamp($url));
$url = $this->assetTimestamp($this->webroot($url));
if (Configure::read('Asset.filter.js')) {
$pos = strpos($url, JS_URL);

View file

@ -325,6 +325,14 @@ class ArticlesTestController extends ArticlesTestAppController {
public function admin_index() {
return true;
}
/**
* fake index method.
*
* @return void
*/
function index() {
return true;
}
}
/**
@ -1354,11 +1362,9 @@ class DispatcherTest extends CakeTestCase {
$Router =& Router::getInstance();
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'TestDispatchPages';
$this->assertEqual($expected, $controller->name);
$this->assertEqual($controller->name, 'TestDispatchPages');
$expected = array('param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs);
$this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
$this->assertTrue($controller->params['admin']);
$expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
@ -1379,7 +1385,10 @@ class DispatcherTest extends CakeTestCase {
Router::reload();
$Dispatcher =& new TestDispatcher();
Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
Router::connect(
'/my_plugin/:controller/*',
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
);
$Dispatcher->base = false;
$url = 'my_plugin/some_pages/home/param:value/param2:value2';
@ -1397,17 +1406,10 @@ class DispatcherTest extends CakeTestCase {
$this->assertEqual($expected, $result);
$expected = 'my_plugin';
$this->assertIdentical($expected, $controller->plugin);
$expected = 'SomePages';
$this->assertIdentical($expected, $controller->name);
$expected = 'some_pages';
$this->assertIdentical($expected, $controller->params['controller']);
$expected = array('0' => 'home', 'param'=>'value', 'param2'=>'value2');
$this->assertIdentical($expected, $controller->passedArgs);
$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'));
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/home/param:value/param2:value2';
$this->assertIdentical($expected, $controller->here);
@ -1427,24 +1429,20 @@ class DispatcherTest extends CakeTestCase {
Router::reload();
$Dispatcher =& new TestDispatcher();
Router::connect('/my_plugin/:controller/:action/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
Router::connect(
'/my_plugin/:controller/:action/*',
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
);
$Dispatcher->base = false;
$url = 'my_plugin/other_pages/index/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'my_plugin';
$this->assertIdentical($expected, $controller->plugin);
$expected = 'OtherPages';
$this->assertIdentical($expected, $controller->name);
$expected = 'index';
$this->assertIdentical($expected, $controller->action);
$expected = array('param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs);
$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'));
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
$this->assertIdentical($expected, $controller->here);
@ -1462,6 +1460,13 @@ class DispatcherTest extends CakeTestCase {
$_POST = array();
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
$plugins = App::objects('plugin');
$plugins[] = 'MyPlugin';
$plugins[] = 'ArticlesTest';
$app = App::getInstance();
$app->__objects['plugin'] = $plugins;
Router::reload();
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
@ -1480,7 +1485,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
/* Simulates the Route for a real plugin, installed in APP/plugins */
// Simulates the Route for a real plugin, installed in APP/plugins
Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
$plugin = 'MyPlugin';
@ -1488,15 +1493,9 @@ class DispatcherTest extends CakeTestCase {
$url = $pluginUrl;
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = $pluginUrl;
$this->assertIdentical($controller->plugin, $expected);
$expected = $plugin;
$this->assertIdentical($controller->name, $expected);
$expected = 'index';
$this->assertIdentical($controller->action, $expected);
$this->assertIdentical($controller->plugin, 'my_plugin');
$this->assertIdentical($controller->name, 'MyPlugin');
$this->assertIdentical($controller->action, 'index');
$expected = $pluginUrl;
$this->assertEqual($controller->params['controller'], $expected);
@ -1511,37 +1510,40 @@ class DispatcherTest extends CakeTestCase {
$url = 'admin/my_plugin/add/5/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'my_plugin';
$this->assertIdentical($controller->plugin, $expected);
$expected = 'MyPlugin';
$this->assertIdentical($controller->name, $expected);
$expected = 'admin_add';
$this->assertIdentical($controller->action, $expected);
$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'));
$this->assertIdentical($controller->plugin, 'my_plugin');
$this->assertIdentical($controller->name, 'MyPlugin');
$this->assertIdentical($controller->action, 'admin_add');
$expected = array(0 => 5, 'param'=>'value', 'param2'=>'value2');
$this->assertEqual($controller->passedArgs, $expected);
Configure::write('Routing.prefixes', array('admin'));
Router::reload();
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
$controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
$expected = 'articles_test';
$this->assertIdentical($controller->plugin, $expected);
$expected = 'ArticlesTest';
$this->assertIdentical($controller->name, $expected);
$expected = 'admin_index';
$this->assertIdentical($controller->action, $expected);
$this->assertIdentical($controller->plugin, 'articles_test');
$this->assertIdentical($controller->name, 'ArticlesTest');
$this->assertIdentical($controller->action, 'admin_index');
$expected = array(
'pass'=> array(), 'named' => array(), 'controller' => 'articles_test', 'plugin' => 'articles_test', 'action' => 'admin_index',
'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/articles_test'), 'return' => 1
'pass'=> array(),
'named' => array(),
'controller' => 'articles_test',
'plugin' => 'articles_test',
'action' => 'admin_index',
'prefix' => 'admin',
'admin' => true,
'form' => array(),
'url' => array('url' => 'admin/articles_test'),
'return' => 1
);
$this->assertEqual($controller->params, $expected);
}
@ -1555,9 +1557,13 @@ class DispatcherTest extends CakeTestCase {
public function testAutomaticPluginDispatchWithShortAccess() {
$_POST = array();
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
$plugins = App::objects('plugin');
$plugins[] = 'MyPlugin';
$app = App::getInstance();
$app->__objects['plugin'] = $plugins;
Router::reload();
Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
@ -1586,6 +1592,9 @@ class DispatcherTest extends CakeTestCase {
$url = 'my_plugin/add';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertFalse(isset($controller->params['pass'][0]));
$this->assertEqual($controller->params['controller'], 'my_plugin');
$this->assertEqual($controller->params['action'], 'add');
$this->assertEqual($controller->params['plugin'], 'my_plugin');
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;

View file

@ -789,6 +789,14 @@ class DboPostgresTest extends CakeTestCase {
$result = $this->db->fields($Article, null, array('COUNT(DISTINCT Article.id)'));
$expected = array('COUNT(DISTINCT "Article"."id")');
$this->assertEqual($result, $expected);
$result = $this->db->fields($Article, null, array('COUNT(DISTINCT id)'));
$expected = array('COUNT(DISTINCT "id")');
$this->assertEqual($result, $expected);
$result = $this->db->fields($Article, null, array('COUNT(DISTINCT FUNC(id))'));
$expected = array('COUNT(DISTINCT FUNC("id"))');
$this->assertEqual($result, $expected);
}
}
?>

View file

@ -17,7 +17,7 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Core', array('Router', 'Debugger'));
App::import('Core', array('Router'));
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', 'http://cakephp.org');
@ -741,31 +741,10 @@ class RouterTest extends CakeTestCase {
'lang' => 'en',
'controller' => 'shows', 'action' => 'index', 'page' => '1',
));
$expected = '/en/shows/page:1';
$expected = '/en/shows/shows/page:1';
$this->assertEqual($result, $expected);
}
/**
* test that plugin short cut routes behave properly. Parse and reverse route correctly.
*
* @return void
*/
function testPluginShortcutRoutes() {
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
$this->assertEqual($result, '/test_plugin', 'Plugin shortcut index action failed.');
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'view', 1));
$this->assertEqual($result, '/test_plugin/view/1', 'Plugin shortcut with passed args failed.');
$result = Router::url(array(
'plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'view',
1, 'sort' => 'title', 'dir' => 'asc'
));
$this->assertEqual(
$result, '/test_plugin/view/1/sort:title/dir:asc', 'Plugin shortcut with passed + named args failed.'
);
}
/**
* test that you can leave active plugin routes with plugin = null
*
@ -1146,7 +1125,7 @@ class RouterTest extends CakeTestCase {
Router::parse('/');
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
$expected = '/admin/test_plugin';
$expected = '/admin/test_plugin/test_plugin';
$this->assertEqual($result, $expected);
Router::reload();
@ -1960,6 +1939,7 @@ class RouterTest extends CakeTestCase {
)
), true);
App::objects('plugin', null, false);
Router::reload();
$plugins = App::objects('plugin');
$plugin = Inflector::underscore($plugins[0]);
@ -1972,6 +1952,17 @@ class RouterTest extends CakeTestCase {
'named' => array(), 'pass' => array()
);
$this->assertEqual($result, $expected);
$result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
$this->assertEqual($result, '/test_plugin');
$result = Router::parse('/test_plugin');
$expected = array(
'plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index',
'named' => array(), 'pass' => array()
);
$this->assertEqual($result, $expected, 'Plugin shortcut route broken. %s');
}
/**
@ -2433,4 +2424,64 @@ class CakeRouteTestCase extends CakeTestCase {
}
}
/**
* test case for PluginShortRoute
*
* @package cake.tests.libs
*/
class PluginShortRouteTestCase extends CakeTestCase {
/**
* startTest method
*
* @access public
* @return void
*/
function startTest() {
$this->_routing = Configure::read('Routing');
Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
Router::reload();
}
/**
* end the test and reset the environment
*
* @return void
**/
function endTest() {
Configure::write('Routing', $this->_routing);
}
/**
* test the parsing of routes.
*
* @return void
*/
function testParsing() {
$route =& new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
$result = $route->parse('/foo');
$this->assertEqual($result['plugin'], 'foo');
$this->assertEqual($result['controller'], 'foo');
$this->assertEqual($result['action'], 'index');
$result = $route->parse('/wrong');
$this->assertFalse($result, 'Wrong plugin name matched %s');
}
/**
* test the reverse routing of the plugin shortcut urls.
*
* @return void
*/
function testMatch() {
$route =& new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
$result = $route->match(array('plugin' => 'foo', 'controller' => 'posts', 'action' => 'index'));
$this->assertFalse($result, 'plugin controller mismatch was converted. %s');
$result = $route->match(array('plugin' => 'foo', 'controller' => 'foo', 'action' => 'index'));
$this->assertEqual($result, '/foo');
}
}
?>

View file

@ -1782,7 +1782,7 @@ class ValidationTest extends CakeTestCase {
*
* @return void
*/
public function testIpBoth() {
function testIpBoth() {
$this->assertTrue(Validation::ip('0.0.0.0'));
$this->assertTrue(Validation::ip('192.168.1.156'));
$this->assertTrue(Validation::ip('255.255.255.255'));
@ -1873,6 +1873,7 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://www.jaist.ac.jp/~hoangle/filesj/index.html'));
$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));

View file

@ -467,6 +467,10 @@ class HelperTest extends CakeTestCase {
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
$this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam');
$this->Helper->webroot = '/some/dir/';
$result = $this->Helper->assetTimestamp('/some/dir/' . CSS_URL . 'cake.generic.css');
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
Configure::write('debug', $_debug);
Configure::write('Asset.timestamp', $_timestamp);
}

View file

@ -1224,6 +1224,31 @@ class FormHelperTest extends CakeTestCase {
$this->assertEqual($this->Form->fields, $expected);
}
/**
* testDisableSecurityUsingForm method
*
* @access public
* @return void
*/
function testDisableSecurityUsingForm() {
$this->Form->params['_Token']['key'] = 'testKey';
$this->Form->params['_Token']['disabledFields'] = array();
$this->Form->create();
$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name', array('secure' => false));
$this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
$this->Form->input('Addresses.zip', array(
'type' => 'select', 'options' => array(1,2), 'secure' => false
));
$result = $this->Form->fields;
$expected = array(
'Addresses.id' => '123456', 'Addresses.title',
);
$this->assertEqual($result, $expected);
}
/**
* testPasswordValidation method
*

View file

@ -304,14 +304,15 @@ class HtmlHelperTest extends CakeTestCase {
function testImageWithTimestampping() {
Configure::write('Asset.timestamp', 'force');
$this->Html->webroot = '/';
$result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
Configure::write('debug', 0);
Configure::write('Asset.timestamp', 'force');
$result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));
$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/longer/';
@ -331,30 +332,42 @@ class HtmlHelperTest extends CakeTestCase {
* @link https://trac.cakephp.org/ticket/6490
*/
function testImageTagWithTheme() {
if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) {
return;
}
App::import('Core', 'File');
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
$file =& new File($testfile, true);
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
Configure::write('Asset.timestamp', true);
Configure::write('debug', 1);
$this->Html->webroot = '/';
$this->Html->theme = 'test_theme';
$result = $this->Html->image('cake.power.gif');
$result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array(
'img' => array(
'src' => 'preg:/theme\/test_theme\/img\/cake\.power\.gif\?\d+/',
'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
)));
$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/';
$result = $this->Html->image('cake.power.gif');
$result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array(
'img' => array(
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/cake\.power\.gif\?\d+/',
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
)));
$this->Html->webroot = $webroot;
$dir =& new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
$dir->delete();
}
/**
@ -364,6 +377,7 @@ class HtmlHelperTest extends CakeTestCase {
* @return void
*/
function testThemeAssetsInMainWebrootPath() {
Configure::write('Asset.timestamp', false);
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
@ -542,6 +556,7 @@ class HtmlHelperTest extends CakeTestCase {
* @return void
*/
function testScript() {
Configure::write('Asset.timestamp', false);
$result = $this->Html->script('foo');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js')

View file

@ -218,29 +218,6 @@ class PaginatorHelperTest extends CakeTestCase {
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
}
/**
* test sort() works with plugin shortcut routes.
*
* @return void
*/
function testSortWithPluginShortcuts() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'something', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'test_plugin/something')),
array('base' => '/', 'here' => '/test_plugin/', 'webroot' => '/')
));
$result = $this->Paginator->sort('title');
$expected = array(
'a' => array('href' => '/test_plugin/something/page:1/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testSortLinksUsingDirectionOption method
*