Skip to content
Browse files

Merge branch '1.3-misc' into 1.3-misc-plugin-datasources

  • Loading branch information...
2 parents c3cd98a + 23954a4 commit 7e5fe04a77841d811a49556bdd9914ef17f1f2a7 @jperras jperras committed
Showing with 698 additions and 248 deletions.
  1. 0 app/views/pages/empty
  2. 0 app/webroot/files/empty
  3. +1 −1 cake/basics.php
  4. +2 −2 cake/console/libs/api.php
  5. +21 −10 cake/console/libs/schema.php
  6. +3 −3 cake/console/libs/tasks/controller.php
  7. +6 −6 cake/console/libs/tasks/db_config.php
  8. +1 −1 cake/console/libs/tasks/fixture.php
  9. +3 −3 cake/console/libs/tasks/model.php
  10. +1 −1 cake/console/libs/tasks/project.php
  11. +25 −0 cake/console/libs/tasks/test.php
  12. +31 −25 cake/console/libs/tasks/view.php
  13. +16 −16 cake/console/templates/default/actions/controller_actions.ctp
  14. +56 −49 cake/libs/controller/components/auth.php
  15. +5 −3 cake/libs/model/cake_schema.php
  16. +19 −0 cake/libs/view/helper.php
  17. +7 −30 cake/libs/view/helpers/html.php
  18. +1 −10 cake/libs/view/helpers/javascript.php
  19. +13 −7 cake/libs/view/helpers/jquery_engine.php
  20. +18 −4 cake/libs/view/helpers/js.php
  21. +36 −2 cake/libs/view/helpers/paginator.php
  22. +30 −2 cake/tests/cases/console/libs/schema.test.php
  23. +5 −5 cake/tests/cases/console/libs/tasks/controller.test.php
  24. +27 −8 cake/tests/cases/console/libs/tasks/view.test.php
  25. +1 −1 cake/tests/cases/libs/cake_log.test.php
  26. +182 −40 cake/tests/cases/libs/controller/components/auth.test.php
  27. +8 −6 cake/tests/cases/libs/router.test.php
  28. +35 −0 cake/tests/cases/libs/view/helper.test.php
  29. +41 −7 cake/tests/cases/libs/view/helpers/html.test.php
  30. +2 −2 cake/tests/cases/libs/view/helpers/javascript.test.php
  31. +8 −2 cake/tests/cases/libs/view/helpers/jquery_engine.test.php
  32. +11 −0 cake/tests/cases/libs/view/helpers/js.test.php
  33. +30 −2 cake/tests/cases/libs/view/helpers/paginator.test.php
  34. +1 −0 cake/tests/groups/database.group.php
  35. +52 −0 cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php
