Merge branch '1.3-misc' into 1.3

This commit is contained in:
mark_story 2009-10-11 21:44:42 -04:00
commit 71f9ab1717
23 changed files with 340 additions and 255 deletions

View file

@ -86,17 +86,17 @@ class ControllerTask extends Shell {
$this->out(__('Baking basic crud methods for ', true) . $controller); $this->out(__('Baking basic crud methods for ', true) . $controller);
$actions = $this->bakeActions($controller); $actions = $this->bakeActions($controller);
} elseif (!empty($this->args[1]) && $this->args[1] == 'admin') { } elseif (!empty($this->args[1]) && $this->args[1] == 'admin') {
$admin = $this->Project->getAdmin(); $admin = $this->Project->getPrefix();
if ($admin) { if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods'); $this->out(sprintf(__('Adding %s methods', true), $admin));
$actions= $this->bakeActions($controller, $admin); $actions = $this->bakeActions($controller, $admin);
} }
} }
if (!empty($this->args[2]) && $this->args[2] == 'admin') { if (!empty($this->args[2]) && $this->args[2] == 'admin') {
$admin = $this->Project->getAdmin(); $admin = $this->Project->getPrefix();
if ($admin) { if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods'); $this->out(sprintf(__('Adding %s methods', true), $admin));
$actions .= "\n" . $this->bakeActions($controller, $admin); $actions .= "\n" . $this->bakeActions($controller, $admin);
} }
} }
@ -194,7 +194,7 @@ class ControllerTask extends Shell {
$actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y'); $actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y');
} }
if (strtolower($wannaBakeAdminCrud) == 'y') { if (strtolower($wannaBakeAdminCrud) == 'y') {
$admin = $this->Project->getAdmin(); $admin = $this->Project->getPrefix();
$actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y'); $actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y');
} }

View file

@ -351,7 +351,8 @@ class ModelTask extends Shell {
$options = $choices = array(); $options = $choices = array();
if (class_exists('Validation')) { if (class_exists('Validation')) {
$parent = get_class_methods(get_parent_class('Validation')); $parent = get_class_methods(get_parent_class('Validation'));
$options = array_diff(get_class_methods('Validation'), $parent); $options = get_class_methods('Validation');
$options = array_diff($options, $parent);
} }
sort($options); sort($options);
$default = 1; $default = 1;

View file

@ -258,10 +258,10 @@ class ProjectTask extends Shell {
$path = (empty($this->configPath)) ? CONFIGS : $this->configPath; $path = (empty($this->configPath)) ? CONFIGS : $this->configPath;
$File =& new File($path . 'core.php'); $File =& new File($path . 'core.php');
$contents = $File->read(); $contents = $File->read();
if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.admin\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) { if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.prefixes\',[\\t\\x20\'a-z,\)\(]*\\);)%', $contents, $match)) {
$result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.admin\', \''.$name.'\');', $contents); $result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents);
if ($File->write($result)) { if ($File->write($result)) {
Configure::write('Routing.admin', $name); Configure::write('Routing.prefixes', array($name));
return true; return true;
} else { } else {
return false; return false;
@ -277,22 +277,31 @@ class ProjectTask extends Shell {
* @return string Admin route to use * @return string Admin route to use
* @access public * @access public
*/ */
function getAdmin() { function getPrefix() {
$admin = ''; $admin = '';
$cakeAdmin = null; $prefixes = Configure::read('Routing.prefixes');
$adminRoute = Configure::read('Routing.admin'); if (!empty($prefixes)) {
if (!empty($adminRoute)) { if (count($prefixes) == 1) {
return $adminRoute . '_'; return $prefixes[0] . '_';
}
$options = array();
foreach ($prefixes as $i => $prefix) {
$options[] = $i + 1;
$this->out($i + 1 . '. ' . $prefix);
}
$selection = $this->in(__('Please choose a prefix to bake with.', true), $options, 1);
return $prefixes[$selection - 1] . '_';
} }
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
$this->out(__('What would you like the admin route to be?', true)); $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.');
$this->out(__('What would you like the prefix route to be?', true));
$this->out(__('Example: www.example.com/admin/controller', true)); $this->out(__('Example: www.example.com/admin/controller', true));
while ($admin == '') { while ($admin == '') {
$admin = $this->in(__("What would you like the admin route to be?", true), null, 'admin'); $admin = $this->in(__("What would you like the prefix route to be?", true), null, 'admin');
} }
if ($this->cakeAdmin($admin) !== true) { if ($this->cakeAdmin($admin) !== true) {
$this->out(__('Unable to write to /app/config/core.php.', true)); $this->out(__('Unable to write to /app/config/core.php.', true));
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.'); $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.');
$this->_stop(); $this->_stop();
} }
return $admin . '_'; return $admin . '_';

View file

@ -156,13 +156,13 @@ class ViewTask extends Shell {
$scaffoldActions = true; $scaffoldActions = true;
$methods = $this->scaffoldActions; $methods = $this->scaffoldActions;
} }
$adminRoute = Configure::read('Routing.admin'); $adminRoute = $this->Project->getPrefix();
foreach ($methods as $i => $method) { foreach ($methods as $i => $method) {
if ($adminRoute && isset($this->params['admin'])) { if ($adminRoute && isset($this->params['admin'])) {
if ($scaffoldActions) { if ($scaffoldActions) {
$methods[$i] = $adminRoute . '_' . $method; $methods[$i] = $adminRoute . $method;
continue; continue;
} elseif (strpos($method, $adminRoute . '_') === false) { } elseif (strpos($method, $adminRoute) === false) {
unset($methods[$i]); unset($methods[$i]);
} }
} }
@ -233,7 +233,7 @@ class ViewTask extends Shell {
$this->bakeActions($actions, $vars); $this->bakeActions($actions, $vars);
} }
if (strtolower($wannaDoAdmin) == 'y') { if (strtolower($wannaDoAdmin) == 'y') {
$admin = $this->Project->getAdmin(); $admin = $this->Project->getPrefix();
$regularActions = $this->scaffoldActions; $regularActions = $this->scaffoldActions;
$adminActions = array(); $adminActions = array();
foreach ($regularActions as $action) { foreach ($regularActions as $action) {
@ -403,9 +403,11 @@ class ViewTask extends Shell {
return $this->template; return $this->template;
} }
$template = $action; $template = $action;
$adminRoute = Configure::read('Routing.admin'); $prefixes = Configure::read('Routing.prefixes');
if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) { foreach ((array)$prefixes as $prefix) {
$template = str_replace($adminRoute . '_', '', $template); if (strpos($template, $prefix) !== false) {
$template = str_replace($prefix . '_', '', $template);
}
} }
if (in_array($template, array('add', 'edit'))) { if (in_array($template, array('add', 'edit'))) {
$template = 'form'; $template = 'form';

View file

@ -26,7 +26,7 @@
<div class="<?php echo $pluralVar;?> form"> <div class="<?php echo $pluralVar;?> form">
<?php echo "<?php echo \$form->create('{$modelClass}');?>\n";?> <?php echo "<?php echo \$form->create('{$modelClass}');?>\n";?>
<fieldset> <fieldset>
<legend><?php echo "<?php __('" . Inflector::humanize($action) . " {$singularHumanName}');?>";?></legend> <legend><?php echo "<?php printf(__('" . Inflector::humanize($action) . " %s', true), __('{$singularHumanName}', true)); ?>";?></legend>
<?php <?php
echo "\t<?php\n"; echo "\t<?php\n";
foreach ($fields as $field) { foreach ($fields as $field) {
@ -45,7 +45,7 @@
?> ?>
</fieldset> </fieldset>
<?php <?php
echo "<?php echo \$form->end('Submit');?>\n"; echo "<?php echo \$form->end(__('Submit', true));?>\n";
?> ?>
</div> </div>
<div class="actions"> <div class="actions">
@ -53,14 +53,14 @@
<?php if ($action != 'add'):?> <?php if ($action != 'add'):?>
<li><?php echo "<?php echo \$html->link(__('Delete', true), array('action' => 'delete', \$form->value('{$modelClass}.{$primaryKey}')), null, sprintf(__('Are you sure you want to delete # %s?', true), \$form->value('{$modelClass}.{$primaryKey}'))); ?>";?></li> <li><?php echo "<?php echo \$html->link(__('Delete', true), array('action' => 'delete', \$form->value('{$modelClass}.{$primaryKey}')), null, sprintf(__('Are you sure you want to delete # %s?', true), \$form->value('{$modelClass}.{$primaryKey}'))); ?>";?></li>
<?php endif;?> <?php endif;?>
<li><?php echo "<?php echo \$html->link(__('List {$pluralHumanName}', true), array('action' => 'index'));?>";?></li> <li><?php echo "<?php echo \$html->link(sprintf(__('List %s', true), __('{$pluralHumanName}', true)), array('action' => 'index'));?>";?></li>
<?php <?php
$done = array(); $done = array();
foreach ($associations as $type => $data) { foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) { foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) { if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?php echo \$html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('List %s', true), __('" . Inflector::humanize($details['controller']) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('New %s', true), __('" . Inflector::humanize(Inflector::underscore($alias)) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
$done[] = $details['controller']; $done[] = $details['controller'];
} }
} }

View file

@ -83,14 +83,14 @@ echo "<?php endforeach; ?>\n";
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<li><?php echo "<?php echo \$html->link(__('New {$singularHumanName}', true), array('action' => 'add')); ?>";?></li> <li><?php echo "<?php echo \$html->link(sprintf(__('New %s', true), __('{$singularHumanName}', true)), array('action' => 'add')); ?>";?></li>
<?php <?php
$done = array(); $done = array();
foreach ($associations as $type => $data) { foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) { foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) { if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?php echo \$html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('List %s', true), __('" . Inflector::humanize($details['controller']) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('New %s', true), __('" . Inflector::humanize(Inflector::underscore($alias)) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
$done[] = $details['controller']; $done[] = $details['controller'];
} }
} }

View file

@ -50,17 +50,17 @@ foreach ($fields as $field) {
<div class="actions"> <div class="actions">
<ul> <ul>
<?php <?php
echo "\t\t<li><?php echo \$html->link(__('Edit {$singularHumanName}', true), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('Edit %s', true), __('{$singularHumanName}', true)), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('Delete {$singularHumanName}', true), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('Delete %s', true), __('{$singularHumanName}', true)), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, sprintf(__('Are you sure you want to delete # %s?', true), \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('List {$pluralHumanName}', true), array('action' => 'index')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('List %s', true), __('{$pluralHumanName}', true)), array('action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New {$singularHumanName}', true), array('action' => 'add')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('New %s', true), __('{$singularHumanName}', true)), array('action' => 'add')); ?> </li>\n";
$done = array(); $done = array();
foreach ($associations as $type => $data) { foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) { foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) { if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?php echo \$html->link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('List %s', true), __('" . Inflector::humanize($details['controller']) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'index')); ?> </li>\n";
echo "\t\t<li><?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n"; echo "\t\t<li><?php echo \$html->link(sprintf(__('New %s', true), __('" . Inflector::humanize(Inflector::underscore($alias)) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'add')); ?> </li>\n";
$done[] = $details['controller']; $done[] = $details['controller'];
} }
} }
@ -72,7 +72,7 @@ foreach ($fields as $field) {
if (!empty($associations['hasOne'])) : if (!empty($associations['hasOne'])) :
foreach ($associations['hasOne'] as $alias => $details): ?> foreach ($associations['hasOne'] as $alias => $details): ?>
<div class="related"> <div class="related">
<h3><?php echo "<?php __('Related " . Inflector::humanize($details['controller']) . "');?>";?></h3> <h3><?php echo "<?php printf(__('Related %s', true), __('" . Inflector::humanize($details['controller']) . "', true));?>";?></h3>
<?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?> <?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
<dl><?php echo "\t<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?> <dl><?php echo "\t<?php \$i = 0; \$class = ' class=\"altrow\"';?>\n";?>
<?php <?php
@ -85,7 +85,7 @@ if (!empty($associations['hasOne'])) :
<?php echo "<?php endif; ?>\n";?> <?php echo "<?php endif; ?>\n";?>
<div class="actions"> <div class="actions">
<ul> <ul>
<li><?php echo "<?php echo \$html->link(__('Edit " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?></li>\n";?> <li><?php echo "<?php echo \$html->link(sprintf(__('Edit %s', true), __('" . Inflector::humanize(Inflector::underscore($alias)) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?></li>\n";?>
</ul> </ul>
</div> </div>
</div> </div>
@ -105,7 +105,7 @@ foreach ($relations as $alias => $details):
$otherPluralHumanName = Inflector::humanize($details['controller']); $otherPluralHumanName = Inflector::humanize($details['controller']);
?> ?>
<div class="related"> <div class="related">
<h3><?php echo "<?php __('Related {$otherPluralHumanName}');?>";?></h3> <h3><?php echo "<?php printf(__('Related %s', true), __('{$otherPluralHumanName}', true));?>";?></h3>
<?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?> <?php echo "<?php if (!empty(\${$singularVar}['{$alias}'])):?>\n";?>
<table cellpadding = "0" cellspacing = "0"> <table cellpadding = "0" cellspacing = "0">
<tr> <tr>
@ -144,7 +144,7 @@ echo "\t<?php endforeach; ?>\n";
<?php echo "<?php endif; ?>\n\n";?> <?php echo "<?php endif; ?>\n\n";?>
<div class="actions"> <div class="actions">
<ul> <ul>
<li><?php echo "<?php echo \$html->link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?> </li> <li><?php echo "<?php echo \$html->link(sprintf(__('New %s', true), __('" . Inflector::humanize(Inflector::underscore($alias)) . "', true)), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?> </li>
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* Error handler * Error handler
* *
@ -9,20 +7,17 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
* @since CakePHP(tm) v 0.10.5.1732 * @since CakePHP(tm) v 0.10.5.1732
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
App::import('Controller', 'App'); App::import('Controller', 'App');
@ -115,8 +110,11 @@ class ErrorHandler extends Object {
} }
if ($method !== 'error') { if ($method !== 'error') {
if (Configure::read() == 0) { if (Configure::read('debug') == 0) {
$method = 'error404'; $parentMethods = get_class_methods(get_parent_class($this));
if (in_array($method, $parentMethods)) {
$method = 'error404';
}
if (isset($code) && $code == 500) { if (isset($code) && $code == 500) {
$method = 'error500'; $method = 'error500';
} }

View file

@ -314,7 +314,7 @@ class File extends Object {
} }
/** /**
* Returns the File extension. * Returns the File info.
* *
* @return string The File extension * @return string The File extension
* @access public * @access public
@ -540,5 +540,20 @@ class File extends Object {
function &Folder() { function &Folder() {
return $this->Folder; return $this->Folder;
} }
/**
* Copy the File to $dest
*
* @param string $dest destination for the copy
* @param boolean $overwrite Overwrite $dest if exists
* @return boolean Succes
* @access public
*/
function copy($dest, $overwrite = true) {
if (!$this->exists() || is_file($dest) && !$overwrite) {
return false;
}
return copy($this->path, $dest);
}
} }
?> ?>

View file

@ -32,7 +32,7 @@
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
*/ */
class Set extends Object { class Set {
/** /**
* Deprecated * Deprecated

View file

@ -26,7 +26,7 @@
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
*/ */
class String extends Object { class String {
/** /**
* Gets a reference to the String object instance * Gets a reference to the String object instance
@ -225,6 +225,7 @@ class String extends Object {
); );
$options += $defaults; $options += $defaults;
$format = $options['format']; $format = $options['format'];
$data = (array)$data;
if (!isset($format)) { if (!isset($format)) {
$format = sprintf( $format = sprintf(
@ -234,42 +235,39 @@ class String extends Object {
str_replace('%', '%%', preg_quote($options['after'], '/')) str_replace('%', '%%', preg_quote($options['after'], '/'))
); );
} }
if (!is_array($data)) {
$data = array($data);
}
if (array_keys($data) === array_keys(array_values($data))) { if (strpos($str, '?') !== false) {
$offset = 0; $offset = 0;
while (($pos = strpos($str, '?', $offset)) !== false) { while (($pos = strpos($str, '?', $offset)) !== false) {
$val = array_shift($data); $val = array_shift($data);
$offset = $pos + strlen($val); $offset = $pos + strlen($val);
$str = substr_replace($str, $val, $pos, 1); $str = substr_replace($str, $val, $pos, 1);
} }
return ($options['clean']) ? String::cleanInsert($str, $options) : $str;
} else { } else {
asort($data); asort($data);
$hashKeys = array_map('md5', array_keys($data)); $hashKeys = array();
foreach ($data as $key => $value) {
$hashKeys[] = crc32($key);
}
$tempData = array_combine(array_keys($data), array_values($hashKeys)); $tempData = array_combine(array_keys($data), array_values($hashKeys));
foreach ($tempData as $key => $hashVal) { foreach ($tempData as $key => $hashVal) {
$key = sprintf($format, preg_quote($key, '/')); $key = sprintf($format, preg_quote($key, '/'));
$str = preg_replace($key, $hashVal, $str); $str = preg_replace($key, $hashVal, $str);
} }
$dataReplacements = array_combine($hashKeys, array_values($data)); $dataReplacements = array_combine($hashKeys, array_values($data));
foreach ($dataReplacements as $tmpHash => $data) { foreach ($dataReplacements as $tmpHash => $tmpValue) {
if (is_array($data)) { $tmpValue = (is_array($tmpValue)) ? '' : $tmpValue;
$data = ''; $str = str_replace($tmpHash, $tmpValue, $str);
}
$str = str_replace($tmpHash, $data, $str);
} }
} }
if (!isset($options['format']) && isset($options['before'])) { if (!isset($options['format']) && isset($options['before'])) {
$str = str_replace($options['escape'].$options['before'], $options['before'], $str); $str = str_replace($options['escape'].$options['before'], $options['before'], $str);
} }
if (!$options['clean']) { return ($options['clean']) ? String::cleanInsert($str, $options) : $str;
return $str;
}
return String::cleanInsert($str, $options);
} }
/** /**

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* Validation Class. Used for validation of model data * Validation Class. Used for validation of model data
* *
@ -9,47 +7,22 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.0.3830 * @since CakePHP(tm) v 1.2.0.3830
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
if (!class_exists('Multibyte')) {
/** App::import('Core', 'Multibyte', false);
* Deprecated }
*/
/**
* Not empty.
*/
define('VALID_NOT_EMPTY', '/.+/');
/**
* Numbers [0-9] only.
*/
define('VALID_NUMBER', '/^[-+]?\\b[0-9]*\\.?[0-9]+\\b$/');
/**
* A valid email address.
*/
define('VALID_EMAIL', "/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2,4}|museum|travel)$/i");
/**
* A valid year (1000-2999).
*/
define('VALID_YEAR', '/^[12][0-9]{3}$/');
/** /**
* Offers different validation methods. * Offers different validation methods.
* *
@ -207,7 +180,7 @@ class Validation extends Object {
* @access public * @access public
*/ */
function between($check, $min, $max) { function between($check, $min, $max) {
$length = strlen($check); $length = mb_strlen($check);
return ($length >= $min && $length <= $max); return ($length >= $min && $length <= $max);
} }
@ -262,7 +235,7 @@ class Validation extends Object {
} }
$_this->check = str_replace(array('-', ' '), '', $_this->check); $_this->check = str_replace(array('-', ' '), '', $_this->check);
if (strlen($_this->check) < 13) { if (mb_strlen($_this->check) < 13) {
return false; return false;
} }
@ -271,20 +244,24 @@ class Validation extends Object {
return $_this->_luhn(); return $_this->_luhn();
} }
} }
$cards = array('all' => array('amex' => '/^3[4|7]\\d{13}$/', $cards = array(
'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/', 'all' => array(
'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/', 'amex' => '/^3[4|7]\\d{13}$/',
'disc' => '/^(?:6011|650\\d)\\d{12}$/', 'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/',
'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/', 'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/',
'enroute' => '/^2(?:014|149)\\d{11}$/', 'disc' => '/^(?:6011|650\\d)\\d{12}$/',
'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/', 'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/',
'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/', 'enroute' => '/^2(?:014|149)\\d{11}$/',
'mc' => '/^5[1-5]\\d{14}$/', 'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/',
'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/', 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/',
'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/', 'mc' => '/^5[1-5]\\d{14}$/',
'visa' => '/^4\\d{12}(\\d{3})?$/', 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/',
'voyager' => '/^8699[0-9]{11}$/'), 'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/',
'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/'); 'visa' => '/^4\\d{12}(\\d{3})?$/',
'voyager' => '/^8699[0-9]{11}$/'
),
'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/'
);
if (is_array($_this->type)) { if (is_array($_this->type)) {
foreach ($_this->type as $value) { foreach ($_this->type as $value) {
@ -315,10 +292,10 @@ class Validation extends Object {
* Used to compare 2 numeric values. * Used to compare 2 numeric values.
* *
* @param mixed $check1 if string is passed for a string must also be passed for $check2 * @param mixed $check1 if string is passed for a string must also be passed for $check2
* used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value) * used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value)
* @param string $operator Can be either a word or operand * @param string $operator Can be either a word or operand
* is greater >, is less <, greater or equal >= * is greater >, is less <, greater or equal >=
* less or equal <=, is less <, equal to ==, not equal != * less or equal <=, is less <, equal to ==, not equal !=
* @param integer $check2 only needed if $check1 is a string * @param integer $check2 only needed if $check1 is a string
* @return boolean Success * @return boolean Success
* @access public * @access public
@ -612,7 +589,7 @@ class Validation extends Object {
* @access public * @access public
*/ */
function minLength($check, $min) { function minLength($check, $min) {
$length = strlen($check); $length = mb_strlen($check);
return ($length >= $min); return ($length >= $min);
} }
@ -625,7 +602,7 @@ class Validation extends Object {
* @access public * @access public
*/ */
function maxLength($check, $max) { function maxLength($check, $max) {
$length = strlen($check); $length = mb_strlen($check);
return ($length <= $max); return ($length <= $max);
} }
@ -914,7 +891,7 @@ class Validation extends Object {
$_this->regex = $regex; $_this->regex = $regex;
} }
if (isset($country)) { if (isset($country)) {
$_this->country = strtolower($country); $_this->country = mb_strtolower($country);
} }
if (isset($deep)) { if (isset($deep)) {
$_this->deep = $deep; $_this->deep = $deep;

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* Text Helper * Text Helper
* *
@ -9,20 +7,17 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.libs.view.helpers * @subpackage cake.cake.libs.view.helpers
* @since CakePHP(tm) v 0.10.0.1076 * @since CakePHP(tm) v 0.10.0.1076
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
@ -114,8 +109,8 @@ class TextHelper extends AppHelper {
function autoLinkUrls($text, $htmlOptions = array()) { function autoLinkUrls($text, $htmlOptions = array()) {
$options = 'array('; $options = 'array(';
foreach ($htmlOptions as $option => $value) { foreach ($htmlOptions as $option => $value) {
$value = var_export($value, true); $value = var_export($value, true);
$options .= "'$option' => $value, "; $options .= "'$option' => $value, ";
} }
$options .= ')'; $options .= ')';
@ -138,7 +133,8 @@ class TextHelper extends AppHelper {
$options = 'array('; $options = 'array(';
foreach ($htmlOptions as $option => $value) { foreach ($htmlOptions as $option => $value) {
$options .= "'$option' => '$value', "; $value = var_export($value, true);
$options .= "'$option' => $value, ";
} }
$options .= ')'; $options .= ')';
@ -226,7 +222,7 @@ class TextHelper extends AppHelper {
if (mb_strlen($text) <= $length) { if (mb_strlen($text) <= $length) {
return $text; return $text;
} else { } else {
$truncate = mb_substr($text, 0, $length - strlen($ending)); $truncate = mb_substr($text, 0, $length - mb_strlen($ending));
} }
} }
if (!$exact) { if (!$exact) {
@ -265,6 +261,7 @@ class TextHelper extends AppHelper {
* @access public * @access public
*/ */
function trim() { function trim() {
trigger_error('TextHelper::trim() is deprecated. Use TextHelper::truncate() instead', E_USER_WARNING);
$args = func_get_args(); $args = func_get_args();
return call_user_func_array(array(&$this, 'truncate'), $args); return call_user_func_array(array(&$this, 'truncate'), $args);
} }
@ -284,26 +281,26 @@ class TextHelper extends AppHelper {
return $this->truncate($text, $radius * 2, $ending); return $this->truncate($text, $radius * 2, $ending);
} }
$phraseLen = strlen($phrase); $phraseLen = mb_strlen($phrase);
if ($radius < $phraseLen) { if ($radius < $phraseLen) {
$radius = $phraseLen; $radius = $phraseLen;
} }
$pos = strpos(strtolower($text), strtolower($phrase)); $pos = mb_strpos(mb_strtolower($text), mb_strtolower($phrase));
$startPos = 0; $startPos = 0;
if ($pos > $radius) { if ($pos > $radius) {
$startPos = $pos - $radius; $startPos = $pos - $radius;
} }
$textLen = strlen($text); $textLen = mb_strlen($text);
$endPos = $pos + $phraseLen + $radius; $endPos = $pos + $phraseLen + $radius;
if ($endPos >= $textLen) { if ($endPos >= $textLen) {
$endPos = $textLen; $endPos = $textLen;
} }
$excerpt = substr($text, $startPos, $endPos - $startPos); $excerpt = mb_substr($text, $startPos, $endPos - $startPos);
if ($startPos != 0) { if ($startPos != 0) {
$excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
} }

View file

@ -27,7 +27,7 @@
<h2><?php echo $pluralHumanName;?></h2> <h2><?php echo $pluralHumanName;?></h2>
<p><?php <p><?php
echo $paginator->counter(array( echo $paginator->counter(array(
'format' => 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%' 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
)); ));
?></p> ?></p>
<table cellpadding="0" cellspacing="0"> <table cellpadding="0" cellspacing="0">
@ -81,7 +81,7 @@ echo "\n";
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<li><?php echo $html->link('New '.$singularHumanName, array('action' => 'add')); ?></li> <li><?php echo $html->link(sprintf(__('New %s', true), $singularHumanName), array('action' => 'add')); ?></li>
<?php <?php
$done = array(); $done = array();
foreach ($associations as $_type => $_data) { foreach ($associations as $_type => $_data) {

View file

@ -680,6 +680,7 @@ class View extends Object {
$this->{$helpers[$i]} =& ${$name}; $this->{$helpers[$i]} =& ${$name};
} }
$this->_triggerHelpers('beforeRender'); $this->_triggerHelpers('beforeRender');
unset($name, $loadedHelpers, $helpers, $i, $helperNames);
} }
extract($___dataForView, EXTR_SKIP); extract($___dataForView, EXTR_SKIP);

View file

@ -55,7 +55,7 @@ Mock::generatePartial(
Mock::generatePartial( Mock::generatePartial(
'ProjectTask', 'ControllerMockProjectTask', 'ProjectTask', 'ControllerMockProjectTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getAdmin') array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix')
); );
Mock::generate('TestTask', 'ControllerMockTestTask'); Mock::generate('TestTask', 'ControllerMockTestTask');
@ -485,7 +485,7 @@ class ControllerTaskTest extends CakeTestCase {
if ($skip) { if ($skip) {
return; return;
} }
$this->Task->Project->setReturnValue('getAdmin', 'admin_'); $this->Task->Project->setReturnValue('getPrefix', 'admin_');
$this->Task->connection = 'test_suite'; $this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'public', 'admin'); $this->Task->args = array('Articles', 'public', 'admin');
@ -509,7 +509,7 @@ class ControllerTaskTest extends CakeTestCase {
if ($skip) { if ($skip) {
return; return;
} }
$this->Task->Project->setReturnValue('getAdmin', 'admin_'); $this->Task->Project->setReturnValue('getPrefix', 'admin_');
$this->Task->connection = 'test_suite'; $this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'admin'); $this->Task->args = array('Articles', 'admin');

View file

@ -132,22 +132,60 @@ class ProjectTaskTest extends CakeTestCase {
} }
/** /**
* test getAdmin method, and that it returns Routing.admin or writes to config file. * test getPrefix method, and that it returns Routing.prefix or writes to config file.
* *
* @return void * @return void
**/ **/
function testGetAdmin() { function testGetPrefix() {
Configure::write('Routing.admin', 'admin'); Configure::write('Routing.prefixes', array('admin'));
$result = $this->Task->getAdmin(); $result = $this->Task->getPrefix();
$this->assertEqual($result, 'admin_'); $this->assertEqual($result, 'admin_');
Configure::write('Routing.admin', null); Configure::write('Routing.prefixes', null);
$this->_setupTestProject(); $this->_setupTestProject();
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS; $this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
$this->Task->setReturnValue('in', 'super_duper_admin'); $this->Task->setReturnValue('in', 'super_duper_admin');
$result = $this->Task->getAdmin(); $result = $this->Task->getPrefix();
$this->assertEqual($result, 'super_duper_admin_'); $this->assertEqual($result, 'super_duper_admin_');
$file =& new File($this->Task->configPath . 'core.php');
$file->delete();
}
/**
* test cakeAdmin() writing core.php
*
* @return void
**/
function testCakeAdmin() {
$file =& new File(CONFIGS . 'core.php');
$contents = $file->read();;
$file =& new File(TMP . 'tests' . DS . 'core.php');
$file->write($contents);
Configure::write('Routing.prefixes', null);
$this->Task->configPath = TMP . 'tests' . DS;
$result = $this->Task->cakeAdmin('my_prefix');
$this->assertTrue($result);
$this->assertEqual(Configure::read('Routing.prefixes'), array('my_prefix'));
$file->delete();
}
/**
* test getting the prefix with more than one prefix setup
*
* @return void
**/
function testGetPrefixWithMultiplePrefixes() {
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
$this->_setupTestProject();
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
$this->Task->setReturnValue('in', 2);
$result = $this->Task->getPrefix();
$this->assertEqual($result, 'ninja_');
} }
/** /**

View file

@ -165,10 +165,10 @@ class ViewTaskTest extends CakeTestCase {
); );
$result = $this->Task->getContent('view', $vars); $result = $this->Task->getContent('view', $vars);
$this->assertPattern('/Delete Test View Model/', $result); $this->assertPattern('/Delete .+Test View Model/', $result);
$this->assertPattern('/Edit Test View Model/', $result); $this->assertPattern('/Edit .+Test View Model/', $result);
$this->assertPattern('/List Test View Models/', $result); $this->assertPattern('/List .+Test View Models/', $result);
$this->assertPattern('/New Test View Model/', $result); $this->assertPattern('/New .+Test View Model/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result); $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result); $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
@ -181,8 +181,8 @@ class ViewTaskTest extends CakeTestCase {
* @return void * @return void
**/ **/
function testGetContentWithAdminAction() { function testGetContentWithAdminAction() {
$_back = Configure::read('Routing.admin'); $_back = Configure::read('Routing');
Configure::write('Routing.admin', 'admin'); Configure::write('Routing.prefixes', array('admin'));
$vars = array( $vars = array(
'modelClass' => 'TestViewModel', 'modelClass' => 'TestViewModel',
'schema' => array(), 'schema' => array(),
@ -197,16 +197,16 @@ class ViewTaskTest extends CakeTestCase {
); );
$result = $this->Task->getContent('admin_view', $vars); $result = $this->Task->getContent('admin_view', $vars);
$this->assertPattern('/Delete Test View Model/', $result); $this->assertPattern('/Delete .+Test View Model/', $result);
$this->assertPattern('/Edit Test View Model/', $result); $this->assertPattern('/Edit .+Test View Model/', $result);
$this->assertPattern('/List Test View Models/', $result); $this->assertPattern('/List .+Test View Models/', $result);
$this->assertPattern('/New Test View Model/', $result); $this->assertPattern('/New .+Test View Model/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result); $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result); $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result); $this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
Configure::write('Routing.admin', $_back); Configure::write('Routing', $_back);
} }
/** /**
@ -264,7 +264,7 @@ class ViewTaskTest extends CakeTestCase {
)); ));
$this->Task->expectAt(1, 'createFile', array( $this->Task->expectAt(1, 'createFile', array(
TMP . 'view_task_comments' . DS . 'edit.ctp', TMP . 'view_task_comments' . DS . 'edit.ctp',
new PatternExpectation('/Edit View Task Comment/') new PatternExpectation('/Edit .+View Task Comment/')
)); ));
$this->Task->expectAt(2, 'createFile', array( $this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'index.ctp', TMP . 'view_task_comments' . DS . 'index.ctp',
@ -347,10 +347,11 @@ class ViewTaskTest extends CakeTestCase {
* @return void * @return void
**/ **/
function testExecuteWithControllerAndAdminFlag() { function testExecuteWithControllerAndAdminFlag() {
$_back = Configure::read('Routing.admin'); $_back = Configure::read('Routing');
Configure::write('Routing.admin', 'admin'); Configure::write('Routing.prefixes', array('admin'));
$this->Task->args[0] = 'ViewTaskArticles'; $this->Task->args[0] = 'ViewTaskArticles';
$this->Task->params['admin'] = 1; $this->Task->params['admin'] = 1;
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
$this->Task->expectCallCount('createFile', 4); $this->Task->expectCallCount('createFile', 4);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_index.ctp', '*')); $this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_index.ctp', '*'));
@ -359,7 +360,7 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_edit.ctp', '*')); $this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_edit.ctp', '*'));
$this->Task->execute(); $this->Task->execute();
Configure::write('Routing.admin', $_back); Configure::write('Routing', $_back);
} }
/** /**
@ -389,11 +390,11 @@ class ViewTaskTest extends CakeTestCase {
)); ));
$this->Task->expectAt(2, 'createFile', array( $this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'add.ctp', TMP . 'view_task_comments' . DS . 'add.ctp',
new PatternExpectation('/Add View Task Comment/') new PatternExpectation('/Add .+View Task Comment/')
)); ));
$this->Task->expectAt(3, 'createFile', array( $this->Task->expectAt(3, 'createFile', array(
TMP . 'view_task_comments' . DS . 'edit.ctp', TMP . 'view_task_comments' . DS . 'edit.ctp',
new PatternExpectation('/Edit View Task Comment/') new PatternExpectation('/Edit .+View Task Comment/')
)); ));
$this->Task->execute(); $this->Task->execute();
@ -423,12 +424,12 @@ class ViewTaskTest extends CakeTestCase {
* @return void * @return void
**/ **/
function testExecuteInteractiveWithAdmin() { function testExecuteInteractiveWithAdmin() {
Configure::write('Routing.admin', 'admin'); Configure::write('Routing.prefixes', array('admin'));
$this->Task->connection = 'test_suite'; $this->Task->connection = 'test_suite';
$this->Task->args = array(); $this->Task->args = array();
$this->Task->Controller->setReturnValue('getName', 'ViewTaskComments'); $this->Task->Controller->setReturnValue('getName', 'ViewTaskComments');
$this->Task->Project->setReturnValue('getAdmin', 'admin_'); $this->Task->Project->setReturnValue('getPrefix', 'admin_');
$this->Task->setReturnValueAt(0, 'in', 'y'); $this->Task->setReturnValueAt(0, 'in', 'y');
$this->Task->setReturnValueAt(1, 'in', 'n'); $this->Task->setReturnValueAt(1, 'in', 'n');
$this->Task->setReturnValueAt(2, 'in', 'y'); $this->Task->setReturnValueAt(2, 'in', 'y');
@ -444,11 +445,11 @@ class ViewTaskTest extends CakeTestCase {
)); ));
$this->Task->expectAt(2, 'createFile', array( $this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'admin_add.ctp', TMP . 'view_task_comments' . DS . 'admin_add.ctp',
new PatternExpectation('/Add View Task Comment/') new PatternExpectation('/Add .+View Task Comment/')
)); ));
$this->Task->expectAt(3, 'createFile', array( $this->Task->expectAt(3, 'createFile', array(
TMP . 'view_task_comments' . DS . 'admin_edit.ctp', TMP . 'view_task_comments' . DS . 'admin_edit.ctp',
new PatternExpectation('/Edit View Task Comment/') new PatternExpectation('/Edit .+View Task Comment/')
)); ));
$this->Task->execute(); $this->Task->execute();

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* ErrorHandlerTest file * ErrorHandlerTest file
* *
@ -9,20 +7,17 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake * @package cake
* @subpackage cake.tests.cases.libs * @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5432 * @since CakePHP(tm) v 1.2.0.5432
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
if (class_exists('TestErrorHandler')) { if (class_exists('TestErrorHandler')) {
@ -212,6 +207,34 @@ class BlueberryController extends AppController {
var $components = array('Auth'); var $components = array('Auth');
} }
/**
* MyCustomErrorHandler class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class MyCustomErrorHandler extends ErrorHandler {
/**
* custom error message type.
*
* @return void
**/
function missingWidgetThing() {
echo 'widget thing is missing';
}
/**
* stop method
*
* @access public
* @return void
*/
function _stop() {
return;
}
}
/** /**
* TestErrorHandler class * TestErrorHandler class
* *
@ -249,6 +272,35 @@ class ErrorHandlerTest extends CakeTestCase {
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console'); $this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
} }
/**
* test that methods declared in an ErrorHandler subclass are not converted
* into error404 when debug == 0
*
* @return void
**/
function testSubclassMethodsNotBeingConvertedToError() {
$back = Configure::read('debug');
Configure::write('debug', 2);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing');
Configure::write('debug', 0);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
Configure::write('debug', 0);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingController', array('message' => 'Page not found'));
$result = ob_get_clean();
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
Configure::write('debug', $back);
}
/** /**
* testError method * testError method
* *
@ -261,9 +313,10 @@ class ErrorHandlerTest extends CakeTestCase {
ob_clean(); ob_clean();
ob_start(); ob_start();
$TestErrorHandler->error(array( $TestErrorHandler->error(array(
'code' => 404, 'code' => 404,
'message' => 'Page not Found', 'message' => 'Page not Found',
'name' => "Couldn't find what you were looking for")); 'name' => "Couldn't find what you were looking for"
));
$result = ob_get_clean(); $result = ob_get_clean();
$this->assertPattern("/<h2>Couldn't find what you were looking for<\/h2>/", $result); $this->assertPattern("/<h2>Couldn't find what you were looking for<\/h2>/", $result);
$this->assertPattern('/Page not Found/', $result); $this->assertPattern('/Page not Found/', $result);

View file

@ -416,6 +416,35 @@ class FileTest extends CakeTestCase {
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* testCopy method
*
* @access public
* @return void
*/
function testCopy() {
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
$file = __FILE__;
$this->File =& new File($file);
$result = $this->File->copy($dest);
$this->assertTrue($result);
$result = $this->File->copy($dest, true);
$this->assertTrue($result);
$result = $this->File->copy($dest, false);
$this->assertFalse($result);
$this->File->close();
unlink($dest);
$TmpFile =& new File('/this/does/not/exist');
$result = $TmpFile->copy($dest);
$this->assertFalse($result);
$TmpFile->close();
}
/** /**
* getTmpFile method * getTmpFile method
* *

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* ValidationTest file * ValidationTest file
* *
@ -9,20 +7,17 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake * @package cake
* @subpackage cake.tests.cases.libs * @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.4206 * @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
App::import('Core', 'Validation'); App::import('Core', 'Validation');
@ -177,7 +172,10 @@ class ValidationTest extends CakeTestCase {
function testBetween() { function testBetween() {
$this->assertTrue(Validation::between('abcdefg', 1, 7)); $this->assertTrue(Validation::between('abcdefg', 1, 7));
$this->assertTrue(Validation::between('', 0, 7)); $this->assertTrue(Validation::between('', 0, 7));
$this->assertTrue(Validation::between('אกあアꀀ豈', 1, 7));
$this->assertFalse(Validation::between('abcdefg', 1, 6)); $this->assertFalse(Validation::between('abcdefg', 1, 6));
$this->assertFalse(Validation::between('ÆΔΩЖÇ', 1, 3));
} }
/** /**
@ -1698,7 +1696,10 @@ class ValidationTest extends CakeTestCase {
function testMaxLength() { function testMaxLength() {
$this->assertTrue(Validation::maxLength('ab', 3)); $this->assertTrue(Validation::maxLength('ab', 3));
$this->assertTrue(Validation::maxLength('abc', 3)); $this->assertTrue(Validation::maxLength('abc', 3));
$this->assertTrue(Validation::maxLength('ÆΔΩЖÇ', 10));
$this->assertFalse(Validation::maxLength('abcd', 3)); $this->assertFalse(Validation::maxLength('abcd', 3));
$this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3));
} }
/** /**
@ -1709,8 +1710,11 @@ class ValidationTest extends CakeTestCase {
*/ */
function testMinLength() { function testMinLength() {
$this->assertFalse(Validation::minLength('ab', 3)); $this->assertFalse(Validation::minLength('ab', 3));
$this->assertFalse(Validation::minLength('ÆΔΩЖÇ', 10));
$this->assertTrue(Validation::minLength('abc', 3)); $this->assertTrue(Validation::minLength('abc', 3));
$this->assertTrue(Validation::minLength('abcd', 3)); $this->assertTrue(Validation::minLength('abcd', 3));
$this->assertTrue(Validation::minLength('ÆΔΩЖÇ', 2));
} }
/** /**
@ -1770,33 +1774,6 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::inList('three', array('one', 'two'))); $this->assertFalse(Validation::inList('three', array('one', 'two')));
} }
/**
* testValidNumber method
*
* @access public
* @return void
*/
function testValidNumber() {
$this->assertTrue(Validation::custom('12345', VALID_NUMBER));
$this->assertTrue(Validation::custom('-12345', VALID_NUMBER));
$this->assertTrue(Validation::custom('+12345', VALID_NUMBER));
$this->assertFalse(Validation::custom('--12345', VALID_NUMBER));
$this->assertFalse(Validation::custom('++12345', VALID_NUMBER));
$this->assertFalse(Validation::custom('a12345', VALID_NUMBER));
$this->assertFalse(Validation::custom('12345z', VALID_NUMBER));
$this->assertFalse(Validation::custom('-a12345z', VALID_NUMBER));
$this->assertFalse(Validation::custom('-', VALID_NUMBER));
$this->assertFalse(Validation::custom('123-12345', VALID_NUMBER));
$this->assertTrue(Validation::custom('1.2345', VALID_NUMBER));
$this->assertTrue(Validation::custom('-1.2345', VALID_NUMBER));
$this->assertTrue(Validation::custom('+1.2345', VALID_NUMBER));
$this->assertFalse(Validation::custom('1..2345', VALID_NUMBER));
$this->assertFalse(Validation::custom('-1..2345', VALID_NUMBER));
$this->assertFalse(Validation::custom('+1..2345', VALID_NUMBER));
$this->assertFalse(Validation::custom('.2345', VALID_NUMBER));
$this->assertFalse(Validation::custom('12345.', VALID_NUMBER));
}
/** /**
* testRange method * testRange method
* *

View file

@ -100,7 +100,7 @@ class CacheHelperTest extends CakeTestCase {
function startCase() { function startCase() {
App::build(array( App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
)); ), true);
} }
/** /**

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* TextHelperTest file * TextHelperTest file
* *
@ -9,20 +7,17 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.view.helpers * @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206 * @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
App::import('Helper', 'Text'); App::import('Helper', 'Text');
@ -70,10 +65,7 @@ class TextHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testTruncate() { function testTruncate() {
if (!isset($this->method)) { $m = 'truncate';
$this->method = 'truncate';
}
$m = $this->method;
$text1 = 'The quick brown fox jumps over the lazy dog'; $text1 = 'The quick brown fox jumps over the lazy dog';
$text2 = 'Heiz&ouml;lr&uuml;cksto&szlig;abd&auml;mpfung'; $text2 = 'Heiz&ouml;lr&uuml;cksto&szlig;abd&auml;mpfung';
$text3 = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener'; $text3 = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
@ -82,35 +74,32 @@ class TextHelperTest extends CakeTestCase {
$text6 = '<p><strong>Extra dates have been announced for this year\'s tour.</strong></p><p>Tickets for the new shows in</p>'; $text6 = '<p><strong>Extra dates have been announced for this year\'s tour.</strong></p><p>Tickets for the new shows in</p>';
$text7 = 'El moño está en el lugar correcto. Eso fue lo que dijo la niña, ¿habrá dicho la verdad?'; $text7 = 'El moño está en el lugar correcto. Eso fue lo que dijo la niña, ¿habrá dicho la verdad?';
$text8 = 'Vive la R'.chr(195).chr(169).'publique de France'; $text8 = 'Vive la R'.chr(195).chr(169).'publique de France';
$text9 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertIdentical($this->Text->{$m}($text1, 15), 'The quick br...'); $this->assertIdentical($this->Text->truncate($text1, 15), 'The quick br...');
$this->assertIdentical($this->Text->{$m}($text1, 15, '...', false), 'The quick...'); $this->assertIdentical($this->Text->truncate($text1, 15, '...', false), 'The quick...');
$this->assertIdentical($this->Text->{$m}($text1, 100), 'The quick brown fox jumps over the lazy dog'); $this->assertIdentical($this->Text->truncate($text1, 100), 'The quick brown fox jumps over the lazy dog');
$this->assertIdentical($this->Text->{$m}($text2, 10, '...'), 'Heiz&ou...'); $this->assertIdentical($this->Text->truncate($text2, 10, '...'), 'Heiz&ou...');
$this->assertIdentical($this->Text->{$m}($text2, 10, '...', false), '...'); $this->assertIdentical($this->Text->truncate($text2, 10, '...', false), '...');
$this->assertIdentical($this->Text->{$m}($text3, 20), '<b>&copy; 2005-20...'); $this->assertIdentical($this->Text->truncate($text3, 20), '<b>&copy; 2005-20...');
$this->assertIdentical($this->Text->{$m}($text4, 15), '<img src="my...'); $this->assertIdentical($this->Text->truncate($text4, 15), '<img src="my...');
$this->assertIdentical($this->Text->{$m}($text5, 6, ''), '0<b>1<'); $this->assertIdentical($this->Text->truncate($text5, 6, ''), '0<b>1<');
$this->assertIdentical($this->Text->{$m}($text1, 15, array('ending' => '...', 'exact' => true, 'considerHtml' => true)), 'The quick br...'); $this->assertIdentical($this->Text->truncate($text1, 15, array('ending' => '...', 'exact' => true, 'considerHtml' => true)), 'The quick br...');
$this->assertIdentical($this->Text->{$m}($text1, 15, '...', true, true), 'The quick br...'); $this->assertIdentical($this->Text->truncate($text1, 15, '...', true, true), 'The quick br...');
$this->assertIdentical($this->Text->{$m}($text1, 15, '...', false, true), 'The quick...'); $this->assertIdentical($this->Text->truncate($text1, 15, '...', false, true), 'The quick...');
$this->assertIdentical($this->Text->{$m}($text2, 10, '...', true, true), 'Heiz&ouml;lr...'); $this->assertIdentical($this->Text->truncate($text2, 10, '...', true, true), 'Heiz&ouml;lr...');
$this->assertIdentical($this->Text->{$m}($text2, 10, '...', false, true), '...'); $this->assertIdentical($this->Text->truncate($text2, 10, '...', false, true), '...');
$this->assertIdentical($this->Text->{$m}($text3, 20, '...', true, true), '<b>&copy; 2005-2007, Cake...</b>'); $this->assertIdentical($this->Text->truncate($text3, 20, '...', true, true), '<b>&copy; 2005-2007, Cake...</b>');
$this->assertIdentical($this->Text->{$m}($text4, 15, '...', true, true), '<img src="mypic.jpg"> This image ...'); $this->assertIdentical($this->Text->truncate($text4, 15, '...', true, true), '<img src="mypic.jpg"> This image ...');
$this->assertIdentical($this->Text->{$m}($text4, 45, '...', true, true), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But t...</b>'); $this->assertIdentical($this->Text->truncate($text4, 45, '...', true, true), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But t...</b>');
$this->assertIdentical($this->Text->{$m}($text4, 90, '...', true, true), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Grea...'); $this->assertIdentical($this->Text->truncate($text4, 90, '...', true, true), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Grea...');
$this->assertIdentical($this->Text->{$m}($text5, 6, '', true, true), '0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>'); $this->assertIdentical($this->Text->truncate($text5, 6, '', true, true), '0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>');
$this->assertIdentical($this->Text->{$m}($text5, 20, '', true, true), $text5); $this->assertIdentical($this->Text->truncate($text5, 20, '', true, true), $text5);
$this->assertIdentical($this->Text->{$m}($text6, 57, '...', false, true), "<p><strong>Extra dates have been announced for this year's...</strong></p>"); $this->assertIdentical($this->Text->truncate($text6, 57, '...', false, true), "<p><strong>Extra dates have been announced for this year's...</strong></p>");
$this->assertIdentical($this->Text->{$m}($text7, 255), $text7); $this->assertIdentical($this->Text->truncate($text7, 255), $text7);
$this->assertIdentical($this->Text->{$m}($text7, 15), 'El moño está...'); $this->assertIdentical($this->Text->truncate($text7, 15), 'El moño está...');
$this->assertIdentical($this->Text->{$m}($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...'); $this->assertIdentical($this->Text->truncate($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...');
$this->assertIdentical($this->Text->truncate($text9, 10), 'НОПРСТУ...');
if ($this->method == 'truncate') {
$this->method = 'trim';
$this->testTruncate();
}
} }
/** /**