Merge branch '2.3' into type-checks

Conflicts:
	lib/Cake/Console/Command/Task/ModelTask.php
	lib/Cake/Controller/Component/RequestHandlerComponent.php
	lib/Cake/Model/Datasource/Database/Mysql.php
	lib/Cake/Utility/CakeNumber.php
This commit is contained in:
dogmatic69 2012-10-01 02:08:00 +01:00
commit 408e619c9f
102 changed files with 1416 additions and 655 deletions

View file

@ -94,4 +94,4 @@ if (!empty($failed)) {
App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse());

View file

@ -366,7 +366,7 @@ class Cache {
}
$key = self::$_engines[$config]->key($key);
if (!$key || !is_integer($offset) || $offset < 0) {
if (!$key || !is_int($offset) || $offset < 0) {
return false;
}
$success = self::$_engines[$config]->increment($settings['prefix'] . $key, $offset);
@ -394,7 +394,7 @@ class Cache {
}
$key = self::$_engines[$config]->key($key);
if (!$key || !is_integer($offset) || $offset < 0) {
if (!$key || !is_int($offset) || $offset < 0) {
return false;
}
$success = self::$_engines[$config]->decrement($settings['prefix'] . $key, $offset);

View file

@ -183,6 +183,7 @@ class WincacheEngine extends CacheEngine {
* @return boolean success
**/
public function clearGroup($group) {
$success = null;
wincache_ucache_inc($this->settings['prefix'] . $group, 1, $success);
return $success;
}

View file

@ -72,11 +72,14 @@ class IniReader implements ConfigReaderInterface {
* Build and construct a new ini file parser. The parser can be used to read
* ini files that are on the filesystem.
*
* @param string $path Path to load ini config files from.
* @param string $path Path to load ini config files from. Defaults to APP . 'Config' . DS
* @param string $section Only get one section, leave null to parse and fetch
* all sections in the ini file.
*/
public function __construct($path, $section = null) {
public function __construct($path = null, $section = null) {
if (!$path) {
$path = APP . 'Config' . DS;
}
$this->_path = $path;
$this->_section = $section;
}
@ -180,7 +183,7 @@ class IniReader implements ConfigReaderInterface {
}
}
}
$contents = join("\n", $result);
$contents = implode("\n", $result);
if (substr($filename, -4) !== '.ini') {
$filename .= '.ini';

View file

@ -349,7 +349,7 @@ class ControllerTask extends BakeTask {
public function doHelpers() {
return $this->_doPropertyChoices(
__d('cake_console', "Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"),
__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'")
__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Text, Js, Time'")
);
}
@ -432,7 +432,7 @@ class ControllerTask extends BakeTask {
}
}
if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers) ) {
if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers)) {
$controllerName = $controllers[intval($enteredController) - 1];
} else {
$controllerName = Inflector::camelize($enteredController);

View file

@ -311,8 +311,11 @@ class DbConfigTask extends AppShell {
$config = array_merge($this->_defaultConfig, $config);
extract($config);
if (strpos($datasource, 'Database/') === false) {
$datasource = "Database/{$datasource}";
}
$out .= "\tpublic \${$name} = array(\n";
$out .= "\t\t'datasource' => 'Database/{$datasource}',\n";
$out .= "\t\t'datasource' => '{$datasource}',\n";
$out .= "\t\t'persistent' => {$persistent},\n";
$out .= "\t\t'host' => '{$host}',\n";

View file

@ -245,7 +245,7 @@ class ExtractTask extends AppShell {
if (empty($this->_translations[$domain][$msgid])) {
$this->_translations[$domain][$msgid] = array(
'msgid_plural' => false
);
);
}
if (isset($details['msgid_plural'])) {

View file

@ -686,7 +686,7 @@ class ModelTask extends BakeTask {
$prompt = __d('cake_console', 'Would you like to define some additional model associations?');
$wannaDoMoreAssoc = $this->in($prompt, array('y', 'n'), 'n');
$possibleKeys = $this->_generatePossibleKeys();
while (strtolower($wannaDoMoreAssoc) == 'y') {
while (strtolower($wannaDoMoreAssoc) === 'y') {
$assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
$this->out(__d('cake_console', 'What is the association type?'));
$assocType = intval($this->inOptions($assocs, __d('cake_console', 'Enter a number')));
@ -696,9 +696,9 @@ class ModelTask extends BakeTask {
$this->hr();
$alias = $this->in(__d('cake_console', 'What is the alias for this association?'));
$className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias );
$className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias);
if (!$assocType) {
if ($assocType === 0) {
if (!empty($possibleKeys[$model->table])) {
$showKeys = $possibleKeys[$model->table];
} else {
@ -731,7 +731,7 @@ class ModelTask extends BakeTask {
if (!isset($foreignKey)) {
$foreignKey = $this->in(__d('cake_console', 'What is the foreignKey? Specify your own.'), null, $suggestedForeignKey);
}
if ($assocType == 3) {
if ($assocType === 3) {
$associationForeignKey = $this->in(__d('cake_console', 'What is the associationForeignKey?'), null, $this->_modelKey($model->name));
$joinTable = $this->in(__d('cake_console', 'What is the joinTable?'));
}
@ -741,7 +741,7 @@ class ModelTask extends BakeTask {
$associations[$assocs[$assocType]][$i]['alias'] = $alias;
$associations[$assocs[$assocType]][$i]['className'] = $className;
$associations[$assocs[$assocType]][$i]['foreignKey'] = $foreignKey;
if ($assocType == 3) {
if ($assocType === 3) {
$associations[$assocs[$assocType]][$i]['associationForeignKey'] = $associationForeignKey;
$associations[$assocs[$assocType]][$i]['joinTable'] = $joinTable;
}

View file

@ -84,6 +84,10 @@ class ConsoleErrorHandler {
if (!Configure::read('debug')) {
CakeLog::write($log, $message);
}
if ($log === LOG_ERR) {
$this->_stop(1);
}
}
/**

View file

@ -160,11 +160,11 @@ class ShellDispatcher {
$errorHandler = new ConsoleErrorHandler();
if (empty($error['consoleHandler'])) {
$error['consoleHandler'] = array($errorHandler, 'handleError');
Configure::write('error', $error);
Configure::write('Error', $error);
}
if (empty($exception['consoleHandler'])) {
$exception['consoleHandler'] = array($errorHandler, 'handleException');
Configure::write('exception', $exception);
Configure::write('Exception', $exception);
}
set_exception_handler($exception['consoleHandler']);
set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
@ -215,7 +215,8 @@ class ShellDispatcher {
return $Shell->main();
}
}
throw new MissingShellMethodException(array('shell' => $shell, 'method' => $arg));
throw new MissingShellMethodException(array('shell' => $shell, 'method' => $command));
}
/**

View file

@ -36,11 +36,11 @@
* @return void
*/
public function <?php echo $admin ?>view($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->find('first', $options));
}
<?php $compact = array(); ?>
@ -91,8 +91,7 @@
* @return void
*/
public function <?php echo $admin; ?>edit($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
if ($this->request->is('post') || $this->request->is('put')) {
@ -109,7 +108,8 @@
<?php endif; ?>
}
} else {
$this->request->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
}
<?php
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):

View file

@ -25,7 +25,7 @@
); ?>
</p>
<?php
if (Configure::read('debug') > 0 ):
if (Configure::read('debug') > 0):
echo $this->element('exception_stack_trace');
endif;
?>

View file

@ -22,7 +22,7 @@
<?php echo __d('cake', 'An Internal Error Has Occurred.'); ?>
</p>
<?php
if (Configure::read('debug') > 0 ):
if (Configure::read('debug') > 0):
echo $this->element('exception_stack_trace');
endif;
?>

View file

@ -98,5 +98,5 @@ App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
new CakeRequest(),
new CakeResponse(array('charset' => Configure::read('App.encoding')))
new CakeResponse()
);

View file

@ -86,7 +86,7 @@ if (!empty($failed)) {
}
if (Configure::read('debug') < 1) {
die(__d('cake_dev', 'Debug setting does not allow access to this url.'));
exit(__d('cake_dev', 'Debug setting does not allow access to this url.'));
}
require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteDispatcher.php';

View file

@ -318,10 +318,8 @@ class PhpAco {
* @return void
*/
public function build(array $allow, array $deny = array()) {
$stack = array();
$this->_tree = array();
$tree = array();
$root = &$tree;
foreach ($allow as $dotPath => $aros) {
if (is_string($aros)) {

View file

@ -327,7 +327,7 @@ class AuthComponent extends Component {
if (!empty($this->loginRedirect)) {
$default = $this->loginRedirect;
}
$controller->redirect($controller->referer($default), null, true);
$controller->redirect($controller->referer($default, true), null, true);
return false;
}

View file

@ -177,7 +177,7 @@ class CookieComponent extends Component {
if ($controller && isset($controller->response)) {
$this->_response = $controller->response;
} else {
$this->_response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
$this->_response = new CakeResponse();
}
}
@ -191,9 +191,6 @@ class CookieComponent extends Component {
$this->_expire($this->time);
$this->_values[$this->name] = array();
if (isset($_COOKIE[$this->name])) {
$this->_values[$this->name] = $this->_decrypt($_COOKIE[$this->name]);
}
}
/**
@ -281,6 +278,19 @@ class CookieComponent extends Component {
return $this->_values[$this->name][$key];
}
/**
* Returns true if given variable is set in cookie.
*
* @param string $var Variable name to check for
* @return boolean True if variable is there
*/
public function check($key = null) {
if (empty($key)) {
return false;
}
return $this->read($key) !== null;
}
/**
* Delete a cookie value
*
@ -385,7 +395,7 @@ class CookieComponent extends Component {
return $this->_expires = 0;
}
if (is_integer($expires) || is_numeric($expires)) {
if (is_int($expires) || is_numeric($expires)) {
return $this->_expires = $now + intval($expires);
}
return $this->_expires = strtotime($expires, $now);

View file

@ -107,8 +107,7 @@ class RequestHandlerComponent extends Component {
* @param array $settings Array of settings.
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
$default = array('checkHttpCache' => true);
parent::__construct($collection, $settings + $default);
parent::__construct($collection, $settings + array('checkHttpCache' => true));
$this->addInputType('xml', array(array($this, 'convertXml')));
$Controller = $collection->getController();
@ -158,9 +157,11 @@ class RequestHandlerComponent extends Component {
$extensions = Router::extensions();
$preferred = array_shift($accept);
$preferredTypes = $this->response->mapType($preferred);
$similarTypes = array_intersect($extensions, $preferredTypes);
if (count($similarTypes) === 1 && !in_array('xhtml', $preferredTypes) && !in_array('html', $preferredTypes)) {
$this->ext = array_shift($similarTypes);
if (!in_array('xhtml', $preferredTypes) && !in_array('html', $preferredTypes)) {
$similarTypes = array_intersect($extensions, $preferredTypes);
if (count($similarTypes) === 1) {
$this->ext = array_shift($similarTypes);
}
}
}
@ -269,8 +270,7 @@ class RequestHandlerComponent extends Component {
* @return boolean false if the render process should be aborted
**/
public function beforeRender(Controller $controller) {
$shouldCheck = $this->settings['checkHttpCache'];
if ($shouldCheck && $this->response->checkNotModified($this->request)) {
if ($this->settings['checkHttpCache'] && $this->response->checkNotModified($this->request)) {
return false;
}
}
@ -395,13 +395,11 @@ class RequestHandlerComponent extends Component {
* Gets Prototype version if call is Ajax, otherwise empty string.
* The Prototype library sets a special "Prototype version" HTTP header.
*
* @return string Prototype version of component making Ajax call
* @return string|boolean When Ajax the prototype version of component making the call otherwise false
*/
public function getAjaxVersion() {
if (env('HTTP_X_PROTOTYPE_VERSION')) {
return env('HTTP_X_PROTOTYPE_VERSION');
}
return false;
$httpX = env('HTTP_X_PROTOTYPE_VERSION');
return ($httpX === null) ? false : $httpX;
}
/**
@ -467,9 +465,10 @@ class RequestHandlerComponent extends Component {
public function accepts($type = null) {
$accepted = $this->request->accepts();
if ($type == null) {
if (!$type) {
return $this->mapType($accepted);
} elseif (is_array($type)) {
}
if (is_array($type)) {
foreach ($type as $t) {
$t = $this->mapAlias($t);
if (in_array($t, $accepted)) {
@ -477,9 +476,9 @@ class RequestHandlerComponent extends Component {
}
}
return false;
} elseif (is_string($type)) {
$type = $this->mapAlias($type);
return in_array($type, $accepted);
}
if (is_string($type)) {
return in_array($this->mapAlias($type), $accepted);
}
return false;
}
@ -496,18 +495,20 @@ class RequestHandlerComponent extends Component {
if (!$this->request->is('post') && !$this->request->is('put')) {
return null;
}
list($contentType) = explode(';', env('CONTENT_TYPE'));
if ($type == null) {
return $this->mapType($contentType);
} elseif (is_array($type)) {
if (is_array($type)) {
foreach ($type as $t) {
if ($this->requestedWith($t)) {
return $t;
}
}
return false;
} elseif (is_string($type)) {
}
list($contentType) = explode(';', env('CONTENT_TYPE'));
if (!$type) {
return $this->mapType($contentType);
}
if (is_string($type)) {
return ($type == $this->mapType($contentType));
}
}
@ -535,10 +536,9 @@ class RequestHandlerComponent extends Component {
if (empty($acceptRaw)) {
return $this->ext;
}
$accepts = array_shift($acceptRaw);
$accepts = $this->mapType($accepts);
$accepts = $this->mapType(array_shift($acceptRaw));
if ($type == null) {
if (!$type) {
if (empty($this->ext) && !empty($accepts)) {
return $accepts[0];
}
@ -611,8 +611,11 @@ class RequestHandlerComponent extends Component {
} elseif (empty($this->_renderType)) {
$controller->viewPath .= DS . $type;
} else {
$remove = preg_replace("/([\/\\\\]{$this->_renderType})$/", DS . $type, $controller->viewPath);
$controller->viewPath = $remove;
$controller->viewPath = preg_replace(
"/([\/\\\\]{$this->_renderType})$/",
DS . $type,
$controller->viewPath
);
}
$this->_renderType = $type;
$controller->layoutPath = $type;
@ -622,12 +625,8 @@ class RequestHandlerComponent extends Component {
}
$helper = ucfirst($type);
$isAdded = (
in_array($helper, $controller->helpers) ||
array_key_exists($helper, $controller->helpers)
);
if (!$isAdded) {
if (!in_array($helper, $controller->helpers) && empty($controller->helpers[$helper])) {
App::uses('AppHelper', 'View/Helper');
App::uses($helper . 'Helper', 'View/Helper');
if (class_exists($helper . 'Helper')) {
@ -653,39 +652,35 @@ class RequestHandlerComponent extends Component {
$defaults = array('index' => null, 'charset' => null, 'attachment' => false);
$options = $options + $defaults;
$cType = $type;
if (strpos($type, '/') === false) {
$cType = $this->response->getMimeType($type);
if ($cType === false) {
return false;
}
if (is_array($cType) && isset($cType[$options['index']])) {
}
if (is_array($cType)) {
if (isset($cType[$options['index']])) {
$cType = $cType[$options['index']];
}
if (is_array($cType)) {
if ($this->prefers($cType)) {
$cType = $this->prefers($cType);
} else {
$cType = $cType[0];
}
if ($this->prefers($cType)) {
$cType = $this->prefers($cType);
} else {
$cType = $cType[0];
}
} else {
$cType = $type;
}
if ($cType) {
if (empty($this->request->params['requested'])) {
$this->response->type($cType);
}
if (!empty($options['charset'])) {
$this->response->charset($options['charset']);
}
if (!empty($options['attachment'])) {
$this->response->download($options['attachment']);
}
return true;
if (!$type) {
return false;
}
return false;
if (empty($this->request->params['requested'])) {
$this->response->type($cType);
}
if (!empty($options['charset'])) {
$this->response->charset($options['charset']);
}
if (!empty($options['attachment'])) {
$this->response->download($options['attachment']);
}
return true;
}
/**
@ -758,7 +753,8 @@ class RequestHandlerComponent extends Component {
public function viewClassMap($type = null, $viewClass = null) {
if (!$viewClass && is_string($type) && isset($this->_viewClassMap[$type])) {
return $this->_viewClassMap[$type];
} elseif (is_string($type)) {
}
if (is_string($type)) {
$this->_viewClassMap[$type] = $viewClass;
} elseif (is_array($type)) {
foreach ($type as $key => $value) {

View file

@ -246,7 +246,8 @@ class SecurityComponent extends Component {
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requirePost
*/
public function requirePost() {
$this->_requireMethod('Post', func_get_args());
$args = func_get_args();
$this->_requireMethod('Post', $args);
}
/**
@ -255,7 +256,8 @@ class SecurityComponent extends Component {
* @return void
*/
public function requireGet() {
$this->_requireMethod('Get', func_get_args());
$args = func_get_args();
$this->_requireMethod('Get', $args);
}
/**
@ -264,7 +266,8 @@ class SecurityComponent extends Component {
* @return void
*/
public function requirePut() {
$this->_requireMethod('Put', func_get_args());
$args = func_get_args();
$this->_requireMethod('Put', $args);
}
/**
@ -273,7 +276,8 @@ class SecurityComponent extends Component {
* @return void
*/
public function requireDelete() {
$this->_requireMethod('Delete', func_get_args());
$args = func_get_args();
$this->_requireMethod('Delete', $args);
}
/**
@ -283,7 +287,8 @@ class SecurityComponent extends Component {
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireSecure
*/
public function requireSecure() {
$this->_requireMethod('Secure', func_get_args());
$args = func_get_args();
$this->_requireMethod('Secure', $args);
}
/**
@ -293,7 +298,8 @@ class SecurityComponent extends Component {
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireAuth
*/
public function requireAuth() {
$this->_requireMethod('Auth', func_get_args());
$args = func_get_args();
$this->_requireMethod('Auth', $args);
}
/**
@ -383,7 +389,7 @@ class SecurityComponent extends Component {
$requireAuth = $this->requireAuth;
if (in_array($this->request->params['action'], $requireAuth) || $this->requireAuth == array('*')) {
if (!isset($controller->request->data['_Token'] )) {
if (!isset($controller->request->data['_Token'])) {
if (!$this->blackHole($controller, 'auth')) {
return null;
}

View file

@ -557,7 +557,6 @@ class Controller extends Object implements CakeEventListener {
if ($mergeParent || !empty($pluginController)) {
$appVars = get_class_vars($this->_mergeParent);
$uses = $appVars['uses'];
$merge = array('components', 'helpers');
$this->_mergeVars($merge, $this->_mergeParent, true);
}

View file

@ -170,6 +170,19 @@ class Configure {
return Hash::get(self::$_values, $var);
}
/**
* Returns true if given variable is set in Configure.
*
* @param string $var Variable name to check for
* @return boolean True if variable is there
*/
public static function check($var = null) {
if (empty($var)) {
return false;
}
return Hash::get(self::$_values, $var) !== null;
}
/**
* Used to delete a variable from Configure.
*
@ -185,7 +198,6 @@ class Configure {
*/
public static function delete($var = null) {
$keys = explode('.', $var);
$last = array_pop($keys);
self::$_values = Hash::remove(self::$_values, $var);
}

View file

@ -146,7 +146,7 @@ class ExceptionRenderer {
if (!$request = Router::getRequest(true)) {
$request = new CakeRequest();
}
$response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
$response = new CakeResponse();
if (method_exists($exception, 'responseHeader')) {
$response->header($exception->responseHeader());
@ -295,11 +295,11 @@ class ExceptionRenderer {
$this->controller->layoutPath = null;
$this->controller->subDir = null;
$this->controller->viewPath = 'Errors/';
$this->controller->viewClass = 'View';
$this->controller->layout = 'error';
$this->controller->helpers = array('Form', 'Html', 'Session');
$this->controller->render($template);
$view = new View($this->controller);
$this->controller->response->body($view->render($template, 'error'));
$this->controller->response->type('html');
$this->controller->response->send();
}

View file

@ -592,19 +592,19 @@ class I18n {
$string = $string[1];
if (substr($string, 0, 2) === $this->_escape . 'x') {
$delimiter = $this->_escape . 'x';
return join('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
return implode('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
}
if (substr($string, 0, 2) === $this->_escape . 'd') {
$delimiter = $this->_escape . 'd';
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
return implode('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if ($string[0] === $this->_escape && isset($string[1]) && is_numeric($string[1])) {
$delimiter = $this->_escape;
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
return implode('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if (substr($string, 0, 3) === 'U00') {
$delimiter = 'U00';
return join('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
}
if (preg_match('/U([0-9a-fA-F]{4})/', $string, $match)) {
return Multibyte::ascii(array(hexdec($match[1])));

View file

@ -85,47 +85,53 @@ class L10n {
/**
* Maps ISO 639-3 to I10n::_l10nCatalog
* The terminological codes (first one per language) should be used if possible.
* They are the ones building the path in `/APP/Locale/[code]/`
* The bibliographic codes are aliases.
*
* @var array
*/
protected $_l10nMap = array(
/* Afrikaans */ 'afr' => 'af',
/* Albanian */ 'alb' => 'sq',
/* Albanian */ 'sqi' => 'sq',
/* Albanian - bibliographic */ 'alb' => 'sq',
/* Arabic */ 'ara' => 'ar',
/* Armenian - Armenia */ 'hye' => 'hy',
/* Armenian/Armenia */ 'hye' => 'hy',
/* Basque */ 'eus' => 'eu',
/* Basque */ 'baq' => 'eu',
/* Tibetan */ 'bod' => 'bo',
/* Tibetan - bibliographic */ 'tib' => 'bo',
/* Bosnian */ 'bos' => 'bs',
/* Bulgarian */ 'bul' => 'bg',
/* Byelorussian */ 'bel' => 'be',
/* Catalan */ 'cat' => 'ca',
/* Chinese */ 'chi' => 'zh',
/* Chinese */ 'zho' => 'zh',
/* Chinese - bibliographic */ 'chi' => 'zh',
/* Croatian */ 'hrv' => 'hr',
/* Czech */ 'cze' => 'cs',
/* Czech */ 'ces' => 'cs',
/* Czech - bibliographic */ 'cze' => 'cs',
/* Danish */ 'dan' => 'da',
/* Dutch (Standard) */ 'dut' => 'nl',
/* Dutch (Standard) */ 'nld' => 'nl',
/* Dutch (Standard) - bibliographic */ 'dut' => 'nl',
/* English */ 'eng' => 'en',
/* Estonian */ 'est' => 'et',
/* Faeroese */ 'fao' => 'fo',
/* Farsi */ 'fas' => 'fa',
/* Farsi */ 'per' => 'fa',
/* Farsi/Persian */ 'fas' => 'fa',
/* Farsi/Persian - bibliographic */ 'per' => 'fa',
/* Finnish */ 'fin' => 'fi',
/* French (Standard) */ 'fre' => 'fr',
/* French (Standard) */ 'fra' => 'fr',
/* French (Standard) - bibliographic */ 'fre' => 'fr',
/* Gaelic (Scots) */ 'gla' => 'gd',
/* Galician */ 'glg' => 'gl',
/* German (Standard) */ 'deu' => 'de',
/* German (Standard) */ 'ger' => 'de',
/* German (Standard) - bibliographic */ 'ger' => 'de',
/* Greek */ 'gre' => 'el',
/* Greek */ 'ell' => 'el',
/* Hebrew */ 'heb' => 'he',
/* Hindi */ 'hin' => 'hi',
/* Hungarian */ 'hun' => 'hu',
/* Icelandic */ 'ice' => 'is',
/* Icelandic */ 'isl' => 'is',
/* Icelandic - bibliographic */ 'ice' => 'is',
/* Indonesian */ 'ind' => 'id',
/* Irish */ 'gle' => 'ga',
/* Italian */ 'ita' => 'it',
@ -133,10 +139,10 @@ class L10n {
/* Korean */ 'kor' => 'ko',
/* Latvian */ 'lav' => 'lv',
/* Lithuanian */ 'lit' => 'lt',
/* Macedonian */ 'mac' => 'mk',
/* Macedonian */ 'mkd' => 'mk',
/* Malaysian */ 'may' => 'ms',
/* Macedonian - bibliographic */ 'mac' => 'mk',
/* Malaysian */ 'msa' => 'ms',
/* Malaysian - bibliographic */ 'may' => 'ms',
/* Maltese */ 'mlt' => 'mt',
/* Norwegian */ 'nor' => 'no',
/* Norwegian Bokmal */ 'nob' => 'nb',
@ -144,14 +150,13 @@ class L10n {
/* Polish */ 'pol' => 'pl',
/* Portuguese (Portugal) */ 'por' => 'pt',
/* Rhaeto-Romanic */ 'roh' => 'rm',
/* Romanian */ 'rum' => 'ro',
/* Romanian */ 'ron' => 'ro',
/* Romanian - bibliographic */ 'rum' => 'ro',
/* Russian */ 'rus' => 'ru',
/* Sami (Lappish) */ 'smi' => 'sz',
/* Serbian */ 'scc' => 'sr',
/* Serbian */ 'srp' => 'sr',
/* Slovak */ 'slo' => 'sk',
/* Slovak */ 'slk' => 'sk',
/* Slovak - bibliographic */ 'slo' => 'sk',
/* Slovenian */ 'slv' => 'sl',
/* Sorbian */ 'wen' => 'sb',
/* Spanish (Spain - Traditional) */ 'spa' => 'es',
@ -165,6 +170,7 @@ class L10n {
/* Venda */ 'ven' => 've',
/* Vietnamese */ 'vie' => 'vi',
/* Welsh */ 'cym' => 'cy',
/* Welsh - bibliographic */ 'wel' => 'cy',
/* Xhosa */ 'xho' => 'xh',
/* Yiddish */ 'yid' => 'yi',
/* Zulu */ 'zul' => 'zu'
@ -203,7 +209,7 @@ class L10n {
'bo-in' => array('language' => 'Tibetan (India)', 'locale' => 'bo_in', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr'),
'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr'),
'cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr'),
'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -245,16 +251,16 @@ class L10n {
'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr'),
'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr'),
'eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fa' => array('language' => 'Farsi', 'locale' => 'per', 'localeFallback' => 'per', 'charset' => 'utf-8', 'direction' => 'rtl'),
'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr'),
'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -266,7 +272,7 @@ class L10n {
'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr'),
'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
'in' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr'),
'is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr'),
'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -276,14 +282,14 @@ class L10n {
'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr'),
'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'n' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
'p' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -291,15 +297,15 @@ class L10n {
'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8', 'direction' => 'ltr'),
@ -315,11 +321,11 @@ class L10n {
'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8', 'direction' => 'ltr'),
'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr')
);

View file

@ -1122,7 +1122,7 @@ class Multibyte {
public static function checkMultibyte($string) {
$length = strlen($string);
for ($i = 0; $i < $length; $i++ ) {
for ($i = 0; $i < $length; $i++) {
$value = ord(($string[$i]));
if ($value > 128) {
return true;

View file

@ -140,15 +140,25 @@ class TranslateBehavior extends ModelBehavior {
return $query;
}
$fields = array_merge($this->settings[$Model->alias], $this->runtime[$Model->alias]['fields']);
$fields = array_merge(
$this->settings[$Model->alias],
$this->runtime[$Model->alias]['fields']
);
$addFields = array();
if (empty($query['fields'])) {
$addFields = $fields;
} elseif (is_array($query['fields'])) {
$isAllFields = (
in_array($Model->alias . '.' . '*', $query['fields']) ||
in_array($Model->escapeField('*'), $query['fields'])
);
foreach ($fields as $key => $value) {
$field = (is_numeric($key)) ? $value : $key;
if (in_array($Model->escapeField('*'), $query['fields']) || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields'])) {
if (
$isAllFields ||
in_array($Model->alias . '.' . $field, $query['fields']) ||
in_array($field, $query['fields'])
) {
$addFields[] = $field;
}
}
@ -184,7 +194,7 @@ class TranslateBehavior extends ModelBehavior {
*/
protected function _checkConditions(Model $Model, $query) {
$conditionFields = array();
if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions'])) ) {
if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions']))) {
return $conditionFields;
}
foreach ($query['conditions'] as $col => $val) {
@ -425,7 +435,11 @@ class TranslateBehavior extends ModelBehavior {
$conditions['locale'] = $_locale;
$conditions['content'] = $_value;
if (array_key_exists($_locale, $translations)) {
$RuntimeModel->save(array($RuntimeModel->alias => array_merge($conditions, array('id' => $translations[$_locale]))));
$RuntimeModel->save(array(
$RuntimeModel->alias => array_merge(
$conditions, array('id' => $translations[$_locale])
)
));
} else {
$RuntimeModel->save(array($RuntimeModel->alias => $conditions));
}
@ -632,7 +646,6 @@ class TranslateBehavior extends ModelBehavior {
if (is_string($fields)) {
$fields = array($fields);
}
$RuntimeModel = $this->translateModel($Model);
$associations = array();
foreach ($fields as $key => $value) {

View file

@ -418,26 +418,26 @@ class CakeSchema extends Object {
}
$col = "\t\t'{$field}' => array('type' => '" . $value['type'] . "', ";
unset($value['type']);
$col .= join(', ', $this->_values($value));
$col .= implode(', ', $this->_values($value));
} elseif ($field == 'indexes') {
$col = "\t\t'indexes' => array(\n\t\t\t";
$props = array();
foreach ((array)$value as $key => $index) {
$props[] = "'{$key}' => array(" . join(', ', $this->_values($index)) . ")";
$props[] = "'{$key}' => array(" . implode(', ', $this->_values($index)) . ")";
}
$col .= join(",\n\t\t\t", $props) . "\n\t\t";
$col .= implode(",\n\t\t\t", $props) . "\n\t\t";
} elseif ($field == 'tableParameters') {
$col = "\t\t'tableParameters' => array(";
$props = array();
foreach ((array)$value as $key => $param) {
$props[] = "'{$key}' => '$param'";
}
$col .= join(', ', $props);
$col .= implode(', ', $props);
}
$col .= ")";
$cols[] = $col;
}
$out .= join(",\n", $cols);
$out .= implode(",\n", $cols);
}
$out .= "\n\t);\n";
return $out;

View file

@ -218,8 +218,7 @@ class CakeSession {
if (empty($name)) {
return false;
}
$result = Hash::get($_SESSION, $name);
return isset($result);
return Hash::get($_SESSION, $name) !== null;
}
/**
@ -283,9 +282,8 @@ class CakeSession {
protected static function _error($errorNumber) {
if (!is_array(self::$error) || !array_key_exists($errorNumber, self::$error)) {
return false;
} else {
return self::$error[$errorNumber];
}
return self::$error[$errorNumber];
}
/**
@ -449,7 +447,6 @@ class CakeSession {
*/
protected static function _configureSession() {
$sessionConfig = Configure::read('Session');
$iniSet = function_exists('ini_set');
if (isset($sessionConfig['defaults'])) {
$defaults = self::_defaultConfig($sessionConfig['defaults']);

View file

@ -150,7 +150,10 @@ class Mysql extends DboSource {
);
$this->connected = true;
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
@ -423,17 +426,22 @@ class Mysql extends DboSource {
$table = $this->fullTableName($model);
$old = version_compare($this->getVersion(), '4.1', '<=');
if ($table) {
$indices = $this->_execute('SHOW INDEX FROM ' . $table);
$indexes = $this->_execute('SHOW INDEX FROM ' . $table);
// @codingStandardsIgnoreStart
// MySQL columns don't match the cakephp conventions.
while ($idx = $indices->fetch(PDO::FETCH_OBJ)) {
while ($idx = $indexes->fetch(PDO::FETCH_OBJ)) {
if ($old) {
$idx = (object)current((array)$idx);
}
if (!isset($index[$idx->Key_name]['column'])) {
$col = array();
$index[$idx->Key_name]['column'] = $idx->Column_name;
$index[$idx->Key_name]['unique'] = intval(!$idx->Non_unique);
if ($idx->Index_type === 'FULLTEXT') {
$index[$idx->Key_name]['type'] = strtolower($idx->Index_type);
} else {
$index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0);
}
} else {
if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) {
$col[] = $index[$idx->Key_name]['column'];
@ -443,7 +451,7 @@ class Mysql extends DboSource {
}
}
// @codingStandardsIgnoreEnd
$indices->closeCursor();
$indexes->closeCursor();
}
return $index;
}
@ -553,31 +561,18 @@ class Mysql extends DboSource {
if (isset($indexes['drop'])) {
foreach ($indexes['drop'] as $name => $value) {
$out = 'DROP ';
if ($name == 'PRIMARY') {
if ($name === 'PRIMARY') {
$out .= 'PRIMARY KEY';
} else {
$out .= 'KEY ' . $name;
$out .= 'KEY ' . $this->startQuote . $name . $this->endQuote;
}
$alter[] = $out;
}
}
if (isset($indexes['add'])) {
foreach ($indexes['add'] as $name => $value) {
$out = 'ADD ';
if ($name == 'PRIMARY') {
$out .= 'PRIMARY ';
$name = null;
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
}
if (is_array($value['column'])) {
$out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')';
}
$alter[] = $out;
$add = $this->buildIndex($indexes['add']);
foreach ($add as $index) {
$alter[] = 'ADD ' . $index;
}
}
return $alter;

View file

@ -122,7 +122,10 @@ class Postgres extends DboSource {
$this->_execute('SET search_path TO ' . $config['schema']);
}
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
return $this->connected;
@ -291,6 +294,24 @@ class Postgres extends DboSource {
}
}
/**
* Reset a sequence based on the MAX() value of $column. Useful
* for resetting sequences after using insertMulti().
*
* @param string $table The name of the table to update.
* @param string $column The column to use when reseting the sequence value, the
* sequence name will be fetched using Postgres::getSequence();
* @return boolean success.
*/
public function resetSequence($table, $column) {
$tableName = $this->fullTableName($table, false, false);
$fullTable = $this->fullTableName($table);
$sequence = $this->value($this->getSequence($tableName, $column));
$this->execute("SELECT setval($sequence, (SELECT MAX(id) FROM $fullTable))");
return true;
}
/**
* Deletes all the records in a table and drops all associated auto-increment sequences
*
@ -439,7 +460,7 @@ class Postgres extends DboSource {
)
AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", false);
foreach ($indexes as $i => $info) {
foreach ($indexes as $info) {
$key = array_pop($info);
if ($key['indisprimary']) {
$key['relname'] = 'PRIMARY';

View file

@ -114,7 +114,10 @@ class Sqlite extends DboSource {
$this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags);
$this->connected = true;
} catch(PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
return $this->connected;
}
@ -459,7 +462,7 @@ class Sqlite extends DboSource {
$out .= 'UNIQUE ';
}
if (is_array($value['column'])) {
$value['column'] = join(', ', array_map(array(&$this, 'name'), $value['column']));
$value['column'] = implode(', ', array_map(array(&$this, 'name'), $value['column']));
} else {
$value['column'] = $this->name($value['column']);
}
@ -488,7 +491,7 @@ class Sqlite extends DboSource {
if (is_bool($indexes)) {
return array();
}
foreach ($indexes as $i => $info) {
foreach ($indexes as $info) {
$key = array_pop($info);
$keyInfo = $this->query('PRAGMA index_info("' . $key['name'] . '")');
foreach ($keyInfo as $keyCol) {
@ -524,10 +527,10 @@ class Sqlite extends DboSource {
case 'schema':
extract($data);
if (is_array($columns)) {
$columns = "\t" . join(",\n\t", array_filter($columns));
$columns = "\t" . implode(",\n\t", array_filter($columns));
}
if (is_array($indexes)) {
$indexes = "\t" . join("\n\t", array_filter($indexes));
$indexes = "\t" . implode("\n\t", array_filter($indexes));
}
return "CREATE TABLE {$table} (\n{$columns});\n{$indexes}";
default:

View file

@ -130,7 +130,10 @@ class Sqlserver extends DboSource {
);
$this->connected = true;
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
return $this->connected;

View file

@ -253,6 +253,7 @@ class DboSource extends DataSource {
if (!$this->enabled()) {
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => __d('cake_dev', 'Selected driver is not enabled'),
'enabled' => false
));
}
@ -599,7 +600,7 @@ class DboSource extends DataSource {
} else {
if (isset($args[1]) && $args[1] === true) {
return $this->fetchAll($args[0], true);
} elseif (isset($args[1]) && !is_array($args[1]) ) {
} elseif (isset($args[1]) && !is_array($args[1])) {
return $this->fetchAll($args[0], false);
} elseif (isset($args[1]) && is_array($args[1])) {
if (isset($args[2])) {
@ -1294,9 +1295,9 @@ class DboSource extends DataSource {
}
}
if ($type === 'hasAndBelongsToMany') {
$uniqueIds = $merge = array();
$merge = array();
foreach ($fetch as $j => $data) {
foreach ($fetch as $data) {
if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$modelAlias][$modelPK]) {
if ($habtmFieldsCount <= 2) {
unset($data[$with]);
@ -1444,7 +1445,7 @@ class DboSource extends DataSource {
$data[$association] = array();
}
} else {
foreach ($merge as $i => $row) {
foreach ($merge as $row) {
$insert = array();
if (count($row) === 1) {
$insert = $row[$association];
@ -1765,7 +1766,7 @@ class DboSource extends DataSource {
case 'schema':
foreach (array('columns', 'indexes', 'tableParameters') as $var) {
if (is_array(${$var})) {
${$var} = "\t" . join(",\n\t", array_filter(${$var}));
${$var} = "\t" . implode(",\n\t", array_filter(${$var}));
} else {
${$var} = '';
}
@ -2412,7 +2413,7 @@ class DboSource extends DataSource {
}
$clauses = '/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i';
if (preg_match($clauses, $conditions, $match)) {
if (preg_match($clauses, $conditions)) {
$clause = '';
}
$conditions = $this->_quoteFields($conditions);
@ -2907,7 +2908,7 @@ class DboSource extends DataSource {
$columnMap[$key] = $pdoMap[$type];
}
foreach ($values as $row => $value) {
foreach ($values as $value) {
$i = 1;
foreach ($value as $col => $val) {
$statement->bindValue($i, $val, $columnMap[$col]);
@ -2919,6 +2920,19 @@ class DboSource extends DataSource {
return $this->commit();
}
/**
* Reset a sequence based on the MAX() value of $column. Useful
* for resetting sequences after using insertMulti().
*
* This method should be implemented by datasources that require sequences to be used.
*
* @param string $table The name of the table to update.
* @param string $column The column to use when reseting the sequence value.
* @return boolean success.
*/
public function resetSequence($table, $column) {
}
/**
* Returns an array of the indexes in given datasource name.
*
@ -3111,7 +3125,7 @@ class DboSource extends DataSource {
}
/**
* Format indexes for create table
* Format indexes for create table.
*
* @param array $indexes
* @param string $table
@ -3127,6 +3141,8 @@ class DboSource extends DataSource {
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
} elseif (!empty($value['type']) && strtoupper($value['type']) === 'FULLTEXT') {
$out .= 'FULLTEXT ';
}
$name = $this->startQuote . $name . $this->endQuote;
}
@ -3204,7 +3220,7 @@ class DboSource extends DataSource {
$isAllFloat = $isAllInt = true;
$containsFloat = $containsInt = $containsString = false;
foreach ($value as $key => $valElement) {
foreach ($value as $valElement) {
$valElement = trim($valElement);
if (!is_float($valElement) && !preg_match('/^[\d]+\.[\d]+$/', $valElement)) {
$isAllFloat = false;

View file

@ -235,6 +235,13 @@ class Model extends Object implements CakeEventListener {
*/
public $tablePrefix = null;
/**
* Plugin model belongs to.
*
* @var string
*/
public $plugin = null;
/**
* Name of the model.
*
@ -665,12 +672,16 @@ class Model extends Object implements CakeEventListener {
extract(array_merge(
array(
'id' => $this->id, 'table' => $this->useTable, 'ds' => $this->useDbConfig,
'name' => $this->name, 'alias' => $this->alias
'name' => $this->name, 'alias' => $this->alias, 'plugin' => $this->plugin
),
$id
));
}
if ($this->plugin === null) {
$this->plugin = (isset($plugin) ? $plugin : $this->plugin);
}
if ($this->name === null) {
$this->name = (isset($name) ? $name : get_class($this));
}
@ -1869,7 +1880,7 @@ class Model extends Object implements CakeEventListener {
if ($keepExisting && !empty($links)) {
foreach ($links as $link) {
$oldJoin = $link[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
if (! in_array($oldJoin, $newJoins) ) {
if (!in_array($oldJoin, $newJoins)) {
$conditions[$associationForeignKey] = $oldJoin;
$db->delete($this->{$join}, $conditions);
} else {
@ -2362,7 +2373,7 @@ class Model extends Object implements CakeEventListener {
$updateCounterCache = false;
if (!empty($this->belongsTo)) {
foreach ($this->belongsTo as $parent => $assoc) {
foreach ($this->belongsTo as $assoc) {
if (!empty($assoc['counterCache'])) {
$updateCounterCache = true;
break;
@ -2448,7 +2459,7 @@ class Model extends Object implements CakeEventListener {
* @return void
*/
protected function _deleteLinks($id) {
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
foreach ($this->hasAndBelongsToMany as $data) {
list($plugin, $joinModel) = pluginSplit($data['with']);
$records = $this->{$joinModel}->find('all', array(
'conditions' => array($this->{$joinModel}->escapeField($data['foreignKey']) => $id),
@ -2723,7 +2734,7 @@ class Model extends Object implements CakeEventListener {
*/
protected function _findCount($state, $query, $results = array()) {
if ($state === 'before') {
if (!empty($query['type']) && isset($this->findMethods[$query['type']]) && $query['type'] !== 'count' ) {
if (!empty($query['type']) && isset($this->findMethods[$query['type']]) && $query['type'] !== 'count') {
$query['operation'] = 'count';
$query = $this->{'_find' . ucfirst($query['type'])}('before', $query);
}
@ -3041,7 +3052,7 @@ class Model extends Object implements CakeEventListener {
public function isForeignKey($field) {
$foreignKeys = array();
if (!empty($this->belongsTo)) {
foreach ($this->belongsTo as $assoc => $data) {
foreach ($this->belongsTo as $data) {
$foreignKeys[] = $data['foreignKey'];
}
}
@ -3249,7 +3260,7 @@ class Model extends Object implements CakeEventListener {
return array($with, array_unique(array_merge($assoc[$with], $keys)));
}
trigger_error(
__d('cake_dev', 'Invalid join model settings in %s', $model->alias),
__d('cake_dev', 'Invalid join model settings in %s. The association parameter has the wrong type, expecting a string or array, but was passed type: %s', $this->alias, gettype($assoc)),
E_USER_WARNING
);
}

View file

@ -18,8 +18,7 @@
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ModelValidator', 'Model');
App::uses('CakeValidationSet', 'Model/Validator');
App::uses('Validation', 'Utility');
/**

View file

@ -18,7 +18,7 @@
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ModelValidator', 'Model');
App::uses('CakeValidationRule', 'Model/Validator');
/**

View file

@ -675,7 +675,7 @@ class CakeRequest implements ArrayAccess {
public function accepts($type = null) {
$raw = $this->parseAccept();
$accept = array();
foreach ($raw as $value => $types) {
foreach ($raw as $types) {
$accept = array_merge($accept, $types);
}
if ($type === null) {
@ -758,6 +758,16 @@ class CakeRequest implements ArrayAccess {
return $accept;
}
/**
* Provides a read accessor for `$this->query`. Allows you
* to use a syntax similar to `CakeSession` for reading url query data.
*
* @return mixed The value being read
*/
public function query($name) {
return Hash::get($this->query, $name);
}
/**
* Provides a read/write accessor for `$this->data`. Allows you
* to use a syntax similar to `CakeSession` for reading post data.

View file

@ -384,9 +384,10 @@ class CakeResponse {
if (isset($options['type'])) {
$this->type($options['type']);
}
if (isset($options['charset'])) {
$this->charset($options['charset']);
if (!isset($options['charset'])) {
$options['charset'] = Configure::read('App.encoding');
}
$this->charset($options['charset']);
}
/**
@ -746,7 +747,7 @@ class CakeResponse {
* @return void
*/
public function cache($since, $time = '+1 day') {
if (!is_integer($time)) {
if (!is_int($time)) {
$time = strtotime($time);
}
$this->header(array(
@ -1008,7 +1009,7 @@ class CakeResponse {
protected function _getUTCDate($time = null) {
if ($time instanceof DateTime) {
$result = clone $time;
} elseif (is_integer($time)) {
} elseif (is_int($time)) {
$result = new DateTime(date('Y-m-d H:i:s', $time));
} else {
$result = new DateTime($time);
@ -1070,7 +1071,7 @@ class CakeResponse {
* @return int
*/
public function length($bytes = null) {
if ($bytes !== null ) {
if ($bytes !== null) {
$this->_headers['Content-Length'] = $bytes;
}
if (isset($this->_headers['Content-Length'])) {

View file

@ -325,7 +325,7 @@ class CakeEmail {
if ($this->_appCharset !== null) {
$this->charset = $this->_appCharset;
}
$this->_domain = env('HTTP_HOST');
$this->_domain = preg_replace('/\:\d+$/', '', env('HTTP_HOST'));
if (empty($this->_domain)) {
$this->_domain = php_uname('n');
}

View file

@ -41,14 +41,31 @@ class MailTransport extends AbstractTransport {
unset($headers['To']);
$headers = $this->_headersToString($headers, $eol);
$message = implode($eol, $email->message());
if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
if (!@mail($to, $email->subject(), $message, $headers)) {
throw new SocketException(__d('cake_dev', 'Could not send email.'));
}
} elseif (!@mail($to, $email->subject(), $message, $headers, $this->_config['additionalParameters'])) {
throw new SocketException(__d('cake_dev', 'Could not send email.'));
$params = null;
if (!ini_get('safe_mode')) {
$params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
}
$this->_mail($to, $email->subject(), $message, $headers, $params);
return array('headers' => $headers, 'message' => $message);
}
/**
* Wraps internal function mail() and throws exception instead of errors if anything goes wrong
*
* @param string $to email's recipient
* @param string $subject email's subject
* @param string $message email's body
* @param string $headers email's custom headers
* @param string $params additional params for sending email
* @throws SocketException if mail could not be sent
* @return void
*/
protected function _mail($to, $subject, $message, $headers, $params = null) {
if (!@mail($to, $subject, $message, $headers, $params)) {
throw new SocketException(__d('cake_dev', 'Could not send email.'));
}
}
}

View file

@ -42,8 +42,6 @@ class AssetDispatcher extends DispatcherFilter {
*/
public function beforeDispatch($event) {
$url = $event->data['request']->url;
$response = $event->data['response'];
if (strpos($url, '..') !== false || strpos($url, '.') === false) {
return;
}
@ -53,43 +51,27 @@ class AssetDispatcher extends DispatcherFilter {
return $result;
}
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$parts = explode('/', $url);
$assetFile = null;
if ($parts[0] === 'theme') {
$themeName = $parts[1];
unset($parts[0], $parts[1]);
$fileFragment = urldecode(implode(DS, $parts));
$path = App::themePath($themeName) . 'webroot' . DS;
if (file_exists($path . $fileFragment)) {
$assetFile = $path . $fileFragment;
}
} else {
$plugin = Inflector::camelize($parts[0]);
if (CakePlugin::loaded($plugin)) {
unset($parts[0]);
$fileFragment = urldecode(implode(DS, $parts));
$pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS;
if (file_exists($pluginWebroot . $fileFragment)) {
$assetFile = $pluginWebroot . $fileFragment;
}
}
$assetFile = $this->_getAssetFile($url);
if ($assetFile === null || !file_exists($assetFile)) {
return null;
}
if ($assetFile !== null) {
$event->stopPropagation();
$response->modified(filemtime($assetFile));
if (!$response->checkNotModified($event->data['request'])) {
$this->_deliverAsset($response, $assetFile, $ext);
}
$response = $event->data['response'];
$event->stopPropagation();
$response->modified(filemtime($assetFile));
if ($response->checkNotModified($event->data['request'])) {
return $response;
}
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$this->_deliverAsset($response, $assetFile, $ext);
return $response;
}
/**
* Checks if the client is requeting a filtered asset and runs the corresponding
* Checks if the client is requesting a filtered asset and runs the corresponding
* filter if any is configured
*
* @param CakeEvent $event containing the request and response object
@ -111,15 +93,44 @@ class AssetDispatcher extends DispatcherFilter {
if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
$response->statusCode(404);
return $response;
} elseif ($isCss) {
}
if ($isCss) {
include WWW_ROOT . DS . $filters['css'];
return $response;
} elseif ($isJs) {
}
if ($isJs) {
include WWW_ROOT . DS . $filters['js'];
return $response;
}
}
/**
* Builds asset file path based off url
*
* @param string $url
* @return string Absolute path for asset file
*/
protected function _getAssetFile($url) {
$parts = explode('/', $url);
if ($parts[0] === 'theme') {
$themeName = $parts[1];
unset($parts[0], $parts[1]);
$fileFragment = urldecode(implode(DS, $parts));
$path = App::themePath($themeName) . 'webroot' . DS;
return $path . $fileFragment;
}
$plugin = Inflector::camelize($parts[0]);
if (CakePlugin::loaded($plugin)) {
unset($parts[0]);
$fileFragment = urldecode(implode(DS, $parts));
$pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS;
return $pluginWebroot . $fileFragment;
}
}
/**
* Sends an asset file to the client
*

View file

@ -219,7 +219,7 @@ class CakeRoute {
if (isset($route[$key])) {
continue;
}
if (is_integer($key)) {
if (is_int($key)) {
$route['pass'][] = $value;
continue;
}

View file

@ -523,7 +523,7 @@ class Router {
$ext = null;
$out = array();
if ($url && strpos($url, '/') !== 0) {
if (strlen($url) && strpos($url, '/') !== 0) {
$url = '/' . $url;
}
if (strpos($url, '?') !== false) {

View file

@ -191,9 +191,9 @@ class ControllerTaskTest extends CakeTestCase {
*/
public function testDoHelpersTrailingSpace() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne '));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne '));
$result = $this->Task->doHelpers();
$expected = array('Javascript', 'Ajax', 'CustomOne');
$expected = array('Text', 'Number', 'CustomOne');
$this->assertEquals($expected, $result);
}
@ -204,9 +204,9 @@ class ControllerTaskTest extends CakeTestCase {
*/
public function testDoHelpersTrailingCommas() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , '));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));
$result = $this->Task->doHelpers();
$expected = array('Javascript', 'Ajax', 'CustomOne');
$expected = array('Text', 'Number', 'CustomOne');
$this->assertEquals($expected, $result);
}
@ -257,11 +257,11 @@ class ControllerTaskTest extends CakeTestCase {
public function testConfirmController() {
$controller = 'Posts';
$scaffold = false;
$helpers = array('Ajax', 'Time');
$helpers = array('Js', 'Time');
$components = array('Acl', 'Auth');
$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time");
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");
$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
}
@ -272,7 +272,7 @@ class ControllerTaskTest extends CakeTestCase {
* @return void
*/
public function testBake() {
$helpers = array('Ajax', 'Time');
$helpers = array('Js', 'Time');
$components = array('Acl', 'Auth');
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
@ -282,7 +282,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertContains(' * @property AuthComponent $Auth', $result);
$this->assertContains('class ArticlesController extends AppController', $result);
$this->assertContains("public \$components = array('Acl', 'Auth')", $result);
$this->assertContains("public \$helpers = array('Ajax', 'Time')", $result);
$this->assertContains("public \$helpers = array('Js', 'Time')", $result);
$this->assertContains("--actions--", $result);
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
@ -350,7 +350,8 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertContains('function view($id = null)', $result);
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
$this->assertContains("\$options = array('conditions' => array('BakeArticle.' . \$this->BakeArticle->primaryKey => \$id));", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);
$this->assertContains('function add()', $result);
$this->assertContains("if (\$this->request->is('post'))", $result);
@ -389,7 +390,7 @@ class ControllerTaskTest extends CakeTestCase {
$this->assertContains('function view($id = null)', $result);
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);
$this->assertContains('function add()', $result);
$this->assertContains("if (\$this->request->is('post'))", $result);

View file

@ -315,7 +315,7 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->initValidations();
$this->Task->interactive = true;
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('23', 'y', '17', 'n'));
->will($this->onConsecutiveCalls('24', 'y', '18', 'n'));
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
@ -333,7 +333,7 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->interactive = true;
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('999999', '23', 'n'));
->will($this->onConsecutiveCalls('999999', '24', 'n'));
$this->Task->expects($this->at(10))->method('out')
->with($this->stringContains('make a valid'));

View file

@ -694,7 +694,7 @@ class TestTaskTest extends CakeTestCase {
public function testTestCaseFileNamePlugin() {
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS ));
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$this->Task->plugin = 'TestTest';
$result = $this->Task->testCaseFileName('Model', 'Post');
$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';

View file

@ -60,6 +60,23 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
$this->Error->handleError(E_NOTICE, 'This is a notice error', '/some/file', 275);
}
/**
* test that the console error handler can deal with fatal errors.
*
* @return void
*/
public function testHandleFatalError() {
$content = "<error>Fatal Error Error:</error> This is a fatal error in [/some/file, line 275]\n";
ConsoleErrorHandler::$stderr->expects($this->once())->method('write')
->with($content);
$this->Error->expects($this->once())
->method('_stop')
->with(1);
$this->Error->handleError(E_USER_ERROR, 'This is a fatal error', '/some/file', 275);
}
/**
* test that the console error handler can deal with CakeExceptions.
*

View file

@ -118,7 +118,7 @@ class PhpAclTest extends CakeTestCase {
$this->Acl->Aro->addAlias(array('Role/25' => 'Role/IT'));
$this->Acl->allow('Role/IT', '/rules/debugging/*');
$this->assertEquals(array(array('Role/IT', )), $this->Acl->Aro->roles($user));
$this->assertEquals(array(array('Role/IT')), $this->Acl->Aro->roles($user));
$this->assertTrue($this->Acl->check($user, '/rules/debugging/stats/pageload'));
$this->assertTrue($this->Acl->check($user, '/rules/debugging/sql/queries'));
// Role/default is allowed users dashboard, but not Role/IT

View file

@ -51,6 +51,9 @@ class BlowfishAuthenticateTest extends CakeTestCase {
$User = ClassRegistry::init('User');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$this->response = $this->getMock('CakeResponse');
$hash = Security::hash('password', 'blowfish');
$this->skipIf(strpos($hash, '$2a$') === false, 'Skipping blowfish tests as hashing is not working');
}
/**

View file

@ -271,12 +271,14 @@ class CookieComponentTest extends CakeTestCase {
$expected = array(
'name' => $this->Cookie->name . '[Testing]',
'value' => '[1,2,3]',
'expire' => time() + 10,
'path' => '/',
'domain' => '',
'secure' => false,
'httpOnly' => false);
$result = $this->Controller->response->cookie($this->Cookie->name . '[Testing]');
$this->assertWithinMargin($result['expire'], time() + 10, 1);
unset($result['expire']);
$this->assertEquals($expected, $result);
}
@ -536,6 +538,60 @@ class CookieComponentTest extends CakeTestCase {
$this->assertNull($this->Cookie->read('value'));
}
/**
* testCheck method
*
* @return void
*/
public function testCheck() {
$this->Cookie->write('CookieComponentTestCase', 'value');
$this->assertTrue($this->Cookie->check('CookieComponentTestCase'));
$this->assertFalse($this->Cookie->check('NotExistingCookieComponentTestCase'));
}
/**
* testCheckingSavedEmpty method
*
* @return void
*/
public function testCheckingSavedEmpty() {
$this->Cookie->write('CookieComponentTestCase', 0);
$this->assertTrue($this->Cookie->check('CookieComponentTestCase'));
$this->Cookie->write('CookieComponentTestCase', '0');
$this->assertTrue($this->Cookie->check('CookieComponentTestCase'));
$this->Cookie->write('CookieComponentTestCase', false);
$this->assertTrue($this->Cookie->check('CookieComponentTestCase'));
$this->Cookie->write('CookieComponentTestCase', null);
$this->assertFalse($this->Cookie->check('CookieComponentTestCase'));
}
/**
* testCheckKeyWithSpaces method
*
* @return void
*/
public function testCheckKeyWithSpaces() {
$this->Cookie->write('CookieComponent Test', "test");
$this->assertTrue($this->Cookie->check('CookieComponent Test'));
$this->Cookie->delete('CookieComponent Test');
$this->Cookie->write('CookieComponent Test.Test Case', "test");
$this->assertTrue($this->Cookie->check('CookieComponent Test.Test Case'));
}
/**
* testCheckEmpty
*
* @return void
*/
public function testCheckEmpty() {
$this->assertFalse($this->Cookie->check());
}
/**
* test that deleting a top level keys kills the child elements too.
*

View file

@ -177,6 +177,60 @@ class ConfigureTest extends CakeTestCase {
$this->assertTrue($result === null);
}
/**
* testCheck method
*
* @return void
*/
public function testCheck() {
Configure::write('ConfigureTestCase', 'value');
$this->assertTrue(Configure::check('ConfigureTestCase'));
$this->assertFalse(Configure::check('NotExistingConfigureTestCase'));
}
/**
* testCheckingSavedEmpty method
*
* @return void
*/
public function testCheckingSavedEmpty() {
$this->assertTrue(Configure::write('ConfigureTestCase', 0));
$this->assertTrue(Configure::check('ConfigureTestCase'));
$this->assertTrue(Configure::write('ConfigureTestCase', '0'));
$this->assertTrue(Configure::check('ConfigureTestCase'));
$this->assertTrue(Configure::write('ConfigureTestCase', false));
$this->assertTrue(Configure::check('ConfigureTestCase'));
$this->assertTrue(Configure::write('ConfigureTestCase', null));
$this->assertFalse(Configure::check('ConfigureTestCase'));
}
/**
* testCheckKeyWithSpaces method
*
* @return void
*/
public function testCheckKeyWithSpaces() {
$this->assertTrue(Configure::write('Configure Test', "test"));
$this->assertTrue(Configure::check('Configure Test'));
Configure::delete('Configure Test');
$this->assertTrue(Configure::write('Configure Test.Test Case', "test"));
$this->assertTrue(Configure::check('Configure Test.Test Case'));
}
/**
* testCheckEmpty
*
* @return void
*/
public function testCheckEmpty() {
$this->assertFalse(Configure::check());
}
/**
* testLoad method
*

View file

@ -573,10 +573,10 @@ class ExceptionRendererTest extends CakeTestCase {
500
),
array(
new MissingConnectionException(array('class' => 'Article')),
new MissingConnectionException(array('class' => 'Mysql')),
array(
'/<h2>Missing Database Connection<\/h2>/',
'/Article requires a database connection/'
'/A Database connection using "Mysql" was missing or unable to connect./',
),
500
),
@ -584,7 +584,7 @@ class ExceptionRendererTest extends CakeTestCase {
new MissingConnectionException(array('class' => 'Mysql', 'enabled' => false)),
array(
'/<h2>Missing Database Connection<\/h2>/',
'/Mysql requires a database connection/',
'/A Database connection using "Mysql" was missing or unable to connect./',
'/Mysql driver is NOT enabled/'
),
500
@ -691,25 +691,49 @@ class ExceptionRendererTest extends CakeTestCase {
$exception = new MissingHelperException(array('class' => 'Fail'));
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller = $this->getMock('Controller');
$ExceptionRenderer->controller = $this->getMock('Controller', array('render'));
$ExceptionRenderer->controller->helpers = array('Fail', 'Boom');
$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
$ExceptionRenderer->controller->expects($this->at(2))
$ExceptionRenderer->controller->expects($this->at(0))
->method('render')
->with('missingHelper')
->will($this->throwException($exception));
$ExceptionRenderer->controller->expects($this->at(4))
->method('render')
->with('error500')
->will($this->returnValue(true));
$response = $this->getMock('CakeResponse');
$response->expects($this->once())
->method('body')
->with($this->stringContains('Helper class Fail'));
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse');
$ExceptionRenderer->controller->response = $response;
$ExceptionRenderer->render();
sort($ExceptionRenderer->controller->helpers);
$this->assertEquals(array('Form', 'Html', 'Session'), $ExceptionRenderer->controller->helpers);
}
/**
* Test that exceptions in beforeRender() are handled by outputMessageSafe
*
* @return void
*/
public function testRenderExceptionInBeforeRender() {
$exception = new NotFoundException('Not there, sorry');
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller = $this->getMock('Controller', array('beforeRender'));
$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
$ExceptionRenderer->controller->expects($this->any())
->method('beforeRender')
->will($this->throwException($exception));
$response = $this->getMock('CakeResponse');
$response->expects($this->once())
->method('body')
->with($this->stringContains('Not there, sorry'));
$ExceptionRenderer->controller->response = $response;
$ExceptionRenderer->render();
}
/**
* Test that missing subDir/layoutPath don't cause other fatal errors.
*
@ -719,32 +743,31 @@ class ExceptionRendererTest extends CakeTestCase {
$exception = new NotFoundException();
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller = $this->getMock('Controller');
$ExceptionRenderer->controller = $this->getMock('Controller', array('render'));
$ExceptionRenderer->controller->helpers = array('Fail', 'Boom');
$ExceptionRenderer->controller->layoutPath = 'json';
$ExceptionRenderer->controller->subDir = 'json';
$ExceptionRenderer->controller->viewClass = 'Json';
$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
$ExceptionRenderer->controller->expects($this->at(1))
$ExceptionRenderer->controller->expects($this->once())
->method('render')
->with('error400')
->will($this->throwException($exception));
$ExceptionRenderer->controller->expects($this->at(3))
->method('render')
->with('error500')
->will($this->returnValue(true));
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse');
$ExceptionRenderer->controller->response->expects($this->once())
$response = $this->getMock('CakeResponse');
$response->expects($this->once())
->method('body')
->with($this->stringContains('Not Found'));
$response->expects($this->once())
->method('type')
->with('html');
$ExceptionRenderer->controller->response = $response;
$ExceptionRenderer->render();
$this->assertEquals('', $ExceptionRenderer->controller->layoutPath);
$this->assertEquals('', $ExceptionRenderer->controller->subDir);
$this->assertEquals('View', $ExceptionRenderer->controller->viewClass);
$this->assertEquals('Errors/', $ExceptionRenderer->controller->viewPath);
}

View file

@ -1893,7 +1893,7 @@ class I18nTest extends CakeTestCase {
private function __domainPlural($domain = 'test_plugin') {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', (float)$number), (float)$number );
$plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', (float)$number), (float)$number);
}
return $plurals;
}
@ -1949,7 +1949,7 @@ class I18nTest extends CakeTestCase {
private function __pluralFromCore() {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number );
$plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number);
}
return $plurals;
}

View file

@ -125,8 +125,12 @@ class L10nTest extends CakeTestCase {
$expected = array('afr' => 'af', 'af' => 'afr');
$this->assertEquals($expected, $result);
$result = $localize->map(array('sqi', 'sq'));
$expected = array('sqi' => 'sq', 'sq' => 'sqi');
$this->assertEquals($expected, $result);
$result = $localize->map(array('alb', 'sq'));
$expected = array('alb' => 'sq', 'sq' => 'alb');
$expected = array('alb' => 'sq', 'sq' => 'sqi');
$this->assertEquals($expected, $result);
$result = $localize->map(array('ara', 'ar'));
@ -137,12 +141,12 @@ class L10nTest extends CakeTestCase {
$expected = array('hye' => 'hy', 'hy' => 'hye');
$this->assertEquals($expected, $result);
$result = $localize->map(array('baq', 'eu'));
$expected = array('baq' => 'eu', 'eu' => 'baq');
$result = $localize->map(array('eus', 'eu'));
$expected = array('eus' => 'eu', 'eu' => 'eus');
$this->assertEquals($expected, $result);
$result = $localize->map(array('baq', 'eu'));
$expected = array('baq' => 'eu', 'eu' => 'baq');
$expected = array('baq' => 'eu', 'eu' => 'eus');
$this->assertEquals($expected, $result);
$result = $localize->map(array('bos', 'bs'));
@ -162,11 +166,11 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('chi', 'zh'));
$expected = array('chi' => 'zh', 'zh' => 'chi');
$expected = array('chi' => 'zh', 'zh' => 'zho');
$this->assertEquals($expected, $result);
$result = $localize->map(array('zho', 'zh'));
$expected = array('zho' => 'zh', 'zh' => 'chi');
$expected = array('zho' => 'zh', 'zh' => 'zho');
$this->assertEquals($expected, $result);
$result = $localize->map(array('hrv', 'hr'));
@ -174,11 +178,11 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('ces', 'cs'));
$expected = array('ces' => 'cs', 'cs' => 'cze');
$expected = array('ces' => 'cs', 'cs' => 'ces');
$this->assertEquals($expected, $result);
$result = $localize->map(array('cze', 'cs'));
$expected = array('cze' => 'cs', 'cs' => 'cze');
$expected = array('cze' => 'cs', 'cs' => 'ces');
$this->assertEquals($expected, $result);
$result = $localize->map(array('dan', 'da'));
@ -186,17 +190,21 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('dut', 'nl'));
$expected = array('dut' => 'nl', 'nl' => 'dut');
$expected = array('dut' => 'nl', 'nl' => 'nld');
$this->assertEquals($expected, $result);
$result = $localize->map(array('nld', 'nl'));
$expected = array('nld' => 'nl', 'nl' => 'dut');
$expected = array('nld' => 'nl', 'nl' => 'nld');
$this->assertEquals($expected, $result);
$result = $localize->map(array('nld'));
$expected = array('nld' => 'nl');
$this->assertEquals($expected, $result);
$result = $localize->map(array('dut'));
$expected = array('dut' => 'nl');
$this->assertEquals($expected, $result);
$result = $localize->map(array('eng', 'en'));
$expected = array('eng' => 'en', 'en' => 'eng');
$this->assertEquals($expected, $result);
@ -222,11 +230,11 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('fra', 'fr'));
$expected = array('fra' => 'fr', 'fr' => 'fre');
$expected = array('fra' => 'fr', 'fr' => 'fra');
$this->assertEquals($expected, $result);
$result = $localize->map(array('fre', 'fr'));
$expected = array('fre' => 'fr', 'fr' => 'fre');
$expected = array('fre' => 'fr', 'fr' => 'fra');
$this->assertEquals($expected, $result);
$result = $localize->map(array('gla', 'gd'));
@ -266,11 +274,11 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('ice', 'is'));
$expected = array('ice' => 'is', 'is' => 'ice');
$expected = array('ice' => 'is', 'is' => 'isl');
$this->assertEquals($expected, $result);
$result = $localize->map(array('isl', 'is'));
$expected = array('isl' => 'is', 'is' => 'ice');
$expected = array('isl' => 'is', 'is' => 'isl');
$this->assertEquals($expected, $result);
$result = $localize->map(array('ind', 'id'));
@ -302,19 +310,19 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('mac', 'mk'));
$expected = array('mac' => 'mk', 'mk' => 'mac');
$expected = array('mac' => 'mk', 'mk' => 'mkd');
$this->assertEquals($expected, $result);
$result = $localize->map(array('mkd', 'mk'));
$expected = array('mkd' => 'mk', 'mk' => 'mac');
$expected = array('mkd' => 'mk', 'mk' => 'mkd');
$this->assertEquals($expected, $result);
$result = $localize->map(array('may', 'ms'));
$expected = array('may' => 'ms', 'ms' => 'may');
$expected = array('may' => 'ms', 'ms' => 'msa');
$this->assertEquals($expected, $result);
$result = $localize->map(array('msa', 'ms'));
$expected = array('msa' => 'ms', 'ms' => 'may');
$expected = array('msa' => 'ms', 'ms' => 'msa');
$this->assertEquals($expected, $result);
$result = $localize->map(array('mlt', 'mt'));
@ -346,11 +354,11 @@ class L10nTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$result = $localize->map(array('ron', 'ro'));
$expected = array('ron' => 'ro', 'ro' => 'rum');
$expected = array('ron' => 'ro', 'ro' => 'ron');
$this->assertEquals($expected, $result);
$result = $localize->map(array('rum', 'ro'));
$expected = array('rum' => 'ro', 'ro' => 'rum');
$expected = array('rum' => 'ro', 'ro' => 'ron');
$this->assertEquals($expected, $result);
$result = $localize->map(array('rus', 'ru'));
@ -361,20 +369,16 @@ class L10nTest extends CakeTestCase {
$expected = array('smi' => 'sz', 'sz' => 'smi');
$this->assertEquals($expected, $result);
$result = $localize->map(array('scc', 'sr'));
$expected = array('scc' => 'sr', 'sr' => 'scc');
$this->assertEquals($expected, $result);
$result = $localize->map(array('srp', 'sr'));
$expected = array('srp' => 'sr', 'sr' => 'scc');
$expected = array('srp' => 'sr', 'sr' => 'srp');
$this->assertEquals($expected, $result);
$result = $localize->map(array('slk', 'sk'));
$expected = array('slk' => 'sk', 'sk' => 'slo');
$expected = array('slk' => 'sk', 'sk' => 'slk');
$this->assertEquals($expected, $result);
$result = $localize->map(array('slo', 'sk'));
$expected = array('slo' => 'sk', 'sk' => 'slo');
$expected = array('slo' => 'sk', 'sk' => 'slk');
$this->assertEquals($expected, $result);
$result = $localize->map(array('slv', 'sl'));
@ -505,7 +509,7 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('cs'));
$expected = array(
'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr')
'cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -583,7 +587,7 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('eu'));
$expected = array(
'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr')
'eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -607,12 +611,12 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('fr', 'fr-be', 'fr-ca', 'fr-ch', 'fr-fr', 'fr-lu'));
$expected = array(
'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr')
'fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -674,7 +678,7 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('is'));
$expected = array(
'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr')
'is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -721,14 +725,14 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('mk', 'mk-mk'));
$expected = array(
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr')
'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
$result = $localize->catalog(array('ms'));
$expected = array(
'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr')
'ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -740,22 +744,22 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('n', 'nl', 'nl-be'));
$expected = array(
'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr')
'n' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
$result = $localize->catalog('nl');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr');
$this->assertEquals($expected, $result);
$result = $localize->catalog('nld');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr');
$this->assertEquals($expected, $result);
$result = $localize->catalog('dut');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr');
$expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr');
$this->assertEquals($expected, $result);
$result = $localize->catalog(array('nb'));
@ -793,8 +797,8 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('ro', 'ro-mo'));
$expected = array(
'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr')
'ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -806,7 +810,7 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('sk'));
$expected = array(
'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr')
'sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -818,13 +822,13 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('sq'));
$expected = array(
'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr')
'sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
$result = $localize->catalog(array('sr'));
$expected = array(
'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr')
'sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -916,11 +920,11 @@ class L10nTest extends CakeTestCase {
$result = $localize->catalog(array('zh', 'zh-cn', 'zh-hk', 'zh-sg', 'zh-tw'));
$expected = array(
'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr')
'zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -936,7 +940,7 @@ class L10nTest extends CakeTestCase {
'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr')
);
$this->assertEquals($expected, $result);
@ -945,8 +949,8 @@ class L10nTest extends CakeTestCase {
$expected = array(
'eng' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
'deu' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zho' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'),
'rum' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zho' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
'rum' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
'zul' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr'),
'yid' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr')
);

View file

@ -636,8 +636,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$parent = $this->Tree->findByName('1. Root', array('id'));
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.1', )));
$expected = array(array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.1')));
$this->assertSame($expected, $result);
}
@ -658,8 +658,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$parent = $this->Tree->findByName('1. Root', array('id'));
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )));
$expected = array(array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')));
$this->assertSame($expected, $result);
}
@ -680,16 +680,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(
array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.5', )),
array($modelClass => array('name' => '1.3', )),
array($modelClass => array('name' => '1.4', )),
array($modelClass => array('name' => '1.6', )),
array($modelClass => array('name' => '1.7', )),
array($modelClass => array('name' => '1.8', )),
array($modelClass => array('name' => '1.9', )),
array($modelClass => array('name' => '1.10', )));
array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.5')),
array($modelClass => array('name' => '1.3')),
array($modelClass => array('name' => '1.4')),
array($modelClass => array('name' => '1.6')),
array($modelClass => array('name' => '1.7')),
array($modelClass => array('name' => '1.8')),
array($modelClass => array('name' => '1.9')),
array($modelClass => array('name' => '1.10')));
$this->assertSame($expected, $result);
}
@ -710,16 +710,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(
array($modelClass => array('name' => '1.5', )),
array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.3', )),
array($modelClass => array('name' => '1.4', )),
array($modelClass => array('name' => '1.6', )),
array($modelClass => array('name' => '1.7', )),
array($modelClass => array('name' => '1.8', )),
array($modelClass => array('name' => '1.9', )),
array($modelClass => array('name' => '1.10', )));
array($modelClass => array('name' => '1.5')),
array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.3')),
array($modelClass => array('name' => '1.4')),
array($modelClass => array('name' => '1.6')),
array($modelClass => array('name' => '1.7')),
array($modelClass => array('name' => '1.8')),
array($modelClass => array('name' => '1.9')),
array($modelClass => array('name' => '1.10')));
$this->assertSame($expected, $result);
}
@ -739,8 +739,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$parent = $this->Tree->findByName('1. Root', array('id'));
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.1', )));
$expected = array(array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.1')));
$this->assertSame($expected, $result);
}
@ -760,8 +760,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$parent = $this->Tree->findByName('1. Root', array('id'));
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )));
$expected = array(array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')));
$this->assertSame($expected, $result);
}
@ -782,16 +782,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(
array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.3', )),
array($modelClass => array('name' => '1.4', )),
array($modelClass => array('name' => '1.6', )),
array($modelClass => array('name' => '1.7', )),
array($modelClass => array('name' => '1.8', )),
array($modelClass => array('name' => '1.9', )),
array($modelClass => array('name' => '1.10', )),
array($modelClass => array('name' => '1.5', )));
array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.3')),
array($modelClass => array('name' => '1.4')),
array($modelClass => array('name' => '1.6')),
array($modelClass => array('name' => '1.7')),
array($modelClass => array('name' => '1.8')),
array($modelClass => array('name' => '1.9')),
array($modelClass => array('name' => '1.10')),
array($modelClass => array('name' => '1.5')));
$this->assertSame($expected, $result);
}
@ -812,16 +812,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(
array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.3', )),
array($modelClass => array('name' => '1.4', )),
array($modelClass => array('name' => '1.6', )),
array($modelClass => array('name' => '1.7', )),
array($modelClass => array('name' => '1.5', )),
array($modelClass => array('name' => '1.8', )),
array($modelClass => array('name' => '1.9', )),
array($modelClass => array('name' => '1.10', )));
array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.3')),
array($modelClass => array('name' => '1.4')),
array($modelClass => array('name' => '1.6')),
array($modelClass => array('name' => '1.7')),
array($modelClass => array('name' => '1.5')),
array($modelClass => array('name' => '1.8')),
array($modelClass => array('name' => '1.9')),
array($modelClass => array('name' => '1.10')));
$this->assertSame($expected, $result);
}
@ -842,16 +842,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
$this->Tree->id = $parent[$modelClass]['id'];
$result = $this->Tree->children(null, true, array('name'));
$expected = array(
array($modelClass => array('name' => '1.1', )),
array($modelClass => array('name' => '1.2', )),
array($modelClass => array('name' => '1.3', )),
array($modelClass => array('name' => '1.4', )),
array($modelClass => array('name' => 'renamed', )),
array($modelClass => array('name' => '1.6', )),
array($modelClass => array('name' => '1.7', )),
array($modelClass => array('name' => '1.8', )),
array($modelClass => array('name' => '1.9', )),
array($modelClass => array('name' => '1.10', )));
array($modelClass => array('name' => '1.1')),
array($modelClass => array('name' => '1.2')),
array($modelClass => array('name' => '1.3')),
array($modelClass => array('name' => '1.4')),
array($modelClass => array('name' => 'renamed')),
array($modelClass => array('name' => '1.6')),
array($modelClass => array('name' => '1.7')),
array($modelClass => array('name' => '1.8')),
array($modelClass => array('name' => '1.9')),
array($modelClass => array('name' => '1.10')));
$this->assertSame($expected, $result);
}

View file

@ -763,6 +763,23 @@ class CakeSchemaTest extends CakeTestCase {
);
$result = $this->Schema->generateTable('posts', $posts);
$this->assertRegExp('/public \$posts/', $result);
$posts = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true),
'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext')
)
);
$result = $this->Schema->generateTable('fields', $posts);
$this->assertRegExp('/public \$fields/', $result);
$this->assertPattern('/\'type\' \=\> \'fulltext\'/', $result);
}
/**

View file

@ -231,7 +231,7 @@ class CakeSessionTest extends CakeTestCase {
TestCakeSession::write('SessionTestCase', 'value');
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'), false);
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'));
}
/**

View file

@ -320,6 +320,16 @@ class MysqlTest extends CakeTestCase {
$result = $this->Dbo->index('with_multiple_compound_keys', false);
$this->Dbo->rawQuery('DROP TABLE ' . $name);
$this->assertEquals($expected, $result);
$name = $this->Dbo->fullTableName('with_fulltext');
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, name varchar(255), description text, primary key(id), FULLTEXT KEY `MyFtIndex` ( `name`, `description` )) ENGINE=MyISAM;');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext')
);
$result = $this->Dbo->index('with_fulltext', false);
$this->Dbo->rawQuery('DROP TABLE ' . $name);
$this->assertEquals($expected, $result);
}
/**
@ -559,9 +569,9 @@ class MysqlTest extends CakeTestCase {
$result = $this->Dbo->alterSchema($schemaB->compare($schemaA));
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('ADD KEY name_idx (`name`),', $result);
$this->assertContains('ADD KEY group_idx (`group1`),', $result);
$this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result);
$this->assertContains('ADD KEY `name_idx` (`name`),', $result);
$this->assertContains('ADD KEY `group_idx` (`group1`),', $result);
$this->assertContains('ADD KEY `compound_idx` (`group1`, `group2`),', $result);
$this->assertContains('ADD PRIMARY KEY (`id`);', $result);
//Test that the string is syntactically correct
@ -587,13 +597,13 @@ class MysqlTest extends CakeTestCase {
$result = $this->Dbo->alterSchema($schemaC->compare($schemaB));
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('DROP PRIMARY KEY,', $result);
$this->assertContains('DROP KEY name_idx,', $result);
$this->assertContains('DROP KEY group_idx,', $result);
$this->assertContains('DROP KEY compound_idx,', $result);
$this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result);
$this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result);
$this->assertContains('ADD KEY group_idx (`group2`),', $result);
$this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result);
$this->assertContains('DROP KEY `name_idx`,', $result);
$this->assertContains('DROP KEY `group_idx`,', $result);
$this->assertContains('DROP KEY `compound_idx`,', $result);
$this->assertContains('ADD KEY `id_name_idx` (`id`, `name`),', $result);
$this->assertContains('ADD UNIQUE KEY `name_idx` (`name`),', $result);
$this->assertContains('ADD KEY `group_idx` (`group2`),', $result);
$this->assertContains('ADD KEY `compound_idx` (`group2`, `group1`);', $result);
$query = $this->Dbo->getConnection()->prepare($result);
$this->assertEquals($query->queryString, $result);
@ -605,10 +615,10 @@ class MysqlTest extends CakeTestCase {
$result = $this->Dbo->alterSchema($schemaA->compare($schemaC));
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('DROP KEY name_idx,', $result);
$this->assertContains('DROP KEY group_idx,', $result);
$this->assertContains('DROP KEY compound_idx,', $result);
$this->assertContains('DROP KEY id_name_idx;', $result);
$this->assertContains('DROP KEY `name_idx`,', $result);
$this->assertContains('DROP KEY `group_idx`,', $result);
$this->assertContains('DROP KEY `compound_idx`,', $result);
$this->assertContains('DROP KEY `id_name_idx`;', $result);
$query = $this->Dbo->getConnection()->prepare($result);
$this->assertEquals($query->queryString, $result);
@ -2867,6 +2877,13 @@ class MysqlTest extends CakeTestCase {
$result = $this->Dbo->buildIndex($data);
$expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)');
$this->assertEquals($expected, $result);
$data = array(
'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext')
);
$result = $this->Dbo->buildIndex($data);
$expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)');
$this->assertEquals($expected, $result);
}
/**
@ -3270,7 +3287,7 @@ class MysqlTest extends CakeTestCase {
);
$conditions = array('comment_count >' => 2);
$query = 'SELECT ' . join(',', $this->Dbo->fields($Article, null, array('id', 'comment_count'))) .
$query = 'SELECT ' . implode(',', $this->Dbo->fields($Article, null, array('id', 'comment_count'))) .
' FROM ' . $this->Dbo->fullTableName($Article) . ' Article ' . $this->Dbo->conditions($conditions, true, true, $Article);
$result = $this->Dbo->fetchAll($query);
$expected = array(array(

View file

@ -950,4 +950,26 @@ class PostgresTest extends CakeTestCase {
$this->assertNotEmpty($model->read(null, 1));
}
public function testResetSequence() {
$model = new Article();
$table = $this->Dbo->fullTableName($model, false);
$fields = array(
'id', 'user_id', 'title', 'body', 'published',
);
$values = array(
array(1, 1, 'test', 'first post', false),
array(2, 1, 'test 2', 'second post post', false),
);
$this->Dbo->insertMulti($table, $fields, $values);
$sequence = $this->Dbo->getSequence($table);
$result = $this->Dbo->rawQuery("SELECT nextval('$sequence')");
$original = $result->fetch(PDO::FETCH_ASSOC);
$this->assertTrue($this->Dbo->resetSequence($table, 'id'));
$result = $this->Dbo->rawQuery("SELECT currval('$sequence')");
$new = $result->fetch(PDO::FETCH_ASSOC);
$this->assertTrue($new['currval'] > $original['nextval'], 'Sequence did not update');
}
}

View file

@ -1667,6 +1667,14 @@ class ModelIntegrationTest extends BaseModelTest {
$result = $TestModel->alias;
$expected = 'AnotherTest';
$this->assertEquals($expected, $result);
$TestModel = ClassRegistry::init('Test');
$expected = null;
$this->assertEquals($expected, $TestModel->plugin);
$TestModel = ClassRegistry::init('TestPlugin.TestPluginComment');
$expected = 'TestPlugin';
$this->assertEquals($expected, $TestModel->plugin);
}
/**

View file

@ -1678,6 +1678,45 @@ class CakeRequestTest extends CakeTestCase {
}
}
/**
* test the query() method
*
* @return void
*/
public function testQuery() {
$_GET = array();
$_GET['foo'] = 'bar';
$request = new CakeRequest();
$result = $request->query('foo');
$this->assertEquals('bar', $result);
$result = $request->query('imaginary');
$this->assertNull($result);
}
/**
* test the query() method with arrays passed via $_GET
*
* @return void
*/
public function testQueryWithArray() {
$_GET = array();
$_GET['test'] = array('foo', 'bar');
$request = new CakeRequest();
$result = $request->query('test');
$this->assertEquals(array('foo', 'bar'), $result);
$result = $request->query('test.1');
$this->assertEquals('bar', $result);
$result = $request->query('test.2');
$this->assertNull($result);
}
/**
* test the data() method reading
*

View file

@ -204,11 +204,11 @@ class CakeSocketTest extends CakeTestCase {
*/
public function testReset() {
$config = array(
'persistent' => true,
'host' => '127.0.0.1',
'protocol' => 'udp',
'port' => 80,
'timeout' => 20
'persistent' => true,
'host' => '127.0.0.1',
'protocol' => 'udp',
'port' => 80,
'timeout' => 20
);
$anotherSocket = new CakeSocket($config);
$anotherSocket->reset();
@ -222,6 +222,7 @@ class CakeSocketTest extends CakeTestCase {
* @return void
*/
public function testEnableCryptoSocketExceptionNoSsl() {
$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
$configNoSslOrTls = array('host' => 'localhost', 'port' => 80, 'timeout' => 0.1);
// testing exception on no ssl socket server for ssl and tls methods
@ -251,6 +252,7 @@ class CakeSocketTest extends CakeTestCase {
* @return void
*/
protected function _connectSocketToSslTls() {
$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
$configSslTls = array('host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 5);
$this->Socket = new CakeSocket($configSslTls);
$this->Socket->connect();

View file

@ -411,14 +411,18 @@ class CakeEmailTest extends CakeTestCase {
* @return void
*/
public function testMessageIdWithDomain() {
$result = $this->CakeEmail->getHeaders();
$expected = '@' . (env('HTTP_HOST') ? env('HTTP_HOST') : php_uname('n')) . '>';
$this->assertTextContains($expected, $result['Message-ID']);
$this->CakeEmail->domain('example.org');
$result = $this->CakeEmail->getHeaders();
$expected = '@example.org>';
$this->assertTextContains($expected, $result['Message-ID']);
$_SERVER['HTTP_HOST'] = 'example.org';
$result = $this->CakeEmail->getHeaders();
$this->assertTextContains('example.org', $result['Message-ID']);
$_SERVER['HTTP_HOST'] = 'example.org:81';
$result = $this->CakeEmail->getHeaders();
$this->assertTextNotContains(':81', $result['Message-ID']);
}
/**

View file

@ -0,0 +1,84 @@
<?php
/**
* MailTransportTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Network.Email
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeEmail', 'Network/Email');
App::uses('AbstractTransport', 'Network/Email');
App::uses('MailTransport', 'Network/Email');
/**
* Test case
*
*/
class MailTransportTest extends CakeTestCase {
/**
* Setup
*
* @return void
*/
public function setUp() {
$this->MailTransport = $this->getMock('MailTransport', array('_mail'));
$this->MailTransport->config(array('additionalParameters' => '-f'));
}
/**
* testSend method
*
* @return void
*/
public function testSendData() {
$email = $this->getMock('CakeEmail', array('message'), array());
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
$email->to('cake@cakephp.org', 'CakePHP');
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
$email->bcc('phpnut@cakephp.org');
$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
$email->subject('Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz');
$date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => 'CakePHP Email', 'Date' => $date));
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
$data = "From: CakePHP Test <noreply@cakephp.org>" . PHP_EOL;
$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>" . PHP_EOL;
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>" . PHP_EOL;
$data .= "Bcc: phpnut@cakephp.org" . PHP_EOL;
$data .= "X-Mailer: CakePHP Email" . PHP_EOL;
$data .= "Date: " . $date . PHP_EOL;
$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL;
$data .= "MIME-Version: 1.0" . PHP_EOL;
$data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL;
$data .= "Content-Transfer-Encoding: 8bit";
$subject = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?=';
$subject .= "\r\n" . ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?=';
$this->MailTransport->expects($this->once())->method('_mail')
->with(
'CakePHP <cake@cakephp.org>',
$subject,
implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')),
$data,
'-f'
);
$this->MailTransport->send($email);
}
}

View file

@ -451,6 +451,30 @@ class RouterTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that catch all routes work with a variety of falsey inputs.
*
* @return void
*/
public function testUrlCatchAllRoute() {
Router::connect('/*', array('controller' => 'categories', 'action' => 'index'));
$result = Router::url(array('controller' => 'categories', 'action' => 'index', '0'));
$this->assertEquals('/0', $result);
$expected = array(
'plugin' => null,
'controller' => 'categories',
'action' => 'index',
'pass' => array('0'),
'named' => array()
);
$result = Router::parse('/0');
$this->assertEquals($expected, $result);
$result = Router::parse('0');
$this->assertEquals($expected, $result);
}
/**
* Tests using arrays in named parameters
*

View file

@ -61,7 +61,7 @@ class CakeTestSuiteTest extends CakeTestCase {
* @return void
*/
public function testAddTestDirectoryRecursiveWithHidden() {
$this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
$this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
mkdir($Folder->path . DS . '.svn', 0777, true);
@ -85,7 +85,7 @@ class CakeTestSuiteTest extends CakeTestCase {
* @return void
*/
public function testAddTestDirectoryRecursiveWithNonPhp() {
$this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
$this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
touch($Folder->path . DS . 'BackupTest.php~');

View file

@ -70,6 +70,56 @@ class CakeNumberTest extends CakeTestCase {
$result = $this->Number->format($value, '-');
$expected = '100-100-100';
$this->assertEquals($expected, $result);
$value = 0.00001;
$result = $this->Number->format($value, array('places' => 1));
$expected = '$0.0';
$this->assertEquals($expected, $result);
$value = -0.00001;
$result = $this->Number->format($value, array('places' => 1));
$expected = '$0.0';
$this->assertEquals($expected, $result);
}
/**
* testFormatDelta method
*
* @return void
*/
public function testFormatDelta() {
$value = '100100100';
$result = $this->Number->formatDelta($value);
$expected = '+100,100,100.00';
$this->assertEquals($expected, $result);
$result = $this->Number->formatDelta($value, array('before' => '', 'after' => ''));
$expected = '+100,100,100.00';
$this->assertEquals($expected, $result);
$result = $this->Number->formatDelta($value, array('before' => '[', 'after' => ']'));
$expected = '[+100,100,100.00]';
$this->assertEquals($expected, $result);
$result = $this->Number->formatDelta(-$value, array('before' => '[', 'after' => ']'));
$expected = '[-100,100,100.00]';
$this->assertEquals($expected, $result);
$value = 0;
$result = $this->Number->formatDelta($value, array('places' => 1, 'before' => '[', 'after' => ']'));
$expected = '[0.0]';
$this->assertEquals($expected, $result);
$value = 0.0001;
$result = $this->Number->formatDelta($value, array('places' => 1, 'before' => '[', 'after' => ']'));
$expected = '[0.0]';
$this->assertEquals($expected, $result);
$value = 9876.1234;
$result = $this->Number->formatDelta($value, array('places' => 1, 'decimals' => ',', 'thousands' => '.'));
$expected = '+9.876,1';
$this->assertEquals($expected, $result);
}
/**
@ -523,4 +573,45 @@ class CakeNumberTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* testFromReadableSize
*
* @dataProvider filesizes
* @return void
*/
public function testFromReadableSize($params, $expected) {
$result = $this->Number->fromReadableSize($params['size'], $params['default']);
$this->assertEquals($expected, $result);
}
/**
* testFromReadableSize
*
* @expectedException CakeException
* @return void
*/
public function testFromReadableSizeException() {
$result = $this->Number->fromReadableSize('bogus', false);
}
/**
* filesizes dataprovider
*
* @return array
*/
public function filesizes() {
return array(
array(array('size' => '512B', 'default' => false), 512),
array(array('size' => '1KB', 'default' => false), 1024),
array(array('size' => '1.5KB', 'default' => false), 1536),
array(array('size' => '1MB', 'default' => false), 1048576),
array(array('size' => '1mb', 'default' => false), 1048576),
array(array('size' => '1.5MB', 'default' => false), 1572864),
array(array('size' => '1GB', 'default' => false), 1073741824),
array(array('size' => '1.5GB', 'default' => false), 1610612736),
array(array('size' => '512', 'default' => 'Unknown type'), 512),
array(array('size' => '2VB', 'default' => 'Unknown type'), 'Unknown type')
);
}
}

View file

@ -1049,4 +1049,19 @@ class CakeTimeTest extends CakeTestCase {
}
}
/**
* Tests that using CakeTime::format() with the correct sytax actually converts
* from one timezone to the other correctly
*
* @return void
**/
public function testCorrectTimezoneConversion() {
date_default_timezone_set('UTC');
$date = '2012-01-01 10:00:00';
$converted = CakeTime::format($date, '%Y-%m-%d %H:%M:%S', '', 'Europe/Copenhagen');
$expected = new DateTime($date);
$expected->setTimezone(new DateTimeZone('Europe/Copenhagen'));
$this->assertEquals($expected->format('Y-m-d H:i:s'), $converted);
}
}

View file

@ -268,7 +268,7 @@ class DebuggerTest extends CakeTestCase {
* Test method for testing addFormat with callbacks.
*/
public function customFormat($error, $strings) {
return $error['error'] . ': I eated an error ' . $error['path'];
return $error['error'] . ': I eated an error ' . $error['file'];
}
/**
@ -357,7 +357,6 @@ TEXT;
[protected] _stack => array()
[protected] _eventManager => object(CakeEventManager) {}
[protected] _eventManagerConfigured => false
[private] __viewFileName => null
TEXT;
}

View file

@ -362,11 +362,10 @@ class FileTest extends CakeTestCase {
* @return void
*/
public function testLastAccess() {
$ts = time();
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertFalse($someFile->lastAccess());
$this->assertTrue($someFile->open());
$this->assertTrue($someFile->lastAccess() >= $ts);
$this->assertWithinMargin($someFile->lastAccess(), time(), 2);
$someFile->close();
$someFile->delete();
}
@ -377,13 +376,14 @@ class FileTest extends CakeTestCase {
* @return void
*/
public function testLastChange() {
$ts = time();
$someFile = new File(TMP . 'some_file.txt', false);
$this->assertFalse($someFile->lastChange());
$this->assertTrue($someFile->open('r+'));
$this->assertTrue($someFile->lastChange() >= $ts);
$this->assertWithinMargin($someFile->lastChange(), time(), 2);
$someFile->write('something');
$this->assertTrue($someFile->lastChange() >= $ts);
$this->assertWithinMargin($someFile->lastChange(), time(), 2);
$someFile->close();
$someFile->delete();
}

View file

@ -374,7 +374,7 @@ class FolderTest extends CakeTestCase {
* @return void
*/
public function testFolderReadWithHiddenFiles() {
$this->skipIf(!is_writeable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.');
$this->skipIf(!is_writable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777);
mkdir($Folder->path . DS . '.svn');
@ -457,7 +457,7 @@ class FolderTest extends CakeTestCase {
* @return void
*/
public function testFolderTreeWithHiddenFiles() {
$this->skipIf(!is_writeable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.');
$this->skipIf(!is_writable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777);
mkdir($Folder->path . DS . '.svn', 0777, true);
@ -918,7 +918,7 @@ class FolderTest extends CakeTestCase {
*
* @return void
*/
function testCopyWithOverwrite() {
public function testCopyWithOverwrite() {
extract($this->_setupFilesystem());
$Folder = new Folder($folderOne);
@ -1050,7 +1050,7 @@ class FolderTest extends CakeTestCase {
$this->assertTrue(file_exists($folderTwo . DS . 'file1.php'));
$this->assertEquals('', file_get_contents($folderTwoB . DS . 'fileB.php'));
$this->assertFalse(file_exists($fileOne));
$this->assertFalse(file_exists($folderOneA));
$this->assertFalse(file_exists($folderOneA));
$this->assertFalse(file_exists($fileOneA));
$Folder = new Folder($path);

View file

@ -147,9 +147,25 @@ class SecurityTest extends CakeTestCase {
$this->assertSame(strlen(Security::hash($key, 'sha256', true)), 64);
}
Security::setHash($_hashType);
}
/**
* Test that hash() works with blowfish.
*
* @return void
*/
public function testHashBlowfish() {
Security::setCost(10);
$test = Security::hash('password', 'blowfish');
$this->skipIf(strpos($test, '$2a$') === false, 'Blowfish hashes are incorrect.');
$_hashType = Security::$hashType;
$key = 'someKey';
$hashType = 'blowfish';
Security::setHash($hashType);
Security::setCost(10); // ensure default cost
$this->assertSame(Security::$hashType, $hashType);
$this->assertSame(strlen(Security::hash($key, null, false)), 60);
@ -215,6 +231,7 @@ class SecurityTest extends CakeTestCase {
* @return void
*/
public function testRijndael() {
$this->skipIf(!function_exists('mcrypt_encrypt'));
$txt = 'The quick brown fox jumped over the lazy dog.';
$key = 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi';

View file

@ -1826,32 +1826,32 @@ class ValidationTest extends CakeTestCase {
$this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('sftp://192.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
$this->assertTrue(Validation::url('www.domain.tld'));
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
$this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&amp;get2=params'));
$this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&amp;get2=params#anchor'));
$this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
$this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://underscore_subdomain.example.org'));
$this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com'));
$this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('http://w_w.domain.co_m'));
$this->assertFalse(Validation::url('http://www.domain.12com'));
$this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
$this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
$this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
$this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
$this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&amp;get2=params'));
$this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&amp;get2=params#anchor'));
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
$this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
$this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
$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://underscore_subdomain.example.org'));
$this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com'));
$this->assertFalse(Validation::url('http://www.underscore_domain.org'));
$this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com'));
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
@ -2273,7 +2273,7 @@ class ValidationTest extends CakeTestCase {
}
/**
* testMimeType method
* testUploadError method
*
* @return void
*/
@ -2284,4 +2284,23 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::uploadError(2));
$this->assertFalse(Validation::uploadError(array('error' => 2)));
}
/**
* testFileSize method
*
* @return void
*/
public function testFileSize() {
$image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$this->assertTrue(Validation::fileSize($image, '<', 1024));
$this->assertTrue(Validation::fileSize(array('tmp_name' => $image), 'isless', 1024));
$this->assertTrue(Validation::fileSize($image, '<', '1KB'));
$this->assertTrue(Validation::fileSize($image, '>=', 200));
$this->assertTrue(Validation::fileSize($image, '==', 201));
$this->assertTrue(Validation::fileSize($image, '==', '201B'));
$this->assertFalse(Validation::fileSize($image, 'isgreater', 1024));
$this->assertFalse(Validation::fileSize(array('tmp_name' => $image), '>', '1KB'));
}
}

View file

@ -107,8 +107,7 @@ class Contact extends CakeTestModel {
'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')),
'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
'imrequiredonboth' => array(
'required' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
'check' => array('rule' => 'alphaNumeric')
'required' => array('rule' => 'alphaNumeric'),
),
'string_required' => 'notEmpty',
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
@ -3274,80 +3273,6 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
@ -3536,6 +3461,59 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* Test that radios with a 0 value are selected under the correct conditions.
*
* @return void
*/
public function testRadioOptionWithZeroValue() {
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 0));
$this->assertTags($result, $expected);
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => ''));
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
$this->assertTags($result, $expected);
}
/**
* test disabled radio options
*
@ -3545,7 +3523,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->radio(
'Model.field',
array('option A', 'option B'),
array('disabled' => array('option A'), 'value' => 'option A')
array('disabled' => array('option A'), 'value' => '0')
);
$expected = array(
'fieldset' => array(),
@ -3567,7 +3545,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->radio(
'Model.field',
array('option A', 'option B'),
array('disabled' => true, 'value' => 'option A')
array('disabled' => true, 'value' => '0')
);
$expected = array(
'fieldset' => array(),
@ -3589,7 +3567,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->radio(
'Model.field',
array('option A', 'option B'),
array('disabled' => 'disabled', 'value' => 'option A')
array('disabled' => 'disabled', 'value' => '0')
);
$expected = array(
'fieldset' => array(),
@ -4346,6 +4324,23 @@ class FormHelperTest extends CakeTestCase {
$this->assertRegExp('/"' . $key . '"/', $result);
}
/**
* Multiple select elements should always be secured as they always participate
* in the POST data.
*
* @return void
*/
public function testSelectMultipleSecureWithNoOptions() {
$this->Form->request['_Token'] = array('key' => 'testkey');
$this->assertEquals(array(), $this->Form->fields);
$result = $this->Form->select(
'Model.select',
array(),
array('multiple' => true)
);
$this->assertEquals(array('Model.select'), $this->Form->fields);
}
/**
* When a select box has no options it should not be added to the fields list
* as it always fail post validation.

View file

@ -1445,4 +1445,20 @@ TEXT;
$end = memory_get_usage();
$this->assertLessThanOrEqual($start + 5000, $end);
}
}
/**
* tests that a vew block uses default value when not assigned and uses assigned value when it is
*
* @return void
*/
public function testBlockDefaultValue() {
$default = 'Default';
$result = $this->View->fetch('title', $default);
$this->assertEquals($default, $result);
$expected = 'My Title';
$this->View->assign('title', $expected);
$result = $this->View->fetch('title', $default);
$this->assertEquals($expected, $result);
}
}

View file

@ -7,7 +7,7 @@ class TestAppsExceptionRenderer extends ExceptionRenderer {
if (!$request = Router::getRequest(true)) {
$request = new CakeRequest();
}
$response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
$response = new CakeResponse();
try {
$controller = new TestAppsErrorController($request, $response);
$controller->layout = 'banana';

View file

@ -25,7 +25,7 @@
); ?>
</p>
<?php
if (Configure::read('debug') > 0 ):
if (Configure::read('debug') > 0):
echo $this->element('exception_stack_trace');
endif;
?>

View file

@ -22,7 +22,7 @@
<?php echo __d('cake', 'An Internal Error Has Occurred.'); ?>
</p>
<?php
if (Configure::read('debug') > 0 ):
if (Configure::read('debug') > 0):
echo $this->element('exception_stack_trace');
endif;
?>

View file

@ -58,6 +58,28 @@ class CakeTestFixture {
*/
public $created = array();
/**
* Fields / Schema for the fixture.
* This array should match the output of Model::schema()
*
* @var array
*/
public $fields = array();
/**
* Fixture records to be inserted.
*
* @var array
*/
public $records = array();
/**
* The primary key for the table this fixture represents.
*
* @var string
*/
public $primaryKey = null;
/**
* Instantiate the fixture.
*
@ -110,6 +132,7 @@ class CakeTestFixture {
$this->fields = $model->schema(true);
$this->fields[$model->primaryKey]['key'] = 'primary';
$this->table = $db->fullTableName($model, false, false);
$this->primaryKey = $model->primaryKey;
ClassRegistry::config(array('ds' => 'test'));
ClassRegistry::flush();
} elseif (isset($import['table'])) {
@ -121,6 +144,7 @@ class CakeTestFixture {
$model->table = $import['table'];
$model->tablePrefix = $db->config['prefix'];
$this->fields = $model->schema(true);
$this->primaryKey = $model->primaryKey;
ClassRegistry::flush();
}
@ -159,7 +183,7 @@ class CakeTestFixture {
/**
* Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully.
*
* @param object $db An instance of the database object used to create the fixture table
* @param DboSource $db An instance of the database object used to create the fixture table
* @return boolean True on success, false on failure
*/
public function create($db) {
@ -210,7 +234,7 @@ class CakeTestFixture {
/**
* Run after all tests executed, should return SQL statement to drop table for this fixture.
*
* @param object $db An instance of the database object used to create the fixture table
* @param DboSource $db An instance of the database object used to create the fixture table
* @return boolean True on success, false on failure
*/
public function drop($db) {
@ -232,7 +256,7 @@ class CakeTestFixture {
* Run before each tests is executed, should return a set of SQL statements to insert records for the table
* of this fixture could be executed successfully.
*
* @param object $db An instance of the database into which the records will be inserted
* @param DboSource $db An instance of the database into which the records will be inserted
* @return boolean on success or if there are no records to insert, or false on failure
*/
public function insert($db) {
@ -252,6 +276,9 @@ class CakeTestFixture {
$nested = $db->useNestedTransactions;
$db->useNestedTransactions = false;
$result = $db->insertMulti($this->table, $fields, $values);
if ($this->primaryKey && in_array($this->fields[$this->primaryKey]['type'], array('integer', 'biginteger'))) {
$db->resetSequence($this->table, $this->primaryKey);
}
$db->useNestedTransactions = $nested;
return $result;
}
@ -260,10 +287,10 @@ class CakeTestFixture {
}
/**
* Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after
* truncate.
* Truncates the current fixture. Can be overwritten by classes extending
* CakeFixture to trigger other events before / after truncate.
*
* @param object $db A reference to a db instance
* @param DboSource $db A reference to a db instance
* @return boolean
*/
public function truncate($db) {

View file

@ -70,13 +70,13 @@ class CakeNumber {
/**
* Formats a number with a level of precision.
*
* @param float $number A floating point number.
* @param float $value A floating point number.
* @param integer $precision The precision of the returned number.
* @return float Formatted float.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision
*/
public static function precision($number, $precision = 3) {
return sprintf("%01.{$precision}F", $number);
public static function precision($value, $precision = 3) {
return sprintf("%01.{$precision}F", $value);
}
/**
@ -101,28 +101,59 @@ class CakeNumber {
}
}
/**
* Converts filesize from human readable string to bytes
*
* @param string $size Size in human readable string like '5MB'
* @param mixed $default Value to be returned when invalid size was used, for example 'Unknown type'
* @return integer Bytes
* @throws CakeException On invalid Unit type.
*/
public static function fromReadableSize($size, $default = false) {
if (ctype_digit($size)) {
return $size * 1;
}
$size = strtoupper($size);
$i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB'));
if ($i !== false) {
$size = substr($size, 0, strlen($size) - 2);
return $size * pow(1024, $i + 1);
}
if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) {
$size = substr($size, 0, strlen($size) - 1);
return $size * 1;
}
if ($default !== false) {
return $default;
}
throw new CakeException(__d('cake_dev', 'No unit type.'));
}
/**
* Formats a number into a percentage string.
*
* @param float $number A floating point number
* @param float $value A floating point number
* @param integer $precision The precision of the returned number
* @return string Percentage string
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentage
*/
public static function toPercentage($number, $precision = 2) {
return self::precision($number, $precision) . '%';
public static function toPercentage($value, $precision = 2) {
return self::precision($value, $precision) . '%';
}
/**
* Formats a number into a currency format.
*
* @param float $number A floating point number
* @param float $value A floating point number
* @param integer $options if int then places, if string then before, if (,.-) then use it
* or array with places and before keys
* @return string formatted number
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::format
*/
public static function format($number, $options = false) {
public static function format($value, $options = false) {
$places = 0;
if (is_int($options)) {
$places = $options;
@ -149,7 +180,8 @@ class CakeNumber {
extract($options);
}
$out = $before . self::_numberFormat($number, $places, $decimals, $thousands) . $after;
$value = self::_numberFormat($value, $places, '.', '');
$out = $before . self::_numberFormat($value, $places, $decimals, $thousands) . $after;
if ($escape) {
return h($out);
@ -157,34 +189,57 @@ class CakeNumber {
return $out;
}
/**
* Formats a number into a currency format to show deltas (signed differences in value).
*
* ### Options
*
* - `places` - Number of decimal places to use. ie. 2
* - `before` - The string to place before whole numbers. ie. '['
* - `after` - The string to place after decimal numbers. ie. ']'
* - `thousands` - Thousands separator ie. ','
* - `decimals` - Decimal separator symbol ie. '.'
*
* @param float $value A floating point number
* @param array $options
* @return string formatted delta
*/
public static function formatDelta($value, $options = array()) {
$places = isset($options['places']) ? $options['places'] : 0;
$value = self::_numberFormat($value, $places, '.', '');
$sign = $value > 0 ? '+' : '';
$options['before'] = isset($options['before']) ? $options['before'] . $sign : $sign;
return self::format($value, $options);
}
/**
* Alternative number_format() to accommodate multibyte decimals and thousands < PHP 5.4
*
* @param float $number
* @param float $value
* @param integer $places
* @param string $decimals
* @param string $thousands
* @return string
*/
protected static function _numberFormat($number, $places = 0, $decimals = '.', $thousands = ',') {
protected static function _numberFormat($value, $places = 0, $decimals = '.', $thousands = ',') {
if (!isset(self::$_numberFormatSupport)) {
self::$_numberFormatSupport = version_compare(PHP_VERSION, '5.4.0', '>=');
}
if (self::$_numberFormatSupport) {
return number_format($number, $places, $decimals, $thousands);
return number_format($value, $places, $decimals, $thousands);
}
$number = number_format($number, $places, '.', '');
$value = number_format($value, $places, '.', '');
$after = '';
$foundDecimal = strpos($number, '.');
$foundDecimal = strpos($value, '.');
if ($foundDecimal !== false) {
$after = substr($number, $foundDecimal);
$number = substr($number, 0, $foundDecimal);
$after = substr($value, $foundDecimal);
$value = substr($value, 0, $foundDecimal);
}
while (($foundThousand = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $number)) != $number) {
$number = $foundThousand;
while (($foundThousand = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $value)) != $value) {
$value = $foundThousand;
}
$number .= $after;
return strtr($number, array(' ' => $thousands, '.' => $decimals));
$value .= $after;
return strtr($value, array(' ' => $thousands, '.' => $decimals));
}
/**
@ -213,14 +268,14 @@ class CakeNumber {
* the number will be wrapped with ( and )
* - `escape` - Should the output be htmlentity escaped? Defaults to true
*
* @param float $number
* @param float $value
* @param string $currency Shortcut to default options. Valid values are
* 'USD', 'EUR', 'GBP', otherwise set at least 'before' and 'after' options.
* @param array $options
* @return string Number formatted as a currency.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency
*/
public static function currency($number, $currency = 'USD', $options = array()) {
public static function currency($value, $currency = 'USD', $options = array()) {
$default = self::$_currencyDefaults;
if (isset(self::$_currencies[$currency])) {
@ -241,14 +296,14 @@ class CakeNumber {
$result = $options['before'] = $options['after'] = null;
$symbolKey = 'whole';
if (!$number) {
if (!$value) {
if ($options['zero'] !== 0 ) {
return $options['zero'];
}
} elseif ($number < 1 && $number > -1 ) {
} elseif ($value < 1 && $value > -1) {
if ($options['fractionSymbol'] !== false) {
$multiply = intval('1' . str_pad('', $options['places'], '0'));
$number = $number * $multiply;
$value = $value * $multiply;
$options['places'] = null;
$symbolKey = 'fraction';
}
@ -257,10 +312,10 @@ class CakeNumber {
$position = $options[$symbolKey . 'Position'] != 'after' ? 'before' : 'after';
$options[$position] = $options[$symbolKey . 'Symbol'];
$abs = abs($number);
$abs = abs($value);
$result = self::format($abs, $options);
if ($number < 0 ) {
if ($value < 0) {
if ($options['negative'] == '()') {
$result = '(' . $result . ')';
} else {

View file

@ -310,7 +310,7 @@ class CakeTime {
return false;
}
if (is_integer($dateString) || is_numeric($dateString)) {
if (is_int($dateString) || is_numeric($dateString)) {
$date = intval($dateString);
} elseif (is_object($dateString) && $dateString instanceof DateTime) {
$clone = clone $dateString;
@ -589,7 +589,7 @@ class CakeTime {
if ($dateString instanceof DateTime) {
$date = $dateString;
} elseif (is_integer($dateString) || is_numeric($dateString)) {
} elseif (is_int($dateString) || is_numeric($dateString)) {
$dateString = (int)$dateString;
$date = new DateTime('@' . $dateString);
@ -941,18 +941,11 @@ class CakeTime {
* @see CakeTime::i18nFormat()
*/
public static function format($date, $format = null, $default = false, $timezone = null) {
//Backwards compatible params order
//Backwards compatible params re-order test
$time = self::fromString($format, $timezone);
$_time = false;
if (!is_numeric($time)) {
$_time = self::fromString($date, $timezone);
}
if (is_numeric($_time) && $time === false) {
return self::i18nFormat($_time, $format, $default, $timezone);
}
if ($time === false && $default !== false) {
return $default;
if ($time === false) {
return self::i18nFormat($date, $format, $default, $timezone);
}
return date($date, $time);
}

View file

@ -124,6 +124,7 @@ class ClassRegistry {
list($plugin, $class) = pluginSplit($class);
if ($plugin) {
$pluginPath = $plugin . '.';
$settings['plugin'] = $plugin;
}
if (empty($settings['alias'])) {

View file

@ -213,7 +213,6 @@ class Debugger {
if (empty($line)) {
$line = '??';
}
$path = self::trimPath($file);
$info = compact('code', 'description', 'file', 'line');
if (!in_array($info, $self->errors)) {
@ -318,7 +317,7 @@ class Debugger {
foreach ($next['args'] as $arg) {
$args[] = Debugger::exportVar($arg);
}
$reference .= join(', ', $args);
$reference .= implode(', ', $args);
}
$reference .= ')';
}
@ -779,11 +778,11 @@ class Debugger {
continue;
}
if (is_array($value)) {
$value = join("\n", $value);
$value = implode("\n", $value);
}
$info .= String::insert($tpl[$key], array($key => $value) + $data, $insertOpts);
}
$links = join(' ', $links);
$links = implode(' ', $links);
if (isset($tpl['callback']) && is_callable($tpl['callback'])) {
return call_user_func($tpl['callback'], $data, compact('links', 'info'));

View file

@ -391,7 +391,7 @@ class Folder {
$paths = $this->tree($path);
foreach ($paths as $type) {
foreach ($type as $key => $fullpath) {
foreach ($type as $fullpath) {
$check = explode(DS, $fullpath);
$count = count($check);

View file

@ -432,7 +432,6 @@ class Hash {
}
$stack = array();
$i = 1;
while (!empty($needle)) {
$key = key($needle);
$val = $needle[$key];

View file

@ -406,8 +406,8 @@ class Inflector {
}
if (!isset(self::$_singular['cacheUninflected']) || !isset(self::$_singular['cacheIrregular'])) {
self::$_singular['cacheUninflected'] = '(?:' . join('|', self::$_singular['merged']['uninflected']) . ')';
self::$_singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$_singular['merged']['irregular'])) . ')';
self::$_singular['cacheUninflected'] = '(?:' . implode('|', self::$_singular['merged']['uninflected']) . ')';
self::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_singular['merged']['irregular'])) . ')';
}
if (preg_match('/(.*)\\b(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {

View file

@ -19,6 +19,7 @@
App::uses('Multibyte', 'I18n');
App::uses('File', 'Utility');
App::uses('CakeNumber', 'Utility');
// Load multibyte if the extension is missing.
if (!function_exists('mb_strlen')) {
class_exists('Multibyte');
@ -899,6 +900,27 @@ class Validation {
return in_array($mime, $mimeTypes);
}
/**
* Checks the filesize
*
* @param string|array $check
* @param integer|string $size Size in bytes or human readable string like '5MB'
* @param string $operator See `Validation::comparison()`
* @return boolean Success
*/
public static function fileSize($check, $operator = null, $size = null) {
if (is_array($check) && isset($check['tmp_name'])) {
$check = $check['tmp_name'];
}
if (is_string($size)) {
$size = CakeNumber::fromReadableSize($size);
}
$filesize = filesize($check);
return self::comparison($filesize, $operator, $size);
}
/**
* Checking for upload errors
*

View file

@ -174,7 +174,7 @@ class Xml {
throw new XmlException(__d('cake_dev', 'Invalid input.'));
}
$key = key($input);
if (is_integer($key)) {
if (is_int($key)) {
throw new XmlException(__d('cake_dev', 'The key of input must be alphanumeric'));
}

View file

@ -19,7 +19,13 @@
<h2><?php echo __d('cake_dev', 'Missing Database Connection'); ?></h2>
<p class="error">
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', '%s requires a database connection', $class); ?>
<?php echo __d('cake_dev', 'A Database connection using "%s" was missing or unable to connect. ', $class); ?>
<br />
<?php
if (isset($message)):
echo __d('cake_dev', 'The database server returned this error: %s', $message);
endif;
?>
</p>
<?php if (!$enabled) : ?>
<p class="error">

View file

@ -606,7 +606,7 @@ class Helper extends Object {
$entity = $this->entity();
$model = array_shift($entity);
$dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity));
$dom = $model . implode('', array_map(array('Inflector', 'camelize'), $entity));
if (is_array($options) && !array_key_exists($id, $options)) {
$options[$id] = $dom;

View file

@ -302,7 +302,7 @@ class CacheHelper extends AppHelper {
$file .= '
$request = unserialize(base64_decode(\'' . base64_encode(serialize($this->request)) . '\'));
$response = new CakeResponse(array("charset" => Configure::read("App.encoding")));
$response = new CakeResponse();
$controller = new ' . $this->_View->name . 'Controller($request, $response);
$controller->plugin = $this->plugin = \'' . $this->_View->plugin . '\';
$controller->helpers = $this->helpers = unserialize(base64_decode(\'' . base64_encode(serialize($this->_View->helpers)) . '\'));

View file

@ -146,7 +146,7 @@ class FormHelper extends AppHelper {
));
} elseif (ClassRegistry::isKeySet($this->defaultModel)) {
$defaultObject = ClassRegistry::getObject($this->defaultModel);
if (in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
if ($defaultObject && in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
$object = $defaultObject->{$model};
}
} else {
@ -168,14 +168,14 @@ class FormHelper extends AppHelper {
*
* The $key parameter accepts the following list of values:
*
* - key: Returns the name of the primary key for the model
* - fields: Returns the model schema
* - validates: returns the list of fields that are required
* - errors: returns the list of validation errors
* - key: Returns the name of the primary key for the model
* - fields: Returns the model schema
* - validates: returns the list of fields that are required
* - errors: returns the list of validation errors
*
* If the $field parameter is passed if will return the information for that sole field.
*
* `$this->_introspectModel('Post', 'fields', 'title');` will return the schema information for title column
* `$this->_introspectModel('Post', 'fields', 'title');` will return the schema information for title column
*
* @param string $model name of the model to extract information from
* @param string $key name of the special information key to obtain (key, fields, validates, errors)
@ -194,7 +194,7 @@ class FormHelper extends AppHelper {
if ($key === 'fields') {
if (!isset($this->fieldset[$model]['fields'])) {
$fields = $this->fieldset[$model]['fields'] = $object->schema();
$this->fieldset[$model]['fields'] = $object->schema();
foreach ($object->hasAndBelongsToMany as $alias => $assocData) {
$this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');
}
@ -244,20 +244,23 @@ class FormHelper extends AppHelper {
* @return boolean true if field is required to be filled, false otherwise
*/
protected function _isRequiredField($validationRules) {
if (empty($validationRules) || count($validationRules) === 0) {
return false;
}
foreach ($validationRules as $rule) {
$rule->isUpdate($this->requestType === 'put');
if (!$rule->isEmptyAllowed()) {
return true;
if ($rule->isEmptyAllowed()) {
return false;
}
}
return false;
return true;
}
/**
* Returns false if given form field described by the current entity has no errors.
* Otherwise it returns the validation message
*
* @return mixed Either false when there or no errors, or an array of error
* @return mixed Either false when there are no errors, or an array of error
* strings. An error string could be ''.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::tagIsInvalid
*/
@ -274,7 +277,7 @@ class FormHelper extends AppHelper {
if (empty($errors)) {
return false;
}
$errors = Hash::get($errors, join('.', $entity));
$errors = Hash::get($errors, implode('.', $entity));
return $errors === null ? false : $errors;
}
@ -320,7 +323,6 @@ class FormHelper extends AppHelper {
$key = null;
if ($model !== false) {
$object = $this->_getModel($model);
$key = $this->_introspectModel($model, 'key');
$this->setEntity($model, true);
}
@ -717,7 +719,7 @@ class FormHelper extends AppHelper {
/**
* Returns a formatted LABEL element for HTML FORMs. Will automatically generate
* a for attribute if one is not provided.
* a `for` attribute if one is not provided.
*
* ### Options
*
@ -1375,7 +1377,7 @@ class FormHelper extends AppHelper {
foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue);
if (isset($value) && $optValue == $value) {
if (isset($value) && strval($optValue) === strval($value)) {
$optionsHere['checked'] = 'checked';
}
if ($disabled && (!is_array($disabled) || in_array($optValue, $disabled))) {
@ -1864,10 +1866,12 @@ class FormHelper extends AppHelper {
if (!empty($tag) || isset($template)) {
$hasOptions = (count($options) > 0 || $showEmpty);
// Secure the field if there are options, or its a multi select.
// Single selects with no options don't submit, but multiselects do.
if (
(!isset($secure) || $secure) &&
empty($attributes['disabled']) &&
$hasOptions
(!empty($attributes['multiple']) || $hasOptions)
) {
$this->_secure(true);
}

View file

@ -160,7 +160,7 @@ class HtmlHelper extends AppHelper {
if (is_object($this->_View->response)) {
$this->response = $this->_View->response;
} else {
$this->response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
$this->response = new CakeResponse();
}
if (!empty($settings['configFile'])) {
$this->loadConfig($settings['configFile']);
@ -637,7 +637,7 @@ class HtmlHelper extends AppHelper {
$out[] = $key . ':' . $value . ';';
}
if ($oneline) {
return join(' ', $out);
return implode(' ', $out);
}
return implode("\n", $out);
}
@ -669,7 +669,7 @@ class HtmlHelper extends AppHelper {
$out[] = $crumb[0];
}
}
return join($separator, $out);
return implode($separator, $out);
} else {
return null;
}
@ -805,7 +805,7 @@ class HtmlHelper extends AppHelper {
$out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes(current($arg)), key($arg));
}
}
return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), implode(' ', $out));
}
/**

View file

@ -494,7 +494,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
$out[] = $key . ':' . $value;
}
sort($out);
return join(', ', $out);
return implode(', ', $out);
}
/**

View file

@ -254,7 +254,6 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
$options['url'] = $url;
$options = $this->_prepareCallbacks('request', $options);
if (!empty($options['dataExpression'])) {
$callbacks[] = 'data';
unset($options['dataExpression']);
} elseif (!empty($data)) {
$data = $this->object($data);

View file

@ -471,7 +471,7 @@ class PaginatorHelper extends AppHelper {
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);
if ($this->{$check}($model)) {
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape'))), compact('class'));
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'model'))), compact('class'));
} else {
unset($options['rel']);
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));

View file

@ -237,7 +237,6 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
$url = '"' . $this->url($url) . '"';
$options = $this->_mapOptions('request', $options);
$type = '.Request';
$data = null;
if (isset($options['type']) && strtolower($options['type']) == 'json') {
unset($options['type']);
}

View file

@ -341,7 +341,7 @@ class RssHelper extends AppHelper {
$nodes->item(0)->setAttribute($key, $value);
}
}
foreach ($children as $k => $child) {
foreach ($children as $child) {
$child = $elem->createElement($name, $child);
$nodes->item(0)->appendChild($child);
}

View file

@ -358,7 +358,6 @@ class TimeHelper extends AppHelper {
*/
public function timeAgoInWords($dateTime, $options = array()) {
$element = null;
$stringDate = '';
if (is_array($options) && !empty($options['element'])) {
$element = array(

Some files were not shown because too many files have changed in this diff Show more