mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge branch '1.3' into 1.3-newlines
This commit is contained in:
commit
766e12bc2a
25 changed files with 13692 additions and 146 deletions
|
@ -70,7 +70,7 @@ class ApiShell extends Shell {
|
|||
return $this->help();
|
||||
}
|
||||
|
||||
$type = low($this->args[0]);
|
||||
$type = strtolower($this->args[0]);
|
||||
|
||||
if (isset($this->paths[$type])) {
|
||||
$path = $this->paths[$type];
|
||||
|
@ -206,7 +206,7 @@ class ApiShell extends Shell {
|
|||
|
||||
if (strpos($method, '__') === false && $method[0] != '_') {
|
||||
$parsed[$method] = array(
|
||||
'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
|
||||
'comment' => str_replace(array('/*', '*/', '*'), '', trim($result[1][$key])),
|
||||
'method' => $method,
|
||||
'parameters' => trim($result[3][$key])
|
||||
);
|
||||
|
|
|
@ -165,10 +165,10 @@ class Shell extends Object {
|
|||
ClassRegistry::map($this->name, $this->alias);
|
||||
|
||||
if (!PHP5 && isset($this->args[0])) {
|
||||
if (strpos($this->name, low(Inflector::camelize($this->args[0]))) !== false) {
|
||||
if (strpos($this->name, strtolower(Inflector::camelize($this->args[0]))) !== false) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
if (low($this->command) == low(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
if (strtolower($this->command) == strtolower(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
|
||||
$dispatch->shiftArgs();
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ class Shell extends Object {
|
|||
}
|
||||
}
|
||||
if (is_array($options)) {
|
||||
while ($in == '' || ($in && (!in_array(low($in), $options) && !in_array(up($in), $options)) && !in_array($in, $options))) {
|
||||
while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
|
||||
$in = $this->Dispatch->getInput($prompt, $options, $default);
|
||||
}
|
||||
}
|
||||
|
@ -457,10 +457,10 @@ class Shell extends Object {
|
|||
$this->out("\n" . sprintf(__("Creating file %s", true), $path));
|
||||
if (is_file($path) && $this->interactive === true) {
|
||||
$key = $this->in(__("File exists, overwrite?", true). " {$path}", array('y', 'n', 'q'), 'n');
|
||||
if (low($key) == 'q') {
|
||||
if (strtolower($key) == 'q') {
|
||||
$this->out(__("Quitting.", true) ."\n");
|
||||
exit;
|
||||
} elseif (low($key) != 'y') {
|
||||
} elseif (strtolower($key) != 'y') {
|
||||
$this->out(__("Skip", true) ." {$path}\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ class Shell extends Object {
|
|||
return true;
|
||||
}
|
||||
$unitTest = $this->in('SimpleTest is not installed. Do you want to bake unit test files anyway?', array('y','n'), 'y');
|
||||
$result = low($unitTest) == 'y' || low($unitTest) == 'yes';
|
||||
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';
|
||||
|
||||
if ($result) {
|
||||
$this->out("\nYou can download SimpleTest from http://simpletest.org", true);
|
||||
|
@ -521,8 +521,8 @@ class Shell extends Object {
|
|||
*/
|
||||
function shortPath($file) {
|
||||
$shortPath = str_replace(ROOT, null, $file);
|
||||
$shortPath = str_replace('..'.DS, '', $shortPath);
|
||||
return r(DS.DS, DS, $shortPath);
|
||||
$shortPath = str_replace('..' . DS, '', $shortPath);
|
||||
return str_replace(DS . DS, DS, $shortPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -533,7 +533,7 @@ class Shell extends Object {
|
|||
* @access protected
|
||||
*/
|
||||
function _controllerPath($name) {
|
||||
return low(Inflector::underscore($name));
|
||||
return strtolower(Inflector::underscore($name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -530,7 +530,7 @@ class CakeSession extends Object {
|
|||
case 'cache':
|
||||
if (empty($_SESSION)) {
|
||||
if (!class_exists('Cache')) {
|
||||
uses('Cache');
|
||||
require LIBS . 'cache.php';
|
||||
}
|
||||
if ($iniSet) {
|
||||
ini_set('session.use_trans_sid', 0);
|
||||
|
|
|
@ -98,19 +98,15 @@ class Configure extends Object {
|
|||
$config = array($config => $value);
|
||||
}
|
||||
|
||||
foreach ($config as $names => $value) {
|
||||
$name = $_this->__configVarNames($names);
|
||||
|
||||
switch (count($name)) {
|
||||
case 3:
|
||||
$_this->{$name[0]}[$name[1]][$name[2]] = $value;
|
||||
break;
|
||||
case 2:
|
||||
$_this->{$name[0]}[$name[1]] = $value;
|
||||
break;
|
||||
case 1:
|
||||
$_this->{$name[0]} = $value;
|
||||
break;
|
||||
foreach ($config as $name => $value) {
|
||||
if (strpos($name, '.') === false) {
|
||||
$_this->{$name} = $value;
|
||||
} else {
|
||||
$names = explode('.', $name, 2);
|
||||
if (!isset($_this->{$names[0]})) {
|
||||
$_this->{$names[0]} = array();
|
||||
}
|
||||
$_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,26 +157,20 @@ class Configure extends Object {
|
|||
}
|
||||
return $_this->debug;
|
||||
}
|
||||
$name = $_this->__configVarNames($var);
|
||||
|
||||
switch (count($name)) {
|
||||
case 3:
|
||||
if (isset($_this->{$name[0]}[$name[1]][$name[2]])) {
|
||||
return $_this->{$name[0]}[$name[1]][$name[2]];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (isset($_this->{$name[0]}[$name[1]])) {
|
||||
return $_this->{$name[0]}[$name[1]];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (isset($_this->{$name[0]})) {
|
||||
return $_this->{$name[0]};
|
||||
}
|
||||
break;
|
||||
if (strpos($var, '.') !== false) {
|
||||
$names = explode('.', $var, 2);
|
||||
$var = $names[0];
|
||||
}
|
||||
return null;
|
||||
if (!isset($_this->{$var})) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($names[1])) {
|
||||
return Set::extract($_this->{$var}, $names[1]);
|
||||
}
|
||||
|
||||
return $_this->{$var};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,13 +187,14 @@ class Configure extends Object {
|
|||
*/
|
||||
function delete($var = null) {
|
||||
$_this =& Configure::getInstance();
|
||||
$name = $_this->__configVarNames($var);
|
||||
|
||||
if (count($name) > 1) {
|
||||
unset($_this->{$name[0]}[$name[1]]);
|
||||
} else {
|
||||
unset($_this->{$name[0]});
|
||||
if (strpos($var, '.') === false) {
|
||||
unset($_this->{$var});
|
||||
return;
|
||||
}
|
||||
|
||||
$names = explode('.', $var, 2);
|
||||
$_this->{$names[0]} = Set::remove($_this->{$names[0]}, $names[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -345,23 +336,6 @@ class Configure extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
|
||||
*
|
||||
* @param mixed $name Name to split
|
||||
* @return array Name separated in items through dot notation
|
||||
* @access private
|
||||
*/
|
||||
function __configVarNames($name) {
|
||||
if (is_string($name)) {
|
||||
if (strpos($name, ".")) {
|
||||
return explode(".", $name);
|
||||
}
|
||||
return array($name);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::objects()
|
||||
|
@ -445,10 +419,14 @@ class Configure extends Object {
|
|||
}
|
||||
Cache::config('default');
|
||||
}
|
||||
App::build(compact(
|
||||
'models', 'views', 'controllers', 'helpers', 'components',
|
||||
'behaviors', 'plugins', 'vendors', 'locales', 'shells'
|
||||
));
|
||||
if (App::path('controllers') == array()) {
|
||||
App::build(array(
|
||||
'models' => $modelPaths, 'views' => $viewPaths, 'controllers' => $controllerPaths,
|
||||
'helpers' => $helperPaths, 'components' => $componentPaths, 'behaviors' => $behaviorPaths,
|
||||
'plugins' => $pluginPaths, 'vendors' => $vendorPaths, 'locales' => $localePaths,
|
||||
'shells' => $shellPaths
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1209,19 +1187,6 @@ class App extends Object {
|
|||
if ($paths = App::path($type .'s')) {
|
||||
return $paths;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'plugin':
|
||||
return array(APP . 'plugins' . DS);
|
||||
case 'vendor':
|
||||
return array(APP . 'vendors' . DS, VENDORS, APP . 'plugins' . DS);
|
||||
case 'controller':
|
||||
return array(APP . 'controllers' . DS, APP);
|
||||
case 'model':
|
||||
return array(APP . 'models' . DS, APP);
|
||||
case 'view':
|
||||
return array(APP . 'views' . DS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -130,13 +130,15 @@ class Debugger extends Object {
|
|||
define('E_DEPRECATED', 8192);
|
||||
}
|
||||
|
||||
$e = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-trace\')';
|
||||
$e = '<pre class="cake-debug">';
|
||||
$e .= '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-trace\')';
|
||||
$e .= '.style.display = (document.getElementById(\'{:id}-trace\').style.display == ';
|
||||
$e .= '\'none\' ? \'\' : \'none\');"><b>{:error}</b> ({:code})</a>: {:description} ';
|
||||
$e .= '[<b>{:path}</b>, line <b>{:line}</b>]';
|
||||
|
||||
$e .= '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
|
||||
$e .= '{:links}{:info}</div>';
|
||||
$e .= '</pre>';
|
||||
$this->_templates['js']['error'] = $e;
|
||||
|
||||
$t = '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
|
||||
|
@ -164,7 +166,7 @@ class Debugger extends Object {
|
|||
$this->_templates['js']['code'] .= 'style="display: none;"><pre>{:code}</pre></div>';
|
||||
|
||||
|
||||
$e = '<pre class="cake-debug"><b>{:error}</b> ({:code}) : {:description} ';
|
||||
$e = '<pre class="cake-debug"><b>{:error}</b> ({:code}) : {:description} ';
|
||||
$e .= '[<b>{:path}</b>, line <b>{:line}]</b></pre>';
|
||||
$this->_templates['html']['error'] = $e;
|
||||
|
||||
|
@ -425,7 +427,7 @@ class Debugger extends Object {
|
|||
} elseif (strpos($path, ROOT) === 0) {
|
||||
return str_replace(ROOT, 'ROOT', $path);
|
||||
}
|
||||
$corePaths = App::core('cake');
|
||||
$corePaths = Configure::corePaths('cake');
|
||||
foreach ($corePaths as $corePath) {
|
||||
if (strpos($path, $corePath) === 0) {
|
||||
return str_replace($corePath, 'CORE' .DS . 'cake' .DS, $path);
|
||||
|
|
|
@ -999,11 +999,11 @@ class DboOracle extends DboSource {
|
|||
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
|
||||
if (!isset($resultSet) || !is_array($resultSet)) {
|
||||
if (Configure::read() > 0) {
|
||||
e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ');
|
||||
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ';
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
e($this->error);
|
||||
echo $this->error;
|
||||
}
|
||||
e('</div>');
|
||||
echo '</div>';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -772,11 +772,11 @@ class DboSource extends DataSource {
|
|||
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
|
||||
if (!isset($resultSet) || !is_array($resultSet)) {
|
||||
if (Configure::read() > 0) {
|
||||
e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ');
|
||||
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ';
|
||||
if (isset($this->error) && $this->error != null) {
|
||||
e($this->error);
|
||||
echo $this->error;
|
||||
}
|
||||
e('</div>');
|
||||
echo '</div>';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1399,7 +1399,7 @@ class Model extends Overloadable {
|
|||
unset($values);
|
||||
} elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||
$newData[] = $row;
|
||||
} elseif (isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||
} elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
|
||||
$newData[] = $row[$join];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -996,7 +996,7 @@ class AjaxHelper extends AppHelper {
|
|||
$keys = array_keys($this->__ajaxBuffer);
|
||||
|
||||
if (count($divs) == 1 && in_array($divs[0], $keys)) {
|
||||
e($this->__ajaxBuffer[$divs[0]]);
|
||||
echo $this->__ajaxBuffer[$divs[0]];
|
||||
} else {
|
||||
foreach ($this->__ajaxBuffer as $key => $val) {
|
||||
if (in_array($key, $divs)) {
|
||||
|
@ -1007,14 +1007,13 @@ class AjaxHelper extends AppHelper {
|
|||
$out .= 'for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == "string"';
|
||||
$out .= ' && $(n)) Element.update($(n), unescape(decodeURIComponent(';
|
||||
$out .= '__ajaxUpdater__[n]))); }';
|
||||
e($this->Javascript->codeBlock($out, false));
|
||||
echo $this->Javascript->codeBlock($out, false);
|
||||
}
|
||||
$scripts = $this->Javascript->getCache();
|
||||
|
||||
if (!empty($scripts)) {
|
||||
e($this->Javascript->codeBlock($scripts, false));
|
||||
echo $this->Javascript->codeBlock($scripts, false);
|
||||
}
|
||||
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,8 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
if (!class_exists('cakesession')) {
|
||||
uses('session');
|
||||
require LIBS . 'cake_session.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Session Helper.
|
||||
*
|
||||
|
|
|
@ -325,34 +325,11 @@ class TextHelper extends AppHelper {
|
|||
$c = count($list) - 1;
|
||||
foreach ($list as $i => $item) {
|
||||
$r .= $item;
|
||||
if ($c > 0 && $i < $c)
|
||||
{
|
||||
if ($c > 0 && $i < $c) {
|
||||
$r .= ($i < $c - 1 ? ', ' : " {$and} ");
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax.
|
||||
*
|
||||
* @param string $text String to "flay"
|
||||
* @param boolean $allowHtml Set to true if if html is allowed
|
||||
* @return string "Flayed" text
|
||||
* @access public
|
||||
* @todo Change this. We need a real Textile parser.
|
||||
* @codeCoverageIgnoreStart
|
||||
*/
|
||||
function flay($text, $allowHtml = false) {
|
||||
trigger_error(__('(TextHelper::flay) Deprecated: the Flay library is no longer supported and will be removed in a future version.', true), E_USER_WARNING);
|
||||
if (!class_exists('Flay')) {
|
||||
uses('flay');
|
||||
}
|
||||
return Flay::toHtml($text, false, $allowHtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnoreEnd
|
||||
*/
|
||||
}
|
||||
?>
|
|
@ -503,7 +503,7 @@ class TimeHelper extends AppHelper {
|
|||
* @return bool
|
||||
*/
|
||||
function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
|
||||
$tmp = r(' ', '', $timeInterval);
|
||||
$tmp = str_replace(' ', '', $timeInterval);
|
||||
if (is_numeric($tmp)) {
|
||||
$timeInterval = $tmp . ' ' . __('days', true);
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<?php e($xml->header()); ?>
|
||||
<?php echo $xml->header(); ?>
|
||||
<?php echo $content_for_layout; ?>
|
|
@ -2,9 +2,7 @@
|
|||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* TestTaskTest file
|
||||
*
|
||||
* Test Case for test generation shell task
|
||||
* ApiShellTest file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
|
@ -52,12 +50,12 @@ Mock::generatePartial(
|
|||
);
|
||||
|
||||
/**
|
||||
* TestTaskTest class
|
||||
* ApiShellTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskTest extends CakeTestCase {
|
||||
class ApiShellTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
|
|
|
@ -241,6 +241,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$this->Case->before('start');
|
||||
$this->expectError();
|
||||
$this->Case->loadFixtures('Wrong!');
|
||||
$this->Case->end();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -283,6 +284,10 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$result = $this->Case->testAction('/tests_apps/set_action', array('return' => 'vars'));
|
||||
$this->assertEqual($result, array('var' => 'string'));
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$fixture =& new PostFixture();
|
||||
$fixture->create($db);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
|
||||
$this->assertTrue(array_key_exists('posts', $result));
|
||||
$this->assertEqual(count($result['posts']), 1);
|
||||
|
@ -324,7 +329,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
)
|
||||
));
|
||||
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
|
||||
|
||||
$fixture->drop($db);
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$_backPrefix = $db->config['prefix'];
|
||||
|
@ -334,11 +339,11 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$config['prefix'] = 'cake_testcase_test_';
|
||||
|
||||
ConnectionManager::create('cake_test_case', $config);
|
||||
$db =& ConnectionManager::getDataSource('cake_test_case');
|
||||
$db2 =& ConnectionManager::getDataSource('cake_test_case');
|
||||
|
||||
$fixture =& new PostFixture($db);
|
||||
$fixture->create($db);
|
||||
$fixture->insert($db);
|
||||
$fixture =& new PostFixture($db2);
|
||||
$fixture->create($db2);
|
||||
$fixture->insert($db2);
|
||||
|
||||
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
|
||||
'return' => 'vars',
|
||||
|
@ -347,15 +352,12 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
));
|
||||
$this->assertTrue(isset($result['posts']));
|
||||
$this->assertEqual(count($result['posts']), 3);
|
||||
$tables = $db->listSources(true);
|
||||
$tables = $db2->listSources();
|
||||
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));
|
||||
|
||||
$fixture->drop($db);
|
||||
$fixture->drop($db2);
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$db->config['prefix'] = $_backPrefix;
|
||||
$fixture->drop($db);
|
||||
|
||||
|
||||
//test that drop tables behaves as exepected with testAction
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
|
|
|
@ -121,6 +121,23 @@ class ConfigureTest extends CakeTestCase {
|
|||
Configure::write('SomeName.someKey', null);
|
||||
$result = Configure::read('SomeName.someKey');
|
||||
$this->assertEqual($result, null);
|
||||
|
||||
$expected = array('One' => array('Two' => array('Three' => array('Four' => array('Five' => 'cool')))));
|
||||
Configure::write('Key', $expected);
|
||||
|
||||
$result = Configure::read('Key');
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
$result = Configure::read('Key.One');
|
||||
$this->assertEqual($expected['One'], $result);
|
||||
|
||||
|
||||
$result = Configure::read('Key.One.Two');
|
||||
$this->assertEqual($expected['One']['Two'], $result);
|
||||
|
||||
$result = Configure::read('Key.One.Two.Three.Four.Five');
|
||||
$this->assertEqual('cool', $result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,8 +99,8 @@ class DebuggerTest extends CakeTestCase {
|
|||
$this->assertTrue(is_array($result));
|
||||
$this->assertEqual(count($result), 4);
|
||||
|
||||
$expected = '<code><span style="color: #000000"><span style="color: #0000BB"><?php';
|
||||
$expected .= '</span></span></code>';
|
||||
$expected = '<code><span style="color: #000000"><?php';
|
||||
$expected .= '</span></code>';
|
||||
$this->assertEqual($result[0], $expected);
|
||||
|
||||
$return = Debugger::excerpt('[internal]', 2, 2);
|
||||
|
@ -148,13 +148,14 @@ class DebuggerTest extends CakeTestCase {
|
|||
$buzz .= '';
|
||||
$result = explode('</a>', ob_get_clean());
|
||||
$this->assertTags($result[0], array(
|
||||
'pre' => array('class' => 'cake-debug'),
|
||||
'a' => array(
|
||||
'href' => "javascript:void(0);",
|
||||
'onclick' => "document.getElementById('cakeErr4-trace').style.display = " .
|
||||
"(document.getElementById('cakeErr4-trace').style.display == 'none'" .
|
||||
" ? '' : 'none');"
|
||||
),
|
||||
'b' => array(), 'Notice', '/b', ' (8)'
|
||||
'b' => array(), 'Notice', '/b', ' (8)',
|
||||
));
|
||||
|
||||
$this->assertPattern('/Undefined variable: buzz/', $result[1]);
|
||||
|
|
571
cake/tests/cases/libs/model/model_delete.test.php
Normal file
571
cake/tests/cases/libs/model/model_delete.test.php
Normal file
|
@ -0,0 +1,571 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
|
||||
/**
|
||||
* ModelDeleteTest file
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @version $Revision: 8225 $
|
||||
* @modifiedby $LastChangedBy: mark_story $
|
||||
* @lastmodified $Date: 2009-07-07 23:25:30 -0400 (Tue, 07 Jul 2009) $
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
require_once dirname(__FILE__) . DS . 'model.test.php';
|
||||
require_once dirname(__FILE__) . DS . 'model_delete.test.php';
|
||||
/**
|
||||
* ModelDeleteTest
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model.operations
|
||||
*/
|
||||
class ModelDeleteTest extends BaseModelTest {
|
||||
/**
|
||||
* testDeleteHabtmReferenceWithConditions method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteHabtmReferenceWithConditions() {
|
||||
$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio');
|
||||
|
||||
$Portfolio =& new Portfolio();
|
||||
$Portfolio->hasAndBelongsToMany['Item']['conditions'] = array('ItemsPortfolio.item_id >' => 1);
|
||||
|
||||
$result = $Portfolio->find('first', array(
|
||||
'conditions' => array('Portfolio.id' => 1)
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 3,
|
||||
'syfile_id' => 3,
|
||||
'published' => 0,
|
||||
'name' => 'Item 3',
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 3,
|
||||
'item_id' => 3,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'id' => 4,
|
||||
'syfile_id' => 4,
|
||||
'published' => 0,
|
||||
'name' => 'Item 4',
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 4,
|
||||
'item_id' => 4,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'id' => 5,
|
||||
'syfile_id' => 5,
|
||||
'published' => 0,
|
||||
'name' => 'Item 5',
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 5,
|
||||
'item_id' => 5,
|
||||
'portfolio_id' => 1
|
||||
)));
|
||||
$this->assertEqual($result['Item'], $expected);
|
||||
|
||||
$result = $Portfolio->ItemsPortfolio->find('all', array(
|
||||
'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 1,
|
||||
'item_id' => 1,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 3,
|
||||
'item_id' => 3,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 4,
|
||||
'item_id' => 4,
|
||||
'portfolio_id' => 1
|
||||
)),
|
||||
array(
|
||||
'ItemsPortfolio' => array(
|
||||
'id' => 5,
|
||||
'item_id' => 5,
|
||||
'portfolio_id' => 1
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$Portfolio->delete(1);
|
||||
|
||||
$result = $Portfolio->find('first', array(
|
||||
'conditions' => array('Portfolio.id' => 1)
|
||||
));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $Portfolio->ItemsPortfolio->find('all', array(
|
||||
'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
|
||||
));
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
/**
|
||||
* testDeleteArticleBLinks method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteArticleBLinks() {
|
||||
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
||||
$TestModel =& new ArticleB();
|
||||
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
|
||||
array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDeleteDependentWithConditions method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteDependentWithConditions() {
|
||||
$this->loadFixtures('Cd','Book','OverallFavorite');
|
||||
|
||||
$Cd =& new Cd();
|
||||
$OverallFavorite =& new OverallFavorite();
|
||||
|
||||
$Cd->del(1);
|
||||
|
||||
$result = $OverallFavorite->find('all', array(
|
||||
'fields' => array('model_type', 'model_id', 'priority')
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'OverallFavorite' => array(
|
||||
'model_type' => 'Book',
|
||||
'model_id' => 1,
|
||||
'priority' => 2
|
||||
)));
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDel() {
|
||||
$this->loadFixtures('Article');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$result = $TestModel->del(2);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $TestModel->read(null, 2);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'title')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'title' => 'First Article'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'title' => 'Third Article'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->del(3);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $TestModel->read(null, 3);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'title')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'title' => 'First Article'
|
||||
)));
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
// make sure deleting a non-existent record doesn't break save()
|
||||
// ticket #6293
|
||||
$this->loadFixtures('Uuid');
|
||||
$Uuid =& new Uuid();
|
||||
$data = array(
|
||||
'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3',
|
||||
'52C8865C-10EE-4302-AE6C-6E7D8E12E2C8',
|
||||
'8208C7FE-E89C-47C5-B378-DED6C271F9B8');
|
||||
foreach ($data as $id) {
|
||||
$Uuid->save(array('id' => $id));
|
||||
}
|
||||
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
|
||||
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
|
||||
foreach ($data as $id) {
|
||||
$Uuid->save(array('id' => $id));
|
||||
}
|
||||
$result = $Uuid->find('all', array(
|
||||
'conditions' => array('id' => $data),
|
||||
'fields' => array('id'),
|
||||
'order' => 'id'));
|
||||
$expected = array(
|
||||
array('Uuid' => array(
|
||||
'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')),
|
||||
array('Uuid' => array(
|
||||
'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')),
|
||||
array('Uuid' => array(
|
||||
'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3')));
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDeleteAll method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteAll() {
|
||||
$this->loadFixtures('Article');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$data = array('Article' => array(
|
||||
'user_id' => 2,
|
||||
'id' => 4,
|
||||
'title' => 'Fourth Article',
|
||||
'published' => 'N'
|
||||
));
|
||||
$result = $TestModel->set($data) && $TestModel->save();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$data = array('Article' => array(
|
||||
'user_id' => 2,
|
||||
'id' => 5,
|
||||
'title' => 'Fifth Article',
|
||||
'published' => 'Y'
|
||||
));
|
||||
$result = $TestModel->set($data) && $TestModel->save();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$data = array('Article' => array(
|
||||
'user_id' => 1,
|
||||
'id' => 6,
|
||||
'title' => 'Sixth Article',
|
||||
'published' => 'N'
|
||||
));
|
||||
$result = $TestModel->set($data) && $TestModel->save();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'user_id', 'title', 'published')
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 2,
|
||||
'user_id' => 3,
|
||||
'title' => 'Second Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'user_id' => 1,
|
||||
'title' => 'Third Article',
|
||||
'published' => 'Y')),
|
||||
array('Article' => array(
|
||||
'id' => 4,
|
||||
'user_id' => 2,
|
||||
'title' => 'Fourth Article',
|
||||
'published' => 'N'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 5,
|
||||
'user_id' => 2,
|
||||
'title' => 'Fifth Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 6,
|
||||
'user_id' => 1,
|
||||
'title' => 'Sixth Article',
|
||||
'published' => 'N'
|
||||
)));
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.published' => 'N'));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'user_id', 'title', 'published')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 2,
|
||||
'user_id' => 3,
|
||||
'title' => 'Second Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'user_id' => 1,
|
||||
'title' => 'Third Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 5,
|
||||
'user_id' => 2,
|
||||
'title' => 'Fifth Article',
|
||||
'published' => 'Y'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array('Article.user_id' => array(2, 3));
|
||||
$result = $TestModel->deleteAll($data, true, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = -1;
|
||||
$result = $TestModel->find('all', array(
|
||||
'fields' => array('id', 'user_id', 'title', 'published')
|
||||
));
|
||||
$expected = array(
|
||||
array('Article' => array(
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
'published' => 'Y'
|
||||
)),
|
||||
array('Article' => array(
|
||||
'id' => 3,
|
||||
'user_id' => 1,
|
||||
'title' => 'Third Article',
|
||||
'published' => 'Y'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
|
||||
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||
}
|
||||
/**
|
||||
* testRecursiveDel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRecursiveDel() {
|
||||
$this->loadFixtures('Article', 'Comment', 'Attachment');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$result = $TestModel->del(2);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$TestModel->recursive = 2;
|
||||
$result = $TestModel->read(null, 2);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->Comment->read(null, 5);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->Comment->read(null, 6);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->Comment->Attachment->read(null, 1);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $TestModel->find('count');
|
||||
$this->assertEqual($result, 2);
|
||||
|
||||
$result = $TestModel->Comment->find('count');
|
||||
$this->assertEqual($result, 4);
|
||||
|
||||
$result = $TestModel->Comment->Attachment->find('count');
|
||||
$this->assertEqual($result, 0);
|
||||
}
|
||||
/**
|
||||
* testDependentExclusiveDelete method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDependentExclusiveDelete() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
$TestModel =& new Article10();
|
||||
|
||||
$result = $TestModel->find('all');
|
||||
$this->assertEqual(count($result[0]['Comment']), 4);
|
||||
$this->assertEqual(count($result[1]['Comment']), 2);
|
||||
$this->assertEqual($TestModel->Comment->find('count'), 6);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$this->assertEqual($TestModel->Comment->find('count'), 2);
|
||||
}
|
||||
/**
|
||||
* testDeleteLinks method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteLinks() {
|
||||
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
||||
$TestModel =& new Article();
|
||||
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '1',
|
||||
'tag_id' => '1'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '1',
|
||||
'tag_id' => '2'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '1'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '3'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$TestModel->delete(1);
|
||||
$result = $TestModel->ArticlesTag->find('all');
|
||||
|
||||
$expected = array(
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '1'
|
||||
)),
|
||||
array('ArticlesTag' => array(
|
||||
'article_id' => '2',
|
||||
'tag_id' => '3'
|
||||
)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
|
||||
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||
}
|
||||
/**
|
||||
* testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() {
|
||||
|
||||
$this->loadFixtures('Apple', 'Device', 'ThePaperMonkies');
|
||||
$ThePaper =& new ThePaper();
|
||||
$ThePaper->id = 1;
|
||||
$ThePaper->save(array('Monkey' => array(2, 3)));
|
||||
|
||||
$result = $ThePaper->findById(1);
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 2',
|
||||
'typ' => '1'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 3',
|
||||
'typ' => '2'
|
||||
));
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
|
||||
$ThePaper =& new ThePaper();
|
||||
$ThePaper->id = 2;
|
||||
$ThePaper->save(array('Monkey' => array(2, 3)));
|
||||
|
||||
$result = $ThePaper->findById(2);
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 2',
|
||||
'typ' => '1'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 3',
|
||||
'typ' => '2'
|
||||
));
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
|
||||
$ThePaper->delete(1);
|
||||
$result = $ThePaper->findById(2);
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 2',
|
||||
'typ' => '1'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
'device_type_id' => '1',
|
||||
'name' => 'Device 3',
|
||||
'typ' => '2'
|
||||
));
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
1837
cake/tests/cases/libs/model/model_integration.test.php
Normal file
1837
cake/tests/cases/libs/model/model_integration.test.php
Normal file
File diff suppressed because it is too large
Load diff
7151
cake/tests/cases/libs/model/model_read.test.php
Normal file
7151
cake/tests/cases/libs/model/model_read.test.php
Normal file
File diff suppressed because it is too large
Load diff
126
cake/tests/cases/libs/model/model_validation.test.php
Normal file
126
cake/tests/cases/libs/model/model_validation.test.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
|
||||
/**
|
||||
* ModelValidationTest file
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @version $Revision: 8225 $
|
||||
* @modifiedby $LastChangedBy: mark_story $
|
||||
* @lastmodified $Date: 2009-07-07 23:25:30 -0400 (Tue, 07 Jul 2009) $
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
require_once dirname(__FILE__) . DS . 'model.test.php';
|
||||
require_once dirname(__FILE__) . DS . 'model_validation.test.php';
|
||||
/**
|
||||
* ModelValidationTest
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model.operations
|
||||
*/
|
||||
class ModelValidationTest extends BaseModelTest {
|
||||
/**
|
||||
* Tests validation parameter order in custom validation methods
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testValidationParams() {
|
||||
$TestModel =& new ValidationTest1();
|
||||
$TestModel->validate['title'] = array(
|
||||
'rule' => 'customValidatorWithParams',
|
||||
'required' => true
|
||||
);
|
||||
$TestModel->create(array('title' => 'foo'));
|
||||
$TestModel->invalidFields();
|
||||
|
||||
$expected = array(
|
||||
'data' => array(
|
||||
'title' => 'foo'
|
||||
),
|
||||
'validator' => array(
|
||||
'rule' => 'customValidatorWithParams',
|
||||
'on' => null,
|
||||
'last' => false,
|
||||
'allowEmpty' => false,
|
||||
'required' => true
|
||||
),
|
||||
'or' => true,
|
||||
'ignore_on_same' => 'id'
|
||||
);
|
||||
$this->assertEqual($TestModel->validatorParams, $expected);
|
||||
|
||||
$TestModel->validate['title'] = array(
|
||||
'rule' => 'customValidatorWithMessage',
|
||||
'required' => true
|
||||
);
|
||||
$expected = array(
|
||||
'title' => 'This field will *never* validate! Muhahaha!'
|
||||
);
|
||||
|
||||
$this->assertEqual($TestModel->invalidFields(), $expected);
|
||||
}
|
||||
/**
|
||||
* Tests validation parameter fieldList in invalidFields
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testInvalidFieldsWithFieldListParams() {
|
||||
$TestModel =& new ValidationTest1();
|
||||
$TestModel->validate = $validate = array(
|
||||
'title' => array(
|
||||
'rule' => 'customValidator',
|
||||
'required' => true
|
||||
),
|
||||
'name' => array(
|
||||
'rule' => 'allowEmpty',
|
||||
'required' => true
|
||||
));
|
||||
$TestModel->invalidFields(array('fieldList' => array('title')));
|
||||
$expected = array(
|
||||
'title' => 'This field cannot be left blank'
|
||||
);
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$TestModel->invalidFields(array('fieldList' => array('name')));
|
||||
$expected = array(
|
||||
'name' => 'This field cannot be left blank'
|
||||
);
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$TestModel->invalidFields(array('fieldList' => array('name', 'title')));
|
||||
$expected = array(
|
||||
'name' => 'This field cannot be left blank',
|
||||
'title' => 'This field cannot be left blank'
|
||||
);
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$TestModel->whitelist = array('name');
|
||||
$TestModel->invalidFields();
|
||||
$expected = array('name' => 'This field cannot be left blank');
|
||||
$this->assertEqual($TestModel->validationErrors, $expected);
|
||||
$TestModel->validationErrors = array();
|
||||
|
||||
$this->assertEqual($TestModel->validate, $validate);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
3894
cake/tests/cases/libs/model/model_write.test.php
Normal file
3894
cake/tests/cases/libs/model/model_write.test.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -448,10 +448,11 @@ class CakeTestCase extends UnitTestCase {
|
|||
return;
|
||||
}
|
||||
foreach ($this->_fixtures as $fixture) {
|
||||
if (in_array($fixture->table, $sources)) {
|
||||
$table = $this->db->config['prefix'] . $fixture->table;
|
||||
if (in_array($table, $sources)) {
|
||||
$fixture->drop($this->db);
|
||||
$fixture->create($this->db);
|
||||
} elseif (!in_array($fixture->table, $sources)) {
|
||||
} elseif (!in_array($table, $sources)) {
|
||||
$fixture->create($this->db);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,12 @@
|
|||
*/
|
||||
class CakeTestFixture extends Object {
|
||||
|
||||
/**
|
||||
* Name of the object
|
||||
*
|
||||
* @var string
|
||||
**/
|
||||
var $name = null;
|
||||
/**
|
||||
* Cake's DBO driver (e.g: DboMysql).
|
||||
*
|
||||
|
@ -47,7 +53,6 @@ class CakeTestFixture extends Object {
|
|||
* @access public
|
||||
*/
|
||||
var $table = null;
|
||||
|
||||
/**
|
||||
* Instantiate the fixture.
|
||||
*
|
||||
|
|
|
@ -34,7 +34,8 @@ class TestsAppsPostsController extends AppController {
|
|||
$data = array(
|
||||
'Post' => array(
|
||||
'title' => 'Test article',
|
||||
'body' => 'Body of article.'
|
||||
'body' => 'Body of article.',
|
||||
'author_id' => 1
|
||||
)
|
||||
);
|
||||
$this->Post->save($data);
|
||||
|
|
Loading…
Reference in a new issue