View
0 app/views/pages/empty
No changes.
View
0 app/webroot/files/empty
No changes.
View
2 cake/basics.php
@@ -490,7 +490,7 @@ function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
$expires = strtotime($expires, $now);
}
- switch (low($target)) {
+ switch (strtolower($target)) {
case 'cache':
$filename = CACHE . $path;
break;
View
4 cake/console/libs/api.php
@@ -173,8 +173,8 @@ function help() {
foreach ($commands as $cmd) {
$this->out("{$cmd}\n\n");
}
- } elseif (isset($commands[low($this->args[1])])) {
- $this->out($commands[low($this->args[1])] . "\n\n");
+ } elseif (isset($commands[strtolower($this->args[1])])) {
+ $this->out($commands[strtolower($this->args[1])] . "\n\n");
} else {
$this->out("Command '" . $this->args[1] . "' not found");
}
View
31 cake/console/libs/schema.php
@@ -58,18 +58,12 @@ function initialize() {
* @access public
*/
function startup() {
- $name = null;
+ $name = $file = $path = $connection = null;
if (!empty($this->params['name'])) {
$name = $this->params['name'];
$this->params['file'] = Inflector::underscore($name);
}
-
- $path = null;
- if (!empty($this->params['path'])) {
- $path = $this->params['path'];
- }
-
- $file = null;
+ $path = $this->_getPath();
if (empty($this->params['file'])) {
$this->params['file'] = 'schema.php';
}
@@ -78,7 +72,6 @@ function startup() {
}
$file = $this->params['file'];
- $connection = null;
if (!empty($this->params['connection'])) {
$connection = $this->params['connection'];
}
@@ -87,6 +80,23 @@ function startup() {
}
/**
+ * Get the correct path for the params. Uses path, and plugin to find the correct path.
+ * path param takes precedence over any plugins specified.
+ *
+ * @return mixed string to correct path or null.
+ **/
+ function _getPath() {
+ if (!empty($this->params['path'])) {
+ return $this->params['path'];
+ }
+ if (!empty($this->params['plugin'])) {
+ $pluginPath = $this->_pluginPath($this->params['plugin']);
+ return $pluginPath . 'config' . DS . 'schema' . DS;
+ }
+ return null;
+ }
+
+/**
* Override main
*
* @access public
@@ -107,7 +117,8 @@ function view() {
$this->out($File->read());
$this->_stop();
} else {
- $this->err(__('Schema could not be found', true));
+ $file = $this->Schema->path . DS . $this->params['file'];
+ $this->err(sprintf(__('Schema file (%s) could not be found.', true), $file));
$this->_stop();
}
}
View
6 cake/console/libs/tasks/controller.php
@@ -92,7 +92,7 @@ function execute() {
$actions= $this->bakeActions($controller, $admin);
}
}
-
+
if (!empty($this->args[2]) && $this->args[2] == 'admin') {
$admin = $this->Project->getAdmin();
if ($admin) {
@@ -294,8 +294,8 @@ function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
$controllerPath = $this->_controllerPath($controllerName);
$pluralName = $this->_pluralName($currentModelName);
$singularName = Inflector::variable($currentModelName);
- $singularHumanName = Inflector::humanize($currentModelName);
- $pluralHumanName = Inflector::humanize($controllerName);
+ $singularHumanName = $this->_singularHumanName($currentModelName);
+ $pluralHumanName = $this->_pluralName($controllerName);
$this->Template->set(compact('admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName',
'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName'));
View
12 cake/console/libs/tasks/db_config.php
@@ -108,7 +108,7 @@ function __interactive() {
$driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
- if (low($persistent) == 'n') {
+ if (strtolower($persistent) == 'n') {
$persistent = 'false';
} else {
$persistent = 'true';
@@ -124,7 +124,7 @@ function __interactive() {
$port = $this->in('Port?', null, 'n');
}
- if (low($port) == 'n') {
+ if (strtolower($port) == 'n') {
$port = null;
}
@@ -155,7 +155,7 @@ function __interactive() {
while ($prefix == '') {
$prefix = $this->in('Table Prefix?', null, 'n');
}
- if (low($prefix) == 'n') {
+ if (strtolower($prefix) == 'n') {
$prefix = null;
}
@@ -163,7 +163,7 @@ function __interactive() {
while ($encoding == '') {
$encoding = $this->in('Table encoding?', null, 'n');
}
- if (low($encoding) == 'n') {
+ if (strtolower($encoding) == 'n') {
$encoding = null;
}
@@ -173,7 +173,7 @@ function __interactive() {
$schema = $this->in('Table schema?', null, 'n');
}
}
- if (low($schema) == 'n') {
+ if (strtolower($schema) == 'n') {
$schema = null;
}
@@ -185,7 +185,7 @@ function __interactive() {
$dbConfigs[] = $config;
$doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');
- if (low($doneYet == 'n')) {
+ if (strtolower($doneYet == 'n')) {
$done = true;
}
}
View
2 cake/console/libs/tasks/fixture.php
@@ -419,7 +419,7 @@ function help() {
$this->out('Parameters:');
$this->out("\t-count When using generated data, the number of records to include in the fixture(s).");
$this->out("\t-connection Which database configuration to use for baking.");
- $this->out("\t-plugin lowercased_underscored name of plugin to bake fixtures for.");
+ $this->out("\t-plugin CamelCased name of plugin to bake fixtures for.");
$this->out("");
$this->_stop();
}
View
6 cake/console/libs/tasks/model.php
@@ -405,7 +405,7 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
$guess = $methods['numeric'];
} elseif ($metaData['type'] == 'boolean') {
$guess = $methods['boolean'];
- } elseif ($metaData['type'] == 'datetime' || $metaData['type'] == 'date') {
+ } elseif ($metaData['type'] == 'date') {
$guess = $methods['date'];
} elseif ($metaData['type'] == 'time') {
$guess = $methods['time'];
@@ -614,7 +614,7 @@ function confirmAssociations(&$model, $associations) {
$prompt = "{$model->name} {$type} {$associations[$type][$i]['alias']}";
$response = $this->in("{$prompt}?", array('y','n'), 'y');
- if ('n' == low($response)) {
+ if ('n' == strtolower($response)) {
unset($associations[$type][$i]);
} elseif ($type == 'hasMany') {
unset($associations['hasOne'][$i]);
@@ -637,7 +637,7 @@ function doMoreAssociations($model, $associations) {
$prompt = __('Would you like to define some additional model associations?', true);
$wannaDoMoreAssoc = $this->in($prompt, array('y','n'), 'n');
$possibleKeys = $this->_generatePossibleKeys();
- while (low($wannaDoMoreAssoc) == 'y') {
+ while (strtolower($wannaDoMoreAssoc) == 'y') {
$assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
$this->out(__('What is the association type?', true));
$assocType = intval($this->inOptions($assocs, __('Enter a number',true)));
View
2 cake/console/libs/tasks/project.php
@@ -184,7 +184,7 @@ function bake($path, $skel = null, $skip = array('empty')) {
function createHome($dir) {
$app = basename($dir);
$path = $dir . 'views' . DS . 'pages' . DS;
- $source = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp';
+ $source = CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp';
include($source);
return $this->createFile($path.'home.ctp', $output);
}
View
25 cake/console/libs/tasks/test.php
@@ -414,5 +414,30 @@ function testCaseFileName($type, $className) {
}
return $path . Inflector::underscore($className) . '.test.php';
}
+
+/**
+ * Show help file.
+ *
+ * @return void
+ **/
+ function help() {
+ $this->hr();
+ $this->out("Usage: cake bake test <type> <class>");
+ $this->hr();
+ $this->out('Commands:');
+ $this->out("");
+ $this->out("test model post\n\tbakes a test case for the post model.");
+ $this->out("");
+ $this->out("test controller comments\n\tbakes a test case for the comments controller.");
+ $this->out("");
+ $this->out('Arguments:');
+ $this->out("\t<type> Can be any of the following 'controller', 'model', 'helper',\n\t'component', 'behavior'.");
+ $this->out("\t<class> Any existing class for the chosen type.");
+ $this->out("");
+ $this->out("Parameters:");
+ $this->out("\t-plugin CamelCased name of plugin to bake tests for.");
+ $this->out("");
+ $this->_stop();
+ }
}
?>
View
56 cake/console/libs/tasks/view.php
@@ -284,9 +284,7 @@ function __loadController() {
$primaryKey = $modelObj->primaryKey;
$displayField = $modelObj->displayField;
$singularVar = Inflector::variable($modelClass);
- $pluralVar = Inflector::variable($this->controllerName);
- $singularHumanName = Inflector::humanize($modelClass);
- $pluralHumanName = Inflector::humanize($this->controllerName);
+ $singularHumanName = $this->_singularHumanName($modelClass);
$schema = $modelObj->schema();
$fields = array_keys($schema);
$associations = $this->__associations($modelObj);
@@ -294,13 +292,13 @@ function __loadController() {
$primaryKey = null;
$displayField = null;
$singularVar = Inflector::variable(Inflector::singularize($this->controllerName));
- $pluralVar = Inflector::variable($this->controllerName);
- $singularHumanName = Inflector::humanize(Inflector::singularize($this->controllerName));
- $pluralHumanName = Inflector::humanize($this->controllerName);
+ $singularHumanName = $this->_singularHumanName($this->controllerName);
$fields = array();
$schema = array();
$associations = array();
}
+ $pluralVar = Inflector::variable($this->controllerName);
+ $pluralHumanName = $this->_pluralHumanName($this->controllerName);
return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'fields','associations');
@@ -372,28 +370,12 @@ function bake($action, $content = '') {
/**
* Builds content from template and variables
*
- * @param string $template file to use
+ * @param string $action name to generate content to
* @param array $vars passed for use in templates
* @return string content from template
* @access public
*/
- function getContent($template = null, $vars = null) {
- if (!$template) {
- $template = $this->template;
- }
- $action = $template;
-
- $adminRoute = Configure::read('Routing.admin');
- if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
- $template = str_replace($adminRoute . '_', '', $template);
- }
- if (in_array($template, array('add', 'edit'))) {
- $action = $template;
- $template = 'form';
- } elseif (preg_match('@(_add|_edit)$@', $template)) {
- $action = $template;
- $template = str_replace(array('_add', '_edit'), '_form', $template);
- }
+ function getContent($action, $vars = null) {
if (!$vars) {
$vars = $this->__loadController();
}
@@ -401,7 +383,7 @@ function getContent($template = null, $vars = null) {
$this->Template->set('action', $action);
$this->Template->set('plugin', $this->plugin);
$this->Template->set($vars);
- $output = $this->Template->generate('views', $template);
+ $output = $this->Template->generate('views', $this->getTemplate($action));
if (!empty($output)) {
return $output;
@@ -410,6 +392,30 @@ function getContent($template = null, $vars = null) {
}
/**
+ * Gets the template name based on the action name
+ *
+ * @param string $action name
+ * @return string template name
+ * @access public
+ */
+ function getTemplate($action) {
+ if (!empty($this->template) && $action != $this->template) {
+ return $this->template;
+ }
+ $template = $action;
+ $adminRoute = Configure::read('Routing.admin');
+ if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
+ $template = str_replace($adminRoute . '_', '', $template);
+ }
+ if (in_array($template, array('add', 'edit'))) {
+ $template = 'form';
+ } elseif (preg_match('@(_add|_edit)$@', $template)) {
+ $template = str_replace(array('_add', '_edit'), '_form', $template);
+ }
+ return $template;
+ }
+
+/**
* Displays help contents
*
* @access public
View
32 cake/console/templates/default/actions/controller_actions.ctp
@@ -27,10 +27,10 @@
function <?php echo $admin ?>view($id = null) {
if (!$id) {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('Invalid <?php echo $singularHumanName ?>', true));
+ $this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName) ?>', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
- $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
+ $this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true), array('action' => 'index'));
<?php endif; ?>
}
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
@@ -42,14 +42,14 @@
$this-><?php echo $currentModelName; ?>->create();
if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
+ $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
- $this->flash(__('<?php echo $currentModelName; ?> saved.', true), array('action' => 'index'));
+ $this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.', true), array('action' => 'index'));
<?php endif; ?>
} else {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> could not be saved. Please, try again.', true));
+ $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.', true));
<?php endif; ?>
}
}
@@ -74,23 +74,23 @@
function <?php echo $admin; ?>edit($id = null) {
if (!$id && empty($this->data)) {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('Invalid <?php echo $singularHumanName; ?>', true));
+ $this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
- $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
+ $this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true), array('action' => 'index'));
<?php endif; ?>
}
if (!empty($this->data)) {
if ($this-><?php echo $currentModelName; ?>->save($this->data)) {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> has been saved', true));
+ $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved', true));
$this->redirect(array('action' => 'index'));
<?php else: ?>
- $this->flash(__('The <?php echo $singularHumanName; ?> has been saved.', true), array('action' => 'index'));
+ $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.', true), array('action' => 'index'));
<?php endif; ?>
} else {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('The <?php echo $singularHumanName; ?> could not be saved. Please, try again.', true));
+ $this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.', true));
<?php endif; ?>
}
}
@@ -117,24 +117,24 @@
function <?php echo $admin; ?>delete($id = null) {
if (!$id) {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('Invalid id for <?php echo $singularHumanName; ?>', true));
+ $this->Session->setFlash(__('Invalid id for <?php echo strtolower($singularHumanName); ?>', true));
$this->redirect(array('action'=>'index'));
<?php else: ?>
- $this->flash(__('Invalid <?php echo $singularHumanName; ?>', true), array('action' => 'index'));
+ $this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>', true), array('action' => 'index'));
<?php endif; ?>
}
if ($this-><?php echo $currentModelName; ?>->delete($id)) {
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('<?php echo $singularHumanName; ?> deleted', true));
+ $this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted', true));
$this->redirect(array('action'=>'index'));
<?php else: ?>
- $this->flash(__('<?php echo $singularHumanName; ?> deleted', true), array('action' => 'index'));
+ $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted', true), array('action' => 'index'));
<?php endif; ?>
}
<?php if ($wannaUseSession): ?>
- $this->Session->setFlash(__('<?php echo $singularHumanName; ?> was not deleted', true));
+ $this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted', true));
<?php else: ?>
- $this->flash(__('<?php echo $singularHumanName; ?> was not deleted', true), array('action' => 'index'));
+ $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted', true), array('action' => 'index'));
<?php endif; ?>
$this->redirect(array('action' => 'index'));
}
View
105 cake/libs/controller/components/auth.php
@@ -1,6 +1,4 @@
<?php
-/* SVN FILE: $Id$ */
-
/**
* Authentication component
*
@@ -9,24 +7,21 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.controller.components
* @since CakePHP(tm) v 0.10.0.1076
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
-App::import(array('Router', 'Security'));
+App::import('Core', array('Router', 'Security'), false);
/**
* Authentication control component class
@@ -85,6 +80,14 @@ class AuthComponent extends Object {
var $ajaxLogin = null;
/**
+ * The name of the layout element used on Session::setFlash
+ *
+ * @var string
+ * @access public
+ */
+ var $flashLayout = 'default';
+
+/**
* The name of the model that represents users which will be authenticated. Defaults to 'User'.
*
* @var string
@@ -330,23 +333,24 @@ function startup(&$controller) {
}
if ($loginAction == $url) {
- if (empty($controller->data) || !isset($controller->data[$this->userModel])) {
+ $model =& $this->getModel();
+ if (empty($controller->data) || !isset($controller->data[$model->alias])) {
if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) {
$this->Session->write('Auth.redirect', $controller->referer(null, true));
}
return false;
}
- $isValid = !empty($controller->data[$this->userModel][$this->fields['username']]) &&
- !empty($controller->data[$this->userModel][$this->fields['password']]);
+ $isValid = !empty($controller->data[$model->alias][$this->fields['username']]) &&
+ !empty($controller->data[$model->alias][$this->fields['password']]);
if ($isValid) {
- $username = $controller->data[$this->userModel][$this->fields['username']];
- $password = $controller->data[$this->userModel][$this->fields['password']];
+ $username = $controller->data[$model->alias][$this->fields['username']];
+ $password = $controller->data[$model->alias][$this->fields['password']];
$data = array(
- $this->userModel . '.' . $this->fields['username'] => $username,
- $this->userModel . '.' . $this->fields['password'] => $password
+ $model->alias . '.' . $this->fields['username'] => $username,
+ $model->alias . '.' . $this->fields['password'] => $password
);
if ($this->login($data)) {
@@ -357,13 +361,13 @@ function startup(&$controller) {
}
}
- $this->Session->setFlash($this->loginError, 'default', array(), 'auth');
- $controller->data[$this->userModel][$this->fields['password']] = null;
+ $this->Session->setFlash($this->loginError, $this->flashLayout, array(), 'auth');
+ $controller->data[$model->alias][$this->fields['password']] = null;
return false;
} else {
if (!$this->user()) {
if (!$this->RequestHandler->isAjax()) {
- $this->Session->setFlash($this->authError, 'default', array(), 'auth');
+ $this->Session->setFlash($this->authError, $this->flashLayout, array(), 'auth');
if (!empty($controller->params['url']) && count($controller->params['url']) >= 2) {
$query = $controller->params['url'];
unset($query['url'], $query['ext']);
@@ -427,7 +431,7 @@ function startup(&$controller) {
return true;
}
- $this->Session->setFlash($this->authError, 'default', array(), 'auth');
+ $this->Session->setFlash($this->authError, $this->flashLayout, array(), 'auth');
$controller->redirect($controller->referer(), null, true);
return false;
}
@@ -582,7 +586,7 @@ function __authType($auth = null) {
* Takes a list of actions in the current controller for which authentication is not required, or
* no parameters to allow all actions.
*
- * @param string $action Controller action name
+ * @param mixed $action Controller action name or array of actions
* @param string $action Controller action name
* @param string ... etc.
* @return void
@@ -596,14 +600,14 @@ function allow() {
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
- $this->allowedActions = array_merge($this->allowedActions, $args);
+ $this->allowedActions = array_merge($this->allowedActions, array_map('strtolower', $args));
}
}
/**
* Removes items from the list of allowed actions.
*
- * @param string $action Controller action name
+ * @param mixed $action Controller action name or array of actions
* @param string $action Controller action name
* @param string ... etc.
* @return void
@@ -612,8 +616,11 @@ function allow() {
*/
function deny() {
$args = func_get_args();
+ if (isset($args[0]) && is_array($args[0])) {
+ $args = $args[0];
+ }
foreach ($args as $arg) {
- $i = array_search($arg, $this->allowedActions);
+ $i = array_search(strtolower($arg), $this->allowedActions);
if (is_int($i)) {
unset($this->allowedActions[$i]);
}
@@ -698,7 +705,8 @@ function user($key = null) {
}
if ($key == null) {
- return array($this->userModel => $this->Session->read($this->sessionKey));
+ $model =& $this->getModel();
+ return array($model->alias => $this->Session->read($this->sessionKey));
} else {
$user = $this->Session->read($this->sessionKey);
if (isset($user[$key])) {
@@ -764,10 +772,11 @@ function validate($object, $user = null, $action = null) {
* @return boolean ACO node path
* @access public
*/
- function action($action = ':controller/:action') {
+ function action($action = ':plugin/:controller/:action') {
+ $plugin = empty($this->params['plugin']) ? null : Inflector::camelize($this->params['plugin']) . '/';
return str_replace(
- array(':controller', ':action'),
- array(Inflector::camelize($this->params['controller']), $this->params['action']),
+ array(':controller', ':action', ':plugin/'),
+ array(Inflector::camelize($this->params['controller']), $this->params['action'], $plugin),
$this->actionPath . $action
);
}
@@ -817,6 +826,7 @@ function identify($user = null, $conditions = null) {
} else {
$conditions = $this->userScope;
}
+ $model =& $this->getModel();
if (empty($user)) {
$user = $this->user();
if (empty($user)) {
@@ -827,51 +837,47 @@ function identify($user = null, $conditions = null) {
return null;
}
$user = $user->read();
- $user = $user[$this->userModel];
- } elseif (is_array($user) && isset($user[$this->userModel])) {
- $user = $user[$this->userModel];
+ $user = $user[$model->alias];
+ } elseif (is_array($user) && isset($user[$model->alias])) {
+ $user = $user[$model->alias];
}
- if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$this->userModel . '.' . $this->fields['username']]))) {
-
+ if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$model->alias . '.' . $this->fields['username']]))) {
if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']]) && !empty($user[$this->fields['password']])) {
if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') {
return false;
}
$find = array(
- $this->userModel.'.'.$this->fields['username'] => $user[$this->fields['username']],
- $this->userModel.'.'.$this->fields['password'] => $user[$this->fields['password']]
+ $model->alias.'.'.$this->fields['username'] => $user[$this->fields['username']],
+ $model->alias.'.'.$this->fields['password'] => $user[$this->fields['password']]
);
- } elseif (isset($user[$this->userModel . '.' . $this->fields['username']]) && !empty($user[$this->userModel . '.' . $this->fields['username']])) {
- if (trim($user[$this->userModel . '.' . $this->fields['username']]) == '=' || trim($user[$this->userModel . '.' . $this->fields['password']]) == '=') {
+ } elseif (isset($user[$model->alias . '.' . $this->fields['username']]) && !empty($user[$model->alias . '.' . $this->fields['username']])) {
+ if (trim($user[$model->alias . '.' . $this->fields['username']]) == '=' || trim($user[$model->alias . '.' . $this->fields['password']]) == '=') {
return false;
}
$find = array(
- $this->userModel.'.'.$this->fields['username'] => $user[$this->userModel . '.' . $this->fields['username']],
- $this->userModel.'.'.$this->fields['password'] => $user[$this->userModel . '.' . $this->fields['password']]
+ $model->alias.'.'.$this->fields['username'] => $user[$model->alias . '.' . $this->fields['username']],
+ $model->alias.'.'.$this->fields['password'] => $user[$model->alias . '.' . $this->fields['password']]
);
} else {
return false;
}
- $model =& $this->getModel();
$data = $model->find(array_merge($find, $conditions), null, null, 0);
- if (empty($data) || empty($data[$this->userModel])) {
+ if (empty($data) || empty($data[$model->alias])) {
return null;
}
} elseif (!empty($user) && is_string($user)) {
- $model =& $this->getModel();
$data = $model->find(array_merge(array($model->escapeField() => $user), $conditions));
-
- if (empty($data) || empty($data[$this->userModel])) {
+ if (empty($data) || empty($data[$model->alias])) {
return null;
}
}
if (!empty($data)) {
- if (!empty($data[$this->userModel][$this->fields['password']])) {
- unset($data[$this->userModel][$this->fields['password']]);
+ if (!empty($data[$model->alias][$this->fields['password']])) {
+ unset($data[$model->alias][$this->fields['password']]);
}
- return $data[$this->userModel];
+ return $data[$model->alias];
}
return null;
}
@@ -888,9 +894,10 @@ function hashPasswords($data) {
return $this->authenticate->hashPasswords($data);
}
- if (is_array($data) && isset($data[$this->userModel])) {
- if (isset($data[$this->userModel][$this->fields['username']]) && isset($data[$this->userModel][$this->fields['password']])) {
- $data[$this->userModel][$this->fields['password']] = $this->password($data[$this->userModel][$this->fields['password']]);
+ $model =& $this->getModel();
+ if (is_array($data) && isset($data[$model->alias])) {
+ if (isset($data[$model->alias][$this->fields['username']]) && isset($data[$model->alias][$this->fields['password']])) {
+ $data[$model->alias][$this->fields['password']] = $this->password($data[$model->alias][$this->fields['password']]);
}
}
return $data;
View
8 cake/libs/model/cake_schema.php
@@ -90,7 +90,11 @@ function __construct($options = array()) {
}
if (empty($options['path'])) {
- $this->path = CONFIGS . 'schema';
+ if (is_dir(CONFIGS . 'schema')) {
+ $this->path = CONFIGS . 'schema';
+ } else {
+ $this->path = CONFIGS . 'sql';
+ }
}
$options = array_merge(get_object_vars($this), $options);
@@ -239,8 +243,6 @@ function read($options = array()) {
foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) {
if (isset($assocData['with'])) {
$class = $assocData['with'];
- } elseif ($assocData['_with']) {
- $class = $assocData['_with'];
}
if (is_object($Object->$class)) {
$table = $db->fullTableName($Object->$class, false);
View
19 cake/libs/view/helper.php
@@ -225,6 +225,25 @@ function webroot($file) {
}
/**
+ * Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
+ * Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force'
+ * a timestamp will be added.
+ *
+ * @param string $path The file path to timestamp, the path must be inside WWW_ROOT
+ * @return string Path with a timestamp added, or not.
+ **/
+ function assetTimestamp($path) {
+ $timestampEnabled = (
+ (Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
+ Configure::read('Asset.timestamp') === 'force'
+ );
+ if (strpos($path, '?') === false && $timestampEnabled) {
+ $path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
+ }
+ return $path;
+ }
+
+/**
* Used to remove harmful tags from content
*
* @param mixed $output
View
37 cake/libs/view/helpers/html.php
@@ -373,17 +373,7 @@ function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
$path .= '.css';
}
}
-
- $path = $this->webroot($path);
-
- $url = $path;
- $timestampEnabled = (
- (Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
- Configure::read('Asset.timestamp') === 'force'
- );
- if (strpos($path, '?') === false && $timestampEnabled) {
- $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
- }
+ $url = $this->webroot($this->assetTimestamp($path));
if (Configure::read('Asset.filter.css')) {
$url = str_replace(CSS_URL, 'ccss/', $url);
@@ -452,21 +442,10 @@ function script($url, $options = array()) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
- $url = $this->webroot($url);
- if (strpos($url, '?') === false) {
- if (strpos($url, '.js') === false) {
- $url .= '.js';
- }
- }
-
- $timestampEnabled = (
- (Configure::read('Asset.timestamp') === true && Configure::read('debug') > 0) ||
- Configure::read('Asset.timestamp') === 'force'
- );
-
- if (strpos($url, '?') === false && $timestampEnabled) {
- $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
+ if (strpos($url, '?') === false && strpos($url, '.js') === false) {
+ $url .= '.js';
}
+ $url = $this->webroot($this->assetTimestamp($url));
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
@@ -607,13 +586,11 @@ function getCrumbs($separator = '&raquo;', $startText = false) {
function image($path, $options = array()) {
if (is_array($path)) {
$path = $this->url($path);
- } elseif ($path[0] === '/') {
- $path = $this->webroot($path);
} elseif (strpos($path, '://') === false) {
- $path = $this->webroot(IMAGES_URL . $path);
- if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') {
- $path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . $path));
+ if ($path[0] !== '/') {
+ $path = IMAGES_URL . $path;
}
+ $path = $this->webroot($this->assetTimestamp($path));
}
if (!isset($options['alt'])) {
View
11 cake/libs/view/helpers/javascript.php
@@ -270,16 +270,7 @@ function link($url, $inline = true) {
$url .= '.js';
}
}
-
- $url = $this->webroot($url);
- $timestampEnabled = (
- (Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
- Configure::read('Asset.timestamp') === 'force'
- );
-
- if (strpos($url, '?') === false && $timestampEnabled) {
- $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url));
- }
+ $url = $this->webroot($this->assetTimestamp($url));
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
View
20 cake/libs/view/helpers/jquery_engine.php
@@ -160,7 +160,7 @@ function get($selector) {
function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options);
-
+
$function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) {
$callback .= "\nreturn false;";
@@ -240,7 +240,13 @@ function request($url, $options = array()) {
}
$options['url'] = $url;
if (isset($options['update'])) {
- $options['success'] = 'function (msg, status) {$("' . $options['update'] . '").html(msg);}';
+ $wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
+ if ($wrapCallbacks) {
+ $success = '$("' . $options['update'] . '").html(data);';
+ } else {
+ $success = 'function (data, textStatus) {$("' . $options['update'] . '").html(data);}';
+ }
+ $options['success'] = $success;
unset($options['update']);
}
$callbacks = array('success', 'error', 'beforeSend', 'complete');
@@ -269,7 +275,7 @@ function sortable($options = array()) {
/**
* Create a Draggable element
- *
+ *
* Requires both Ui.Core and Ui.Draggable to be loaded.
*
* @param array $options Array of options for the draggable element.
@@ -283,7 +289,7 @@ function drag($options = array()) {
/**
* Create a Droppable element
- *
+ *
* Requires both Ui.Core and Ui.Droppable to be loaded.
*
* @param array $options Array of options for the droppable element.
@@ -297,7 +303,7 @@ function drop($options = array()) {
/**
* Create a Slider element
- *
+ *
* Requires both Ui.Core and Ui.Slider to be loaded.
*
* @param array $options Array of options for the droppable element.
@@ -311,9 +317,9 @@ function slider($options = array()) {
}
/**
- * Serialize a form attached to $selector. If the current selection is not an input or
+ * Serialize a form attached to $selector. If the current selection is not an input or
* form, errors will be created in the Javascript.
- *
+ *
* @param array $options Options for the serialization
* @return string completed form serialization script
* @see JsHelper::serializeForm() for option list.
View
22 cake/libs/view/helpers/js.php
@@ -115,7 +115,7 @@ function __construct($settings = array()) {
* @param string $method Method to be called
* @param array $params Parameters for the method being called.
* @access public
- * @return mixed
+ * @return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper
**/
function call__($method, $params) {
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
@@ -151,6 +151,20 @@ function call__($method, $params) {
}
/**
+ * Workaround for Object::Object() existing. Since Object::object exists, it does not
+ * fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for
+ * more information on this method.
+ *
+ * @param mixed $data Data to convert into JSON
+ * @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details.
+ * @return string encoded JSON
+ * @deprecated Remove when support for PHP4 and Object::object are removed.
+ **/
+ function object($data = array(), $options = array()) {
+ return $this->{$this->__engineName}->object($data, $options);
+ }
+
+/**
* Writes all Javascript generated so far to a code block or
* caches them to a file and returns a linked script.
*
@@ -203,7 +217,7 @@ function buffer($script) {
/**
* Get all the cached scripts
*
- * @param boolean $clear Whether or not to clear the script caches
+ * @param boolean $clear Whether or not to clear the script caches (default true)
* @return array Array of scripts added to the request.
**/
function getBuffer($clear = true) {
@@ -919,10 +933,10 @@ function _mapOptions($method, $options) {
}
/**
- * Prepare callbacks and wrap them with function ([args]) { } as defined in
+ * Prepare callbacks and wrap them with function ([args]) { } as defined in
* _callbackArgs array.
*
- * @param string $method Name of the method you are preparing callbacks for.
+ * @param string $method Name of the method you are preparing callbacks for.
* @param array $options Array of options being parsed
* @param string $callbacks Additional Keys that contain callbacks
* @access protected
View
38 cake/libs/view/helpers/paginator.php
@@ -33,7 +33,7 @@ class PaginatorHelper extends AppHelper {
*
* @var array
*/
- var $helpers = array('Html', 'Ajax');
+ var $helpers = array('Html');
/**
* Holds the default model for paged recordsets
@@ -43,6 +43,13 @@ class PaginatorHelper extends AppHelper {
var $__defaultModel = null;
/**
+ * The class used for 'Ajax' pagination links.
+ *
+ * @var string
+ **/
+ var $_ajaxHelperClass = 'Js';
+
+/**
* Holds the default options for pagination links
*
* The values that may be specified are:
@@ -67,6 +74,33 @@ class PaginatorHelper extends AppHelper {
var $options = array();
/**
+ * Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
+ *
+ * Use `var $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
+ * or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
+ * adapter before including PaginatorHelper in your helpers array.
+ *
+ * The chosen custom helper must implement a `link()` method.
+ *
+ * @return void
+ **/
+ function __construct($config = array()) {
+ $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js';
+ $this->helpers[] = $ajaxProvider;
+ $this->_ajaxHelperClass = $ajaxProvider;
+
+ App::import('Helper', $ajaxProvider);
+ $classname = $ajaxProvider . 'Helper';
+ if (!method_exists($classname, 'link')) {
+ $message = sprintf(
+ __('%s does not implement a link() method, it is incompatible with PaginatorHelper', true),
+ $classname
+ );
+ trigger_error($message, E_USER_WARNING);
+ }
+ }
+
+/**
* Gets the current paging parameters from the resultset for the given model
*
* @param string $model Optional model name. Uses the default if none is specified.
@@ -280,7 +314,7 @@ function link($title, $url = array(), $options = array()) {
}
$url = $this->url($url, true, $model);
- $obj = isset($options['update']) ? 'Ajax' : 'Html';
+ $obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html';
$url = array_merge(array('page' => $this->current($model)), $url);
$url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin'=>true)));
return $this->{$obj}->link($title, $url, $options);
View
32 cake/tests/cases/console/libs/schema.test.php
@@ -148,7 +148,7 @@ function testStartup() {
$this->Shell->startup();
$this->assertTrue(isset($this->Shell->Schema));
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
- $this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR);
+ $this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR));
$this->assertEqual($this->Shell->Schema->file, 'schema.php');
unset($this->Shell->Schema);
@@ -168,7 +168,7 @@ function testStartup() {
'path' => '/test/path'
);
$this->Shell->startup();
- $this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR);
+ $this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR));
$this->assertEqual($this->Shell->Schema->file, 'other_file.php');
$this->assertEqual($this->Shell->Schema->connection, 'test_suite');
$this->assertEqual($this->Shell->Schema->path, '/test/path');
@@ -354,5 +354,33 @@ function testRunUpdateWithTable() {
$this->_fixtures['core.article']->create($this->db);
}
+/**
+ * test that the plugin param creates the correct path in the schema object.
+ *
+ * @return void
+ **/
+ function testPluginParam() {
+ App::build(array(
+ 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
+ ));
+ $this->Shell->params = array(
+ 'plugin' => 'TestPlugin',
+ 'connection' => 'test_suite'
+ );
+ $this->Shell->startup();
+ $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema' . DS;
+ $this->assertEqual($this->Shell->Schema->path, $expected);
+
+ unset($this->Shell->Schema);
+ $this->Shell->params = array(
+ 'plugin' => 'TestPlugin',
+ 'connection' => 'test_suite',
+ 'path' => '/some/path'
+ );
+ $this->Shell->startup();
+ $expected = '/some/path';
+ $this->assertEqual($this->Shell->Schema->path, $expected);
+ }
+
}
?>
View
10 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -303,16 +303,16 @@ function testBakeActionsUsingSessions() {
$this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false);
$this->assertTrue(strpos($result, 'function view($id = null)') !== false);
- $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid Article', true))") !== false);
+ $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid article', true))") !== false);
$this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false);
$this->assertTrue(strpos($result, 'function add()') !== false);
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
- $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The Article has been saved', true))") !== false);
+ $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article has been saved', true))") !== false);
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
- $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The Article could not be saved. Please, try again.', true));") !== false);
+ $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article could not be saved. Please, try again.', true));") !== false);
$this->assertTrue(strpos($result, 'function delete($id = null)') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false);
@@ -346,13 +346,13 @@ function testBakeActionsWithNoSessions() {
$this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false);
$this->assertTrue(strpos($result, 'function view($id = null)') !== false);
- $this->assertTrue(strpos($result, "\$this->flash(__('Invalid Article', true), array('action' => 'index'))") !== false);
+ $this->assertTrue(strpos($result, "\$this->flash(__('Invalid article', true), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false);
$this->assertTrue(strpos($result, 'function add()') !== false);
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
- $this->assertTrue(strpos($result, "\$this->flash(__('The Article has been saved.', true), array('action' => 'index'))") !== false);
+ $this->assertTrue(strpos($result, "\$this->flash(__('The article has been saved.', true), array('action' => 'index'))") !== false);
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
$this->assertTrue(strpos($result, "\$this->Article->Tag->find('list')") !== false);
View
35 cake/tests/cases/console/libs/tasks/view.test.php
@@ -33,13 +33,11 @@
ob_end_clean();
}
-
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'view.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
-
Mock::generatePartial(
'ShellDispatcher', 'TestViewTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
@@ -120,6 +118,8 @@ class ViewTaskTest extends CakeTestCase {
/**
* startTest method
*
+ * Ensure that the default theme is used
+ *
* @return void
* @access public
*/
@@ -132,6 +132,7 @@ function startTest() {
$this->Task->Controller =& new ViewTaskMockControllerTask();
$this->Task->Project =& new ViewTaskMockProjectTask();
$this->Task->path = TMP;
+ $this->Task->Template->params['theme'] = 'default';
}
/**
@@ -259,11 +260,11 @@ function testBakeActions() {
$this->Task->expectAt(0, 'createFile', array(
TMP . 'view_task_comments' . DS . 'view.ctp',
- new PatternExpectation('/ViewTaskComments/')
+ new PatternExpectation('/View Task Comments/')
));
$this->Task->expectAt(1, 'createFile', array(
TMP . 'view_task_comments' . DS . 'edit.ctp',
- new PatternExpectation('/Edit ViewTaskComment/')
+ new PatternExpectation('/Edit View Task Comment/')
));
$this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'index.ctp',
@@ -388,17 +389,35 @@ function testExecuteInteractive() {
));
$this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'add.ctp',
- new PatternExpectation('/Add ViewTaskComment/')
+ new PatternExpectation('/Add View Task Comment/')
));
$this->Task->expectAt(3, 'createFile', array(
TMP . 'view_task_comments' . DS . 'edit.ctp',
- new PatternExpectation('/Edit ViewTaskComment/')
+ new PatternExpectation('/Edit View Task Comment/')
));
$this->Task->execute();
}
/**
+ * test `cake bake view posts index list`
+ *
+ * @return void
+ **/
+ function testExecuteWithAlternateTemplates() {
+ $this->Task->connection = 'test_suite';
+ $this->Task->args = array('ViewTaskComments', 'index', 'list');
+ $this->Task->params = array();
+
+ $this->Task->expectCallCount('createFile', 1);
+ $this->Task->expectAt(0, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'list.ctp',
+ new PatternExpectation('/ViewTaskComment/')
+ ));
+ $this->Task->execute();
+ }
+
+/**
* test execute into interactive() with admin methods.
*
* @return void
@@ -425,11 +444,11 @@ function testExecuteInteractiveWithAdmin() {
));
$this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'admin_add.ctp',
- new PatternExpectation('/Add ViewTaskComment/')
+ new PatternExpectation('/Add View Task Comment/')
));
$this->Task->expectAt(3, 'createFile', array(
TMP . 'view_task_comments' . DS . 'admin_edit.ctp',
- new PatternExpectation('/Edit ViewTaskComment/')
+ new PatternExpectation('/Edit View Task Comment/')
));
$this->Task->execute();
View
2 cake/tests/cases/libs/cake_log.test.php
@@ -66,7 +66,7 @@ function testLoggingWithErrorHandling() {
$result = file(LOGS . 'debug.log');
$this->assertEqual(count($result), 1);
$this->assertPattern(
- '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Debug: Notice \(8\): Undefined variable: out in \[.+ line \d{2}\]$/',
+ '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Notice: Notice \(8\): Undefined variable: out in \[.+ line \d{2}\]$/',
$result[0]
);
@unlink(LOGS . 'debug.log');
View
222 cake/tests/cases/libs/controller/components/auth.test.php
@@ -1,34 +1,31 @@
<?php
-/* SVN FILE: $Id$ */
-
/**
- * AutComponentTest file
+ * AuthComponentTest file
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.cake.tests.cases.libs.controller.components
* @since CakePHP(tm) v 1.2.0.5347
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
-App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl'));
-App::import(array('controller' . DS . 'components' . DS . 'acl', 'model' . DS . 'db_acl'));
+App::import('Component', array('Auth', 'Acl'));
+App::import('Model', 'DbAcl');
App::import('Core', 'Xml');
+Mock::generate('AclComponent', 'AuthTestMockAclComponent');
+
/**
* TestAuthComponent class
*
@@ -272,6 +269,7 @@ function __construct() {
* @return void
*/
function beforeFilter() {
+ $this->Auth->userModel = 'AuthUser';
}
/**
@@ -495,11 +493,13 @@ function startTest() {
$this->Controller =& new AuthTestController();
$this->Controller->Component->init($this->Controller);
+ $this->Controller->Component->initialize($this->Controller);
+ $this->Controller->beforeFilter();
ClassRegistry::addObject('view', new View($this->Controller));
- $this->Controller->Session->del('Auth');
- $this->Controller->Session->del('Message.auth');
+ $this->Controller->Session->delete('Auth');
+ $this->Controller->Session->delete('Message.auth');
Router::reload();
@@ -517,8 +517,8 @@ function endTest() {
$_ENV = $this->_env;
Configure::write('Acl', $this->_acl);
Configure::write('Security.salt', $this->_securitySalt);
- $this->Controller->Session->del('Auth');
- $this->Controller->Session->del('Message.auth');
+ $this->Controller->Session->delete('Auth');
+ $this->Controller->Session->delete('Message.auth');
ClassRegistry::flush();
unset($this->Controller, $this->AuthUser);
}
@@ -586,7 +586,7 @@ function testLogin() {
'id' => 1, 'username' => 'mariano', 'created' => '2007-03-17 01:16:23', 'updated' => date('Y-m-d H:i:s')
));
$this->assertEqual($user, $expected);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->data['AuthUser']['username'] = 'blah';
$this->Controller->data['AuthUser']['password'] = '';
@@ -595,7 +595,7 @@ function testLogin() {
$user = $this->Controller->Auth->user();
$this->assertFalse($user);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->data['AuthUser']['username'] = 'now() or 1=1 --';
$this->Controller->data['AuthUser']['password'] = '';
@@ -604,7 +604,7 @@ function testLogin() {
$user = $this->Controller->Auth->user();
$this->assertFalse($user);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->data['AuthUser']['username'] = 'now() or 1=1 # something';
$this->Controller->data['AuthUser']['password'] = '';
@@ -613,7 +613,7 @@ function testLogin() {
$user = $this->Controller->Auth->user();
$this->assertFalse($user);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->Auth->userModel = 'UuidUser';
$this->Controller->Auth->login('47c36f9c-bc00-4d17-9626-4e183ca6822b');
@@ -623,7 +623,7 @@ function testLogin() {
'id' => '47c36f9c-bc00-4d17-9626-4e183ca6822b', 'title' => 'Unique record 1', 'count' => 2, 'created' => '2008-03-13 01:16:23', 'updated' => '2008-03-13 01:18:31'
));
$this->assertEqual($user, $expected);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
}
/**
@@ -642,7 +642,7 @@ function testAuthorizeFalse() {
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertFalse($result);
$this->assertTrue($this->Controller->Session->check('Message.auth'));
@@ -673,7 +673,7 @@ function testAuthorizeController() {
$this->assertTrue($this->Controller->Session->check('Message.auth'));
$this->assertFalse($result);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
}
/**
@@ -695,7 +695,7 @@ function testAuthorizeModel() {
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertTrue($result);
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->Auth->startup($this->Controller);
$this->assertTrue($this->Controller->Session->check('Message.auth'));
$result = $this->Controller->Auth->isAuthorized();
@@ -737,7 +737,7 @@ function testAuthorizeCrud() {
$result = $this->Controller->Acl->Aro->save();
$this->assertTrue($result);
- $this->Controller->Acl->Aco->create(array('alias'=>'Root'));
+ $this->Controller->Acl->Aco->create(array('alias' => 'Root'));
$result = $this->Controller->Acl->Aco->save();
$this->assertTrue($result);
@@ -759,12 +759,41 @@ function testAuthorizeCrud() {
$this->Controller->Auth->startup($this->Controller);
$this->assertTrue($this->Controller->Auth->isAuthorized());
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->Auth->startup($this->Controller);
$this->assertTrue($this->Controller->Session->check('Message.auth'));
}
/**
+ * test authorize = 'actions' setting.
+ *
+ * @return void
+ **/
+ function testAuthorizeActions() {
+ $this->AuthUser =& new AuthUser();
+ $user = $this->AuthUser->find();
+ $this->Controller->Session->write('Auth', $user);
+ $this->Controller->params['controller'] = 'auth_test';
+ $this->Controller->params['action'] = 'add';
+
+ $this->Controller->Acl =& new AuthTestMockAclComponent();
+ $this->Controller->Acl->setReturnValue('check', true);
+
+ $this->Controller->Auth->initialize($this->Controller);
+
+ $this->Controller->Auth->userModel = 'AuthUser';
+ $this->Controller->Auth->authorize = 'actions';
+ $this->Controller->Auth->actionPath = 'Root/';
+
+ $this->Controller->Acl->expectAt(0, 'check', array(
+ $user, 'Root/AuthTest/add'
+ ));
+
+ $this->Controller->Auth->startup($this->Controller);
+ $this->assertTrue($this->Controller->Auth->isAuthorized());
+ }
+
+/**
* Tests that deny always takes precedence over allow
*
* @access public
@@ -774,7 +803,7 @@ function testAllowDenyAll() {
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->allow('*');
- $this->Controller->Auth->deny('add');
+ $this->Controller->Auth->deny('add', 'camelcase');
$this->Controller->params['action'] = 'delete';
$this->assertTrue($this->Controller->Auth->startup($this->Controller));
@@ -784,6 +813,61 @@ function testAllowDenyAll() {
$this->Controller->params['action'] = 'Add';
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
+
+ $this->Controller->params['action'] = 'camelCase';
+ $this->assertFalse($this->Controller->Auth->startup($this->Controller));
+
+ $this->Controller->Auth->allow('*');
+ $this->Controller->Auth->deny(array('add', 'camelcase'));
+
+ $this->Controller->params['action'] = 'camelCase';
+ $this->assertFalse($this->Controller->Auth->startup($this->Controller));
+ }
+
+/**
+ * test the action() method
+ *
+ * @return void
+ **/
+ function testActionMethod() {
+ $this->Controller->params['controller'] = 'auth_test';
+ $this->Controller->params['action'] = 'add';
+
+ $this->Controller->Auth->initialize($this->Controller);
+ $this->Controller->Auth->actionPath = 'ROOT/';
+
+ $result = $this->Controller->Auth->action();
+ $this->assertEqual($result, 'ROOT/AuthTest/add');
+
+ $result = $this->Controller->Auth->action(':controller');
+ $this->assertEqual($result, 'ROOT/AuthTest');
+
+ $result = $this->Controller->Auth->action(':controller');
+ $this->assertEqual($result, 'ROOT/AuthTest');
+
+ $this->Controller->params['plugin'] = 'test_plugin';
+ $this->Controller->params['controller'] = 'auth_test';
+ $this->Controller->params['action'] = 'add';
+ $this->Controller->Auth->initialize($this->Controller);
+ $result = $this->Controller->Auth->action();
+ $this->assertEqual($result, 'ROOT/TestPlugin/AuthTest/add');
+ }
+
+/**
+ * test that deny() converts camel case inputs to lowercase.
+ *
+ * @return void
+ **/
+ function testDenyWithCamelCaseMethods() {
+ $this->Controller->Auth->initialize($this->Controller);
+ $this->Controller->Auth->allow('*');
+ $this->Controller->Auth->deny('add', 'camelCase');
+
+ $url = '/auth_test/camelCase';
+ $this->Controller->params = Router::parse($url);
+ $this->Controller->params['url']['url'] = Router::normalize($url);
+
+ $this->assertFalse($this->Controller->Auth->startup($this->Controller));
}
/**
@@ -815,6 +899,17 @@ function testAllowedActionsWithCamelCaseMethods() {
$this->Controller->Auth->allowedActions = array('delete', 'add');
$result = $this->Controller->Auth->startup($this->Controller);
$this->assertFalse($result, 'startup() should return false, as action is not allowed. %s');
+
+ }
+
+ function testAllowedActionsSetWithAllowMethod() {
+ $url = '/auth_test/action_name';
+ $this->Controller->params = Router::parse($url);
+ $this->Controller->params['url']['url'] = Router::normalize($url);
+ $this->Controller->Auth->initialize($this->Controller);
+ $this->Controller->Auth->allow('action_name', 'anotherAction');
+ $this->assertEqual($this->Controller->Auth->allowedActions, array('action_name', 'anotheraction'));
+
}
/**
@@ -848,7 +943,7 @@ function testLoginRedirect() {
$expected = Router::normalize($this->Controller->Auth->loginRedirect);
$this->assertEqual($expected, $this->Controller->Auth->redirect());
- $this->Controller->Session->del('Auth');
+ $this->Controller->Session->delete('Auth');
$this->Controller->params['url']['url'] = 'admin/';
$this->Controller->Auth->initialize($this->Controller);