Merge branch '2.0' into 2.0-helpers

This commit is contained in:
mark_story 2010-08-16 23:02:44 -04:00
commit f46241a6e7
34 changed files with 770 additions and 258 deletions

View file

@ -29,3 +29,5 @@ SET lib=%~dp0
php -q "%lib%cake.php" -working "%CD%" %*
echo.
exit /B %ERRORLEVEL%

View file

@ -110,7 +110,7 @@ class Dispatcher extends Object {
$this->here = $this->base . '/' . $url;
if ($this->asset($url) || $this->cached($url)) {
$this->_stop();
return;
}
$controller = $this->_getController();
@ -186,7 +186,7 @@ class Dispatcher extends Object {
$methods = array_flip($controller->methods);
if (!isset($methods[strtolower($params['action'])])) {
if (!isset($methods[$params['action']])) {
if ($controller->scaffold !== false) {
App::import('Controller', 'Scaffold', false);
return new Scaffold($controller, $params);
@ -224,8 +224,11 @@ class Dispatcher extends Object {
*/
protected function _extractParams($url, $additionalParams = array()) {
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
$this->params = array_merge($defaults, $url, $additionalParams);
return Router::url($url);
$params = array_merge($defaults, $url, $additionalParams);
$this->params = $params;
$params += array('base' => false, 'url' => array());
return ltrim(Router::reverse($params), '/');
}
/**

View file

@ -20,7 +20,9 @@
*/
/**
* Memcache storage engine for cache
* Memcache storage engine for cache. Memcache has some limitations in the amount of
* control you have over expire times far in the future. See MemcacheEngine::write() for
* more information.
*
* @package cake
* @subpackage cake.cake.libs.cache
@ -94,17 +96,19 @@ class MemcacheEngine extends CacheEngine {
}
/**
* Write data for key into cache
* Write data for key into cache. When using memcache as your cache engine
* remember that the Memcache pecl extension does not support cache expiry times greater
* than 30 days in the future. If you wish to create cache entries that do not expire, set the duration
* to `0` in your cache configuration.
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
* @param integer $duration How long to cache the data, in seconds
* @return boolean True if the data was succesfully cached, false on failure
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
$expires = time() + $duration;
$this->__Memcache->set($key . '_expires', $expires, $this->settings['compress'], $expires);
return $this->__Memcache->set($key, $value, $this->settings['compress'], $expires);
public function write($key, &$value, $duration) {
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
}
/**
@ -114,11 +118,6 @@ class MemcacheEngine extends CacheEngine {
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
*/
public function read($key) {
$time = time();
$cachetime = intval($this->__Memcache->get($key . '_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
return $this->__Memcache->get($key);
}

View file

@ -193,8 +193,8 @@ class Scaffold extends Object {
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'
));
if ($this->controller->view && $this->controller->view !== 'Theme') {
$this->controller->view = 'scaffold';
if ($this->controller->view) {
$this->controller->view = 'Scaffold';
}
$this->_validSession = (
isset($this->controller->Session) && $this->controller->Session->valid() != false

View file

@ -470,6 +470,7 @@ class Folder {
$this->__errors[] = sprintf(__('%s is a file'), $pathname);
return false;
}
$pathname = rtrim($pathname, DS);
$nextPathname = substr($pathname, 0, strrpos($pathname, DS));
if ($this->create($nextPathname, $mode)) {

View file

@ -131,7 +131,7 @@ class Inflector {
'/(drive)s$/i' => '\1',
'/([^fo])ves$/i' => '\1fe',
'/(^analy)ses$/i' => '\1sis',
'/(analy|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/(analy|ba|diagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/([ti])a$/i' => '\1um',
'/(p)eople$/i' => '\1\2erson',
'/(m)en$/i' => '\1an',

View file

@ -48,6 +48,7 @@ class AclBehavior extends ModelBehavior {
$config = array('type' => $config);
}
$this->settings[$model->name] = array_merge(array('type' => 'requester'), (array)$config);
$this->settings[$model->name]['type'] = strtolower($this->settings[$model->name]['type']);
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
if (!class_exists('AclNode')) {
@ -67,7 +68,7 @@ class AclBehavior extends ModelBehavior {
* @link http://book.cakephp.org/view/1322/node
*/
public function node(&$model, $ref = null) {
$type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])];
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
if (empty($ref)) {
$ref = array('model' => $model->name, 'foreign_key' => $model->id);
}
@ -81,7 +82,7 @@ class AclBehavior extends ModelBehavior {
* @return void
*/
public function afterSave(&$model, $created) {
$type = $this->__typeMaps[strtolower($this->settings[$model->alias]['type'])];
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
$parent = $model->parentNode();
if (!empty($parent)) {
$parent = $this->node($model, $parent);
@ -105,7 +106,7 @@ class AclBehavior extends ModelBehavior {
* @return void
*/
public function afterDelete(&$model) {
$type = $this->__typeMaps[strtolower($this->settings[$model->name]['type'])];
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
$node = Set::extract($this->node($model), "0.{$type}.id");
if (!empty($node)) {
$model->{$type}->delete($node);

View file

@ -703,7 +703,10 @@ class TreeBehavior extends ModelBehavior {
}
$db =& ConnectionManager::getDataSource($Model->useDbConfig);
$Model->updateAll(array($parent => $db->value($node[$parent], $parent)), array($parent => $node[$Model->primaryKey]));
$Model->updateAll(
array($parent => $db->value($node[$parent], $parent)),
array($Model->escapeField($parent) => $node[$Model->primaryKey])
);
$this->__sync($Model, 1, '-', 'BETWEEN ' . ($node[$left] + 1) . ' AND ' . ($node[$right] - 1));
$this->__sync($Model, 2, '-', '> ' . ($node[$right]));
$Model->id = $id;

View file

@ -122,7 +122,7 @@ class DboMysqlBase extends DboSource {
return $cache;
}
$fields = false;
$cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
$cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model));
foreach ($cols as $column) {
$colKey = array_keys($column);
@ -139,11 +139,23 @@ class DboMysqlBase extends DboSource {
if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
$fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
}
foreach ($this->fieldParameters as $name => $value) {
if (!empty($column[0][$value['column']])) {
$fields[$column[0]['Field']][$name] = $column[0][$value['column']];
}
}
if (isset($fields[$column[0]['Field']]['collate'])) {
$charset = $this->getCharsetName($fields[$column[0]['Field']]['collate']);
if ($charset) {
$fields[$column[0]['Field']]['charset'] = $charset;
}
}
}
}
$this->__cacheDescription($this->fullTableName($model, false), $fields);
return $fields;
}
/**
* Generates and executes an SQL UPDATE statement for given model, fields, and values.
*
@ -274,7 +286,7 @@ class DboMysqlBase extends DboSource {
$out = '';
$colList = array();
foreach ($compare as $curTable => $types) {
$indexes = $tableParameters = array();
$indexes = $tableParameters = $colList = array();
if (!$table || $table == $curTable) {
$out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
foreach ($types as $type => $column) {

View file

@ -561,7 +561,7 @@ class DboPostgres extends DboSource {
$out = '';
$colList = array();
foreach ($compare as $curTable => $types) {
$indexes = array();
$indexes = $colList = array();
if (!$table || $table == $curTable) {
$out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
foreach ($types as $type => $column) {
@ -629,7 +629,7 @@ class DboPostgres extends DboSource {
} else {
$out = '';
}
$out .= implode(";\n\t", $this->_alterIndexes($curTable, $indexes)) . ";";
$out .= implode(";\n\t", $this->_alterIndexes($curTable, $indexes));
}
}
return $out;

View file

@ -2013,7 +2013,7 @@ class Model extends Object {
}
/**
* Returns a result set array.
* Queries the datasource and returns a result set array.
*
* Also used to perform new-notation finds, where the first argument is type of find operation to perform
* (all / first / count / neighbors / list / threaded ),
@ -2022,8 +2022,8 @@ class Model extends Object {
*
* Eg:
* {{{
* find('all', array(
* 'conditions' => array('name' => 'Thomas Anderson'),
* find('all', array(
* 'conditions' => array('name' => 'Thomas Anderson'),
* 'fields' => array('name', 'email'),
* 'order' => 'field3 DESC',
* 'recursive' => 2,
@ -2031,6 +2031,24 @@ class Model extends Object {
* ));
* }}}
*
* In addition to the standard query keys above, you can provide Datasource, and behavior specific
* keys. For example, when using a SQL based datasource you can use the joins key to specify additional
* joins that should be part of the query.
*
* {{{
* find('all', array(
* 'conditions' => array('name' => 'Thomas Anderson'),
* 'joins' => array(
* 'alias' => 'Thought',
* 'table' => 'thoughts',
* 'type' => 'LEFT',
* 'conditions' => '`Thought`.`person_id` = `Person`.`id`'
* )
* ));
* }}}
*
* Behaviors and find types can also define custom finder keys which are passed into find().
*
* Specifying 'fields' for new-notation 'list':
*
* - If no fields are specified, then 'id' is used for key and 'model->displayField' is used for value.
@ -2039,9 +2057,9 @@ class Model extends Object {
* - Otherwise, first and second fields are used for key and value.
*
* @param array $conditions SQL conditions array, or type of find operation (all / first / count /
* neighbors / list / threaded)
* neighbors / list / threaded)
* @param mixed $fields Either a single string of a field name, or an array of field names, or
* options for matching
* options for matching
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of records

View file

@ -1010,6 +1010,9 @@ class Router {
* Since parsed URL's contain additional 'pass' and 'named' as well as 'url.url' keys.
* Those keys need to be specially handled in order to reverse a params array into a string url.
*
* This will strip out 'autoRender', 'bare', 'requested', and 'return' param names as those
* are used for CakePHP internals and should not normally be part of an output url.
*
* @param array $param The params array that needs to be reversed.
* @return string The string that is the reversed result of the array
*/
@ -1017,7 +1020,10 @@ class Router {
$pass = $params['pass'];
$named = $params['named'];
$url = $params['url'];
unset($params['pass'], $params['named'], $params['paging'], $params['models'], $params['url'], $url['url']);
unset(
$params['pass'], $params['named'], $params['paging'], $params['models'], $params['url'], $url['url'],
$params['autoRender'], $params['bare'], $params['requested'], $params['return']
);
$params = array_merge($params, $pass, $named);
if (!empty($url)) {
$params['?'] = $url;
@ -1309,8 +1315,9 @@ class CakeRoute {
$route = $this->template;
$names = $routeParams = array();
$parsed = preg_quote($this->template, '#');
$parsed = str_replace('\\-', '-', $parsed);
preg_match_all('#:([A-Za-z0-9_-]+[A-Z0-9a-z])#', $route, $namedElements);
preg_match_all('#:([A-Za-z0-9_-]+[A-Z0-9a-z])#', $parsed, $namedElements);
foreach ($namedElements[1] as $i => $name) {
$search = '\\' . $namedElements[0][$i];
if (isset($this->options[$name])) {
@ -1320,12 +1327,12 @@ class CakeRoute {
}
$slashParam = '/\\' . $namedElements[0][$i];
if (strpos($parsed, $slashParam) !== false) {
$routeParams[$slashParam] = '(?:/(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
$routeParams[$slashParam] = '(?:/(' . $this->options[$name] . ')' . $option . ')' . $option;
} else {
$routeParams[$search] = '(?:(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
$routeParams[$search] = '(?:(' . $this->options[$name] . ')' . $option . ')' . $option;
}
} else {
$routeParams[$search] = '(?:(?P<' . $name . '>[^/]+))';
$routeParams[$search] = '(?:([^/]+))';
}
$names[] = $name;
}
@ -1351,7 +1358,7 @@ class CakeRoute {
if (!$this->compiled()) {
$this->compile();
}
if (!preg_match($this->_compiledRoute, $url, $route)) {
if (!preg_match($this->_compiledRoute, $url, $parsed)) {
return false;
} else {
foreach ($this->defaults as $key => $val) {
@ -1375,15 +1382,18 @@ class CakeRoute {
}
}
}
array_shift($route);
$count = count($this->keys);
for ($i = 0; $i <= $count; $i++) {
unset($route[$i]);
array_shift($parsed);
$route = array();
foreach ($this->keys as $i => $key) {
if (isset($parsed[$i])) {
$route[$key] = $parsed[$i];
}
}
$route['pass'] = $route['named'] = array();
$route += $this->defaults;
//move numerically indexed elements from the defaults into pass.
if (isset($parsed['_args_'])) {
$route['_args_'] = $parsed['_args_'];
}
foreach ($route as $key => $value) {
if (is_integer($key)) {
$route['pass'][] = $value;

View file

@ -237,6 +237,7 @@ class String {
}
$tempData = array_combine(array_keys($data), array_values($hashKeys));
krsort($tempData);
foreach ($tempData as $key => $hashVal) {
$key = sprintf($format, preg_quote($key, '/'));
$str = preg_replace($key, $hashVal, $str);

View file

@ -20,9 +20,9 @@
if (!class_exists('ConnectionManager') || Configure::read('debug') < 2) {
return false;
}
$sources = ConnectionManager::sourceList();
if (!isset($logs)):
$sources = ConnectionManager::sourceList();
$logs = array();
foreach ($sources as $source):
$db =& ConnectionManager::getDataSource($source);
@ -31,24 +31,27 @@ if (!isset($logs)):
endif;
$logs[$source] = $db->getLog();
endforeach;
endif;
foreach ($logs as $source => $logInfo):
$text = $logInfo['count'] > 1 ? 'queries' : 'query';
printf(
'<table class="cake-sql-log" id="cakeSqlLog_%s" summary="Cake SQL Log" cellspacing="0" border = "0">',
preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true))
);
printf('<caption>(%s) %s %s took %s ms</caption>', $source, $logInfo['count'], $text, $logInfo['time']);
?>
<thead>
<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>
</thead>
<tbody>
<?php
foreach ($logInfo['log'] as $k => $i) :
echo "<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n";
foreach ($logs as $source => $logInfo):
$text = $logInfo['count'] > 1 ? 'queries' : 'query';
printf(
'<table class="cake-sql-log" id="cakeSqlLog_%s" summary="Cake SQL Log" cellspacing="0" border = "0">',
preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true))
);
printf('<caption>(%s) %s %s took %s ms</caption>', $source, $logInfo['count'], $text, $logInfo['time']);
?>
<thead>
<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>
</thead>
<tbody>
<?php
foreach ($logInfo['log'] as $k => $i) :
echo "<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n";
endforeach;
?>
</tbody></table>
<?php
endforeach;
endif;
?>
</tbody></table>
<?php endforeach; ?>

View file

@ -1765,6 +1765,8 @@ class FormHelper extends AppHelper {
* - `separator` The contents of the string between select elements. Defaults to '-'
* - `empty` - If true, the empty select option is shown. If a string,
* that string is displayed as the empty element.
* - `value` | `default` The default value to be used by the input. A value in `$this->data`
* matching the field name will override this value. If no default is provided `time()` will be used.
*
* @param string $fieldName Prefix name for the SELECT element
* @param string $dateFormat DMY, MDY, YMD.
@ -1780,7 +1782,12 @@ class FormHelper extends AppHelper {
$year = $month = $day = $hour = $min = $meridian = null;
if (empty($selected)) {
$selected = $this->value($fieldName);
$selected = $this->value($attributes, $fieldName);
if (isset($selected['value'])) {
$selected = $selected['value'];
} else {
$selected = null;
}
}
if ($selected === null && $attributes['empty'] != true) {

View file

@ -428,7 +428,7 @@ class HtmlHelper extends AppHelper {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
if (strpos($url, '?') === false && strpos($url, '.js') === false) {
if (strpos($url, '?') === false && substr($url, -3) !== '.js') {
$url .= '.js';
}
$url = $this->assetTimestamp($this->webroot($url));

View file

@ -202,6 +202,13 @@ class RssHelper extends XmlHelper {
foreach ($elements as $key => $val) {
$attrib = array();
$escape = true;
if (is_array($val) && isset($val['convertEntities'])) {
$escape = $val['convertEntities'];
unset($val['convertEntities']);
}
switch ($key) {
case 'pubDate' :
$val = $this->time($val);
@ -255,11 +262,6 @@ class RssHelper extends XmlHelper {
$val = null;
break;
}
$escape = true;
if (is_array($val) && isset($val['convertEntities'])) {
$escape = $val['convertEntities'];
unset($val['convertEntities']);
}
if (!is_null($val) && $escape) {
$val = h($val);
}

View file

@ -1283,12 +1283,12 @@ class DispatcherTest extends CakeTestCase {
*
* @return void
*/
public function testDispatch() {
public function testDispatchBasic() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
Configure::write('App.baseUrl', '/index.php');
$url = 'pages/home/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
@ -1331,7 +1331,6 @@ class DispatcherTest extends CakeTestCase {
$this->assertEqual('Timesheets', $controller->name);
$this->assertEqual('/timesheets/index.php', $Dispatcher->base);
$url = 'test_dispatch_pages/camelCased';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual('TestDispatchPages', $controller->name);
@ -1353,15 +1352,22 @@ class DispatcherTest extends CakeTestCase {
));
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
$url = 'pages/home/param:value/param2:value2';
$url = array('controller' => 'pages', 'action' => 'display');
$controller = $Dispatcher->dispatch($url, array('pass' => array('home'), 'named' => array('param' => 'value', 'param2' => 'value2'), 'return' => 1));
$controller = $Dispatcher->dispatch($url, array(
'pass' => array('home'),
'named' => array('param' => 'value', 'param2' => 'value2'),
'return' => 1
));
$expected = 'Pages';
$this->assertEqual($expected, $controller->name);
$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs);
$this->assertEqual($Dispatcher->base . '/pages/display/home/param:value/param2:value2', $Dispatcher->here);
}
/**

View file

@ -203,11 +203,12 @@ class CakeTestFixtureTest extends CakeTestCase {
$this->assertEqual(count($Fixture->records), count($Source->records));
$Fixture->create(ConnectionManager::getDataSource('fixture_test_suite'));
$Fixture2 = new CakeTestFixtureImportFixture();
$Fixture2->fields = $Fixture->records = null;
$Fixture2->import = array('model' => 'FixtureImportTestModel', 'connection' => 'fixture_test_suite');
$Fixture2->init();
$this->assertEqual(array_keys($Fixture2->fields), array('id', 'name', 'created'));
$Fixture =& new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test_suite');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$this->assertEqual($Fixture->table, 'fixture_tests');
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
@ -216,14 +217,43 @@ class CakeTestFixtureTest extends CakeTestCase {
$Source->drop($db);
}
/**
* test that fixtures don't duplicate the test db prefix.
*
* @return void
*/
function testInitDbPrefixDuplication() {
$this->_initDb();
$backPrefix = $this->db->config['prefix'];
$this->db->config['prefix'] = 'cake_fixture_test_';
$Source =& new CakeTestFixtureTestFixture();
$Source->create($this->db);
$Source->insert($this->db);
$Fixture =& new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test_suite');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$this->assertEqual($Fixture->table, 'fixture_tests');
$Source->drop($this->db);
$this->db->config['prefix'] = $backPrefix;
}
/**
* test init with a model that has a tablePrefix declared.
*
* @return void
*/
function testInitModelTablePrefix() {
$db = ConnectionManager::getDataSource('test_suite');
$this->_initDb();
$hasPrefix = !empty($this->db->config['prefix']);
if ($this->skipIf($hasPrefix, 'Cannot run this test, you have a database connection prefix.')) {
return;
}
$Source =& new CakeTestFixtureTestFixture();
$Source->create($db);
$Source->insert($db);

View file

@ -730,6 +730,7 @@ class ScaffoldTest extends CakeTestCase {
$result = $Scaffold->getParams();
$this->assertEqual($result['action'], 'admin_edit');
}
/**
* test that the proper names and variable values are set by Scaffold
*
@ -769,6 +770,24 @@ class ScaffoldTest extends CakeTestCase {
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
}
function getTests() {
return array('start', 'startCase', 'testScaffoldChangingViewProperty', 'endCase', 'end');
}
/**
* test that Scaffold overrides the view property even if its set to 'Theme'
*
* @return void
*/
function testScaffoldChangingViewProperty() {
$this->Controller->action = 'edit';
$this->Controller->theme = 'test_theme';
$this->Controller->view = 'Theme';
$this->Controller->constructClasses();
$Scaffold =& new TestScaffoldMock($this->Controller, array());
$this->assertEqual($this->Controller->view, 'Scaffold');
}
/**
* test that scaffold outputs flash messages when sessions are unset.

View file

@ -108,7 +108,8 @@ class FolderTest extends CakeTestCase {
function testCreateWithTrailingDs() {
$folder = new Folder(TMP);
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
$folder->create($path);
$result = $folder->create($path);
$this->assertTrue($result);
$this->assertTrue(is_dir($path), 'Folder was not made');

View file

@ -101,6 +101,9 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::singularize('parantheses'), 'paranthesis');
$this->assertEqual(Inflector::singularize('Causes'), 'Cause');
$this->assertEqual(Inflector::singularize('colossuses'), 'colossus');
$this->assertEqual(Inflector::singularize('diagnoses'), 'diagnosis');
$this->assertEqual(Inflector::singularize('bases'), 'basis');
$this->assertEqual(Inflector::singularize('analyses'), 'analysis');
$this->assertEqual(Inflector::singularize(''), '');
}

View file

@ -89,14 +89,15 @@ class AclPerson extends CakeTestModel {
if (!$this->id && empty($this->data)) {
return null;
}
$data = $this->data;
if (empty($this->data)) {
$data = $this->read();
if (isset($this->data['AclPerson']['mother_id'])) {
$motherId = $this->data['AclPerson']['mother_id'];
} else {
$motherId = $this->field('mother_id');
}
if (!$data['AclPerson']['mother_id']) {
if (!$motherId) {
return null;
} else {
return array('AclPerson' => array('id' => $data['AclPerson']['mother_id']));
return array('AclPerson' => array('id' => $motherId));
}
}
}
@ -172,7 +173,7 @@ class AclPost extends CakeTestModel {
* @var array
* @access public
*/
public $actsAs = array('Acl' => 'controlled');
var $actsAs = array('Acl' => 'Controlled');
/**
* parentNode
@ -270,7 +271,9 @@ class AclBehaviorTest extends CakeTestCase {
),
);
$Post->save($data);
$result = $this->Aco->find('first', array('conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id)));
$result = $this->Aco->find('first', array(
'conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id)
));
$this->assertTrue(is_array($result));
$this->assertEqual($result['Aco']['model'], 'Post');
$this->assertEqual($result['Aco']['foreign_key'], $Post->id);
@ -293,7 +296,9 @@ class AclBehaviorTest extends CakeTestCase {
),
);
$Person->save($data);
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)));
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
));
$this->assertTrue(is_array($result));
$this->assertEqual($result['Aro']['parent_id'], 5);
@ -308,21 +313,60 @@ class AclBehaviorTest extends CakeTestCase {
'foreign_key' => 1,
'parent_id' => null
)
);
$this->Aro->create();
$this->Aro->save($aroData);
);
$this->Aro->create();
$this->Aro->save($aroData);
$Person->read(null, 8);
$Person->set('mother_id', 1);
$Person->save();
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)));
$Person->read(null, 8);
$Person->set('mother_id', 1);
$Person->save();
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
));
$this->assertTrue(is_array($result));
$this->assertEqual($result['Aro']['parent_id'], 7);
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
$this->assertEqual(sizeof($node), 2);
$this->assertEqual($node[0]['Aro']['parent_id'], 7);
$this->assertEqual($node[1]['Aro']['parent_id'], null);
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
$this->assertEqual(sizeof($node), 2);
$this->assertEqual($node[0]['Aro']['parent_id'], 7);
$this->assertEqual($node[1]['Aro']['parent_id'], null);
}
/**
* test that an afterSave on an update does not cause parent_id to become null.
*
* @return void
*/
function testAfterSaveUpdateParentIdNotNull() {
$aroData = array(
'Aro' => array(
'model' => 'AclPerson',
'foreign_key' => 2,
'parent_id' => null
)
);
$this->Aro->save($aroData);
$Person =& new AclPerson();
$data = array(
'AclPerson' => array(
'name' => 'Trent',
'mother_id' => 2,
'father_id' => 3,
),
);
$Person->save($data);
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
));
$this->assertTrue(is_array($result));
$this->assertEqual($result['Aro']['parent_id'], 5);
$Person->save(array('id' => $Person->id, 'name' => 'Bruce'));
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
));
$this->assertEqual($result['Aro']['parent_id'], 5);
}
/**
@ -355,9 +399,13 @@ class AclBehaviorTest extends CakeTestCase {
$this->assertEqual($node[1]['Aro']['parent_id'], null);
$Person->delete($id);
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)));
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)
));
$this->assertTrue(empty($result));
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)));
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
));
$this->assertFalse(empty($result));
$data = array(
@ -370,12 +418,15 @@ class AclBehaviorTest extends CakeTestCase {
$Person->save($data);
$id = $Person->id;
$Person->delete(2);
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)));
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)
));
$this->assertTrue(empty($result));
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)));
$result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
));
$this->assertTrue(empty($result));
}
/**

View file

@ -672,6 +672,40 @@ class DboMysqlTest extends CakeTestCase {
$this->Dbo->query($this->Dbo->dropSchema($schema1));
}
/**
* test alterSchema on two tables.
*
* @return void
*/
function testAlteringTwoTables() {
$schema1 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
),
'other_table' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
)
));
$schema2 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
),
'other_table' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
)
));
$result = $this->db->alterSchema($schema2->compare($schema1));
$this->assertEqual(2, substr_count($result, 'field_two'), 'Too many fields');
}
/**
* testReadTableParameters method
*
@ -749,7 +783,41 @@ class DboMysqlTest extends CakeTestCase {
$result = $this->db->fields($model, null, array('data', 'other__field'));
$expected = array('`BinaryTest`.`data`', '(SUM(id)) AS BinaryTest_$_other__field');
$this->assertEqual($result, $expected);
}
/**
* test that a describe() gets additional fieldParameters
*
* @return void
*/
function testDescribeGettingFieldParameters() {
$schema =& new CakeSchema(array(
'connection' => 'test_suite',
'testdescribes' => array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'stringy' => array(
'type' => 'string',
'null' => true,
'charset' => 'cp1250',
'collate' => 'cp1250_general_ci',
),
'other_col' => array(
'type' => 'string',
'null' => false,
'charset' => 'latin1',
'comment' => 'Test Comment'
)
)
));
$this->db->execute($this->db->createSchema($schema));
$model =& new CakeTestModel(array('table' => 'testdescribes', 'name' => 'Testdescribes'));
$result = $this->db->describe($model);
$this->assertEqual($result['stringy']['collate'], 'cp1250_general_ci');
$this->assertEqual($result['stringy']['charset'], 'cp1250');
$this->assertEqual($result['other_col']['comment'], 'Test Comment');
$this->db->execute($this->db->dropSchema($schema));
}
}

View file

@ -546,7 +546,7 @@ class DboPostgresTest extends CakeTestCase {
date date,
CONSTRAINT test_suite_data_types_pkey PRIMARY KEY (id)
)');
$model = ClassRegistry::init('datatypes');
$model = new Model(array('name' => 'Datatype', 'ds' => 'test_suite'));
$schema = new CakeSchema(array('connection' => 'test_suite'));
$result = $schema->read(array(
'connection' => 'test_suite',
@ -781,4 +781,56 @@ class DboPostgresTest extends CakeTestCase {
$expected = array('COUNT(DISTINCT FUNC("id"))');
$this->assertEqual($result, $expected);
}
/**
* test that saveAll works even with conditions that lack a model name.
*
* @return void
*/
function testUpdateAllWithNonQualifiedConditions() {
$this->loadFixtures('Article');
$Article =& new Article();
$result = $Article->updateAll(array('title' => "'Awesome'"), array('published' => 'Y'));
$this->assertTrue($result);
$result = $Article->find('count', array(
'conditions' => array('Article.title' => 'Awesome')
));
$this->assertEqual($result, 3, 'Article count is wrong or fixture has changed.');
}
/**
* test alterSchema on two tables.
*
* @return void
*/
function testAlteringTwoTables() {
$schema1 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
),
'other_table' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
)
));
$schema2 =& new CakeSchema(array(
'name' => 'AlterTest1',
'connection' => 'test_suite',
'altertest' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
),
'other_table' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
)
));
$result = $this->db->alterSchema($schema2->compare($schema1));
$this->assertEqual(2, substr_count($result, 'field_two'), 'Too many fields');
$this->assertFalse(strpos(';ALTER', $result), 'Too many semi colons');
}
}

View file

@ -3613,6 +3613,7 @@ class ModelWriteTest extends BaseModelTest {
);
$this->assertEqual($TestModel->Comment->validationErrors, $expected);
}
/**
* TestFindAllWithoutForeignKey
*
@ -3626,57 +3627,58 @@ class ModelWriteTest extends BaseModelTest {
$conditions = array('Group.name' => 'group one');
$ProductUpdateAll->bindModel(array(
$ProductUpdateAll->bindModel(array(
'belongsTo' => array(
'Group' => array('className' => 'GroupUpdateAll')
)
));
$ProductUpdateAll->belongsTo = array(
$ProductUpdateAll->belongsTo = array(
'Group' => array('className' => 'GroupUpdateAll', 'foreignKey' => 'group_id')
);
$results = $ProductUpdateAll->find('all', compact('conditions'));
$results = $ProductUpdateAll->find('all', compact('conditions'));
$this->assertTrue(!empty($results));
$ProductUpdateAll->bindModel(array('belongsTo'=>array('Group')));
$ProductUpdateAll->belongsTo = array(
'Group' => array(
$ProductUpdateAll->bindModel(array('belongsTo'=>array('Group')));
$ProductUpdateAll->belongsTo = array(
'Group' => array(
'className' => 'GroupUpdateAll',
'foreignKey' => false,
'conditions' => 'ProductUpdateAll.groupcode = Group.code'
));
$resultsFkFalse = $ProductUpdateAll->find('all', compact('conditions'));
$this->assertTrue(!empty($resultsFkFalse));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'product one',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'product two',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
)
$resultsFkFalse = $ProductUpdateAll->find('all', compact('conditions'));
$this->assertTrue(!empty($resultsFkFalse));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'product one',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'product two',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
)
);
$this->assertEqual($results, $expected);
$this->assertEqual($resultsFkFalse, $expected);
}
);
$this->assertEqual($results, $expected);
$this->assertEqual($resultsFkFalse, $expected);
}
/**
* testProductUpdateAllWithForeignKey
*
@ -3684,7 +3686,7 @@ class ModelWriteTest extends BaseModelTest {
* @access public
* @return void
*/
function testProductUpdateAll() {
function testProductUpdateAll() {
$this->skipIf(
$this->db->config['driver'] == 'postgres',
'%s Currently, there is no way of doing joins in an update statement in postgresql'
@ -3694,39 +3696,39 @@ class ModelWriteTest extends BaseModelTest {
$conditions = array('Group.name' => 'group one');
$ProductUpdateAll->bindModel(array('belongsTo' => array(
$ProductUpdateAll->bindModel(array('belongsTo' => array(
'Group' => array('className' => 'GroupUpdateAll')))
);
$ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions);
$results = $ProductUpdateAll->find('all', array(
$ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions);
$results = $ProductUpdateAll->find('all', array(
'conditions' => array('ProductUpdateAll.name' => 'new product')
));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)));
$this->assertEqual($results, $expected);
}
$this->assertEqual($results, $expected);
}
/**
* testProductUpdateAllWithoutForeignKey
@ -3757,32 +3759,32 @@ class ModelWriteTest extends BaseModelTest {
)
);
$ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions);
$resultsFkFalse = $ProductUpdateAll->find('all', array('conditions' => array('ProductUpdateAll.name'=>'new product')));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)));
$this->assertEqual($resultsFkFalse, $expected);
}
$ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions);
$resultsFkFalse = $ProductUpdateAll->find('all', array('conditions' => array('ProductUpdateAll.name'=>'new product')));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)));
$this->assertEqual($resultsFkFalse, $expected);
}
/**
* test that saveAll behaves like plain save() when suplied empty data

View file

@ -92,6 +92,15 @@ class RequestActionController extends Controller {
return 'Hello World';
}
/**
* returns $this->here
*
* @return void
*/
function return_here() {
return $this->here;
}
/**
* paginate_request_action method
*
@ -677,70 +686,30 @@ class ObjectTest extends CakeTestCase {
* @return void
*/
function testRequestAction() {
App::build(array(
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
));
$result = $this->object->requestAction('');
$this->assertFalse($result);
$result = $this->object->requestAction('/request_action/test_request_action');
$expected = 'This is a test';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'test_request_action'));
$expected = 'This is a test';
$this->assertEqual($result, $expected);
$this->assertEqual($result, $expected);;
$result = $this->object->requestAction('/request_action/another_ra_test/2/5');
$expected = 7;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'another_ra_test'), array('pass' => array('5', '7')));
$expected = 12;
$this->assertEqual($result, $expected);
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
));
App::objects('plugin', null, false);
Router::reload();
$result = $this->object->requestAction('/tests_apps/index', array('return'));
$expected = 'This is the TestsAppsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'index'), array('return'));
$expected = 'This is the TestsAppsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/tests_apps/some_method');
$expected = 5;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
$expected = 5;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
$expected = 'test plugin index';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return'));
$expected = 'test plugin index';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return'));
$expected = 'test plugin index';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/test_plugin/tests/some_method');
$expected = 25;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin'));
$expected = 25;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/request_action/paginate_request_action');
$this->assertTrue($result);
@ -748,20 +717,104 @@ class ObjectTest extends CakeTestCase {
$expected = 'Hello World';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'normal_request_action'));
$expected = 'Hello World';
App::build();
}
/**
* test requestAction() and plugins.
*
* @return void
*/
function testRequestActionPlugins() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
));
App::objects('plugin', null, false);
Router::reload();
$result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
$expected = 'test plugin index';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'paginate_request_action'));
$this->assertTrue($result);
$result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return'));
$expected = 'test plugin index';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'paginate_request_action'), array('pass' => array(5), 'named' => array('param' => 'value')));
$this->assertTrue($result);
$result = $this->object->requestAction(
array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return')
);
$expected = 'test plugin index';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/test_plugin/tests/some_method');
$expected = 25;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(
array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin')
);
$expected = 25;
$this->assertEqual($result, $expected);
App::build();
App::objects('plugin', null, false);
}
/**
* test requestAction() with arrays.
*
* @return void
*/
function testRequestActionArray() {
App::build(array(
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
));
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'test_request_action')
);
$expected = 'This is a test';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'another_ra_test'),
array('pass' => array('5', '7'))
);
$expected = 12;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(
array('controller' => 'tests_apps', 'action' => 'index'), array('return')
);
$expected = 'This is the TestsAppsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
$expected = 5;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'normal_request_action')
);
$expected = 'Hello World';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'paginate_request_action')
);
$this->assertTrue($result);
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'paginate_request_action'),
array('pass' => array(5), 'named' => array('param' => 'value'))
);
$this->assertTrue($result);
App::build();
}
/**
* Test that requestAction() is populating $this->params properly
*
@ -781,7 +834,10 @@ class ObjectTest extends CakeTestCase {
$expected = array('sort' => 'desc', 'limit' => 5,);
$this->assertEqual($result['named'], $expected);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'params_pass'), array('named' => array('sort' => 'desc', 'limit' => 5)));
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'params_pass'),
array('named' => array('sort' => 'desc', 'limit' => 5))
);
$this->assertEqual($result['named'], $expected);
}

View file

@ -1897,9 +1897,7 @@ class RouterTest extends CakeTestCase {
App::objects('plugin', null, false);
Router::reload();
$plugins = App::objects('plugin');
$plugin = Inflector::underscore($plugins[0]);
$result = Router::url(array('plugin' => $plugin, 'controller' => 'js_file', 'action' => 'index'));
$result = Router::url(array('plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index'));
$this->assertEqual($result, '/plugin_js/js_file');
$result = Router::parse('/plugin_js/js_file');
@ -1963,7 +1961,11 @@ class RouterTest extends CakeTestCase {
'action' => 'view',
'pass' => array(1),
'named' => array(),
'url' => array()
'url' => array(),
'autoRender' => 1,
'bare' => 1,
'return' => 1,
'requested' => 1
);
$result = Router::reverse($params);
$this->assertEqual($result, '/posts/view/1');
@ -2083,6 +2085,27 @@ class CakeRouteTest extends CakeTestCase {
$this->assertPattern($result, '/test_plugin/posts/edit/5/name:value/nick:name');
}
/**
* test route names with - in them.
*
* @return void
*/
function testHyphenNames() {
$route =& new CakeRoute('/articles/:date-from/:date-to', array(
'controller' => 'articles', 'action' => 'index'
));
$expected = array(
'controller' => 'articles',
'action' => 'index',
'date-from' => '2009-07-31',
'date-to' => '2010-07-31',
'named' => array(),
'pass' => array()
);
$result = $route->parse('/articles/2009-07-31/2010-07-31');
$this->assertEqual($result, $expected);
}
/**
* test that route parameters that overlap don't cause errors.
*
@ -2294,7 +2317,6 @@ class CakeRouteTest extends CakeTestCase {
$result = $route->match(array('plugin' => 'fo', 'controller' => 'posts', 'action' => 'edit', 'id' => 1));
$this->assertFalse($result);
$route =& new CakeRoute('/admin/subscriptions/:action/*', array(
'controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin'
));
@ -2303,6 +2325,20 @@ class CakeRouteTest extends CakeTestCase {
$result = $route->match($url);
$expected = '/admin/subscriptions/edit/1';
$this->assertEqual($result, $expected);
$route =& new CakeRoute('/articles/:date-from/:date-to', array(
'controller' => 'articles', 'action' => 'index'
));
$url = array(
'controller' => 'articles',
'action' => 'index',
'date-from' => '2009-07-31',
'date-to' => '2010-07-31'
);
$result = $route->match($url);
$expected = '/articles/2009-07-31/2010-07-31';
$this->assertEqual($result, $expected);
}
/**

View file

@ -200,6 +200,26 @@ class StringTest extends CakeTestCase {
$result = String::insert('?-pended result', array('Pre'));
$expected = "Pre-pended result";
$this->assertEqual($result, $expected);
$string = 'switching :timeout / :timeout_count';
$expected = 'switching 5 / 10';
$result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10));
$this->assertEqual($result, $expected);
$string = 'switching :timeout / :timeout_count';
$expected = 'switching 5 / 10';
$result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5));
$this->assertEqual($result, $expected);
$string = 'switching :timeout_count by :timeout';
$expected = 'switching 10 by 5';
$result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10));
$this->assertEqual($result, $expected);
$string = 'switching :timeout_count by :timeout';
$expected = 'switching 10 by 5';
$result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5));
$this->assertEqual($result, $expected);
}
/**

View file

@ -363,6 +363,42 @@ class CacheHelperTest extends CakeTestCase {
$this->assertFalse(file_exists($filename));
}
/**
* test with named and pass args.
*
* @return void
*/
function testCacheWithNamedAndPassedArgs() {
Router::reload();
$this->Controller->cache_parsing();
$this->Controller->params = array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'url' => array(),
'pass' => array(1, 2),
'named' => array(
'name' => 'mark',
'ice' => 'cream'
)
);
$this->Controller->cacheAction = array(
'cache_parsing' => 21600
);
$this->Controller->here = '/cache_test/cache_parsing/1/2/name:mark/ice:cream';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNoPattern('/cake:nocache/', $result);
$this->assertNoPattern('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing_1_2_name_mark_ice_cream.php';
$this->assertTrue(file_exists($filename));
@unlink($filename);
}
/**
* test that custom routes are respected when generating cache files.
*

View file

@ -4225,6 +4225,25 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', null, array('empty' => false));
}
/**
* test that datetime() and default values work.
*
* @return void
*/
function testDatetimeWithDefault() {
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', null, array('value' => '2009-06-01 11:15:30'));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', null, array(
'default' => '2009-06-01 11:15:30'
));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
}
/**
* testFormDateTimeMulti method
*

View file

@ -585,12 +585,24 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->script('test.json');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('test.json.js?foo=bar');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('foo');
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');

View file

@ -517,6 +517,40 @@ class RssHelperTest extends CakeTestCase {
'/item'
);
$this->assertTags($result, $expected);
$item = array(
'title' => 'Foo bar',
'link' => array(
'url' => 'http://example.com/foo?a=1&b=2',
'convertEntities' => false
),
'description' => array(
'value' => 'descriptive words',
'cdata' => true,
),
'pubDate' => '2008-05-31 12:00:00'
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'Foo bar',
'/title',
'<link',
'http://example.com/foo?a=1&amp;b=2',
'/link',
'<description',
'<![CDATA[descriptive words]]',
'/description',
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
'/pubDate',
'<guid',
'http://example.com/foo?a=1&amp;b=2',
'/guid',
'/item'
);
$this->assertTags($result, $expected);
}
/**

View file

@ -88,6 +88,11 @@ class CakeTestFixture {
$model->table = $import['table'];
$model->tablePrefix = $db->config['prefix'];
$this->fields = $model->schema(true);
ClassRegistry::flush();
}
if (!empty($db->config['prefix']) && strpos($this->table, $db->config['prefix']) === 0) {
$this->table = str_replace($db->config['prefix'], '', $this->table);
}
if (isset($import['records']) && $import['records'] !== false && isset($model) && isset($db)) {