mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Merge branch '1.3' into integration
Conflicts: cake/libs/model/cake_schema.php cake/libs/model/datasources/dbo_source.php cake/libs/model/model.php cake/libs/view/helpers/form.php cake/libs/view/view.php cake/libs/xml.php cake/tests/cases/libs/model/model_delete.test.php cake/tests/cases/libs/view/view.test.php cake/tests/cases/libs/xml.test.php
This commit is contained in:
commit
f19e3d501c
25 changed files with 929 additions and 430 deletions
|
@ -21,7 +21,8 @@ App::import('Component', 'Acl');
|
||||||
App::import('Model', 'DbAcl');
|
App::import('Model', 'DbAcl');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shell for ACL management.
|
* Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode
|
||||||
|
* being enabled. Be sure to turn it off when using this shell.
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.console.libs
|
* @subpackage cake.cake.console.libs
|
||||||
|
|
32
cake/libs/cache/memcache.php
vendored
32
cake/libs/cache/memcache.php
vendored
|
@ -80,12 +80,7 @@ class MemcacheEngine extends CacheEngine {
|
||||||
$return = false;
|
$return = false;
|
||||||
$this->__Memcache =& new Memcache();
|
$this->__Memcache =& new Memcache();
|
||||||
foreach ($this->settings['servers'] as $server) {
|
foreach ($this->settings['servers'] as $server) {
|
||||||
$parts = explode(':', $server);
|
list($host, $port) = $this->_parseServerString($server);
|
||||||
$host = $parts[0];
|
|
||||||
$port = 11211;
|
|
||||||
if (isset($parts[1])) {
|
|
||||||
$port = $parts[1];
|
|
||||||
}
|
|
||||||
if ($this->__Memcache->addServer($host, $port)) {
|
if ($this->__Memcache->addServer($host, $port)) {
|
||||||
$return = true;
|
$return = true;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +90,31 @@ class MemcacheEngine extends CacheEngine {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the server address into the host/port. Handles both IPv6 and IPv4
|
||||||
|
* addresses
|
||||||
|
*
|
||||||
|
* @param string $server The server address string.
|
||||||
|
* @return array Array containing host, port
|
||||||
|
*/
|
||||||
|
function _parseServerString($server) {
|
||||||
|
if (substr($server, 0, 1) == '[') {
|
||||||
|
$position = strpos($server, ']:');
|
||||||
|
if ($position !== false) {
|
||||||
|
$position++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$position = strpos($server, ':');
|
||||||
|
}
|
||||||
|
$port = 11211;
|
||||||
|
$host = $server;
|
||||||
|
if ($position !== false) {
|
||||||
|
$host = substr($server, 0, $position);
|
||||||
|
$port = substr($server, $position + 1);
|
||||||
|
}
|
||||||
|
return array($host, $port);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write data for key into cache. When using memcache as your cache engine
|
* 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
|
* remember that the Memcache pecl extension does not support cache expiry times greater
|
||||||
|
|
|
@ -389,7 +389,7 @@ class SecurityComponent extends Component {
|
||||||
$keys = array();
|
$keys = array();
|
||||||
$match = array();
|
$match = array();
|
||||||
$req = array('nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1);
|
$req = array('nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1);
|
||||||
preg_match_all('@(\w+)=([\'"]?)([a-zA-Z0-9=./\_-]+)\2@', $digest, $match, PREG_SET_ORDER);
|
preg_match_all('/(\w+)=([\'"]?)([a-zA-Z0-9@=.\/_-]+)\2/', $digest, $match, PREG_SET_ORDER);
|
||||||
|
|
||||||
foreach ($match as $i) {
|
foreach ($match as $i) {
|
||||||
$keys[$i[1]] = $i[3];
|
$keys[$i[1]] = $i[3];
|
||||||
|
|
|
@ -98,7 +98,7 @@ class File {
|
||||||
$this->name = basename($path);
|
$this->name = basename($path);
|
||||||
}
|
}
|
||||||
$this->pwd();
|
$this->pwd();
|
||||||
!$this->exists() && $create && $this->safe($path) && $this->create();
|
$create && !$this->exists() && $this->safe($path) && $this->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -232,13 +232,21 @@ class CakeSchema extends Object {
|
||||||
|
|
||||||
if (is_array($models)) {
|
if (is_array($models)) {
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
|
$importModel = $model;
|
||||||
if (isset($this->plugin)) {
|
if (isset($this->plugin)) {
|
||||||
$model = $this->plugin . '.' . $model;
|
$importModel = $this->plugin . '.' . $model;
|
||||||
}
|
}
|
||||||
$Object = ClassRegistry::init(array('class' => $model, 'ds' => null));
|
if (!App::import('Model', $importModel)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$vars = get_class_vars($model);
|
||||||
|
if (empty($vars['useDbConfig']) || $vars['useDbConfig'] != $connection) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection));
|
||||||
|
|
||||||
if (is_object($Object) && $Object->useTable !== false) {
|
if (is_object($Object) && $Object->useTable !== false) {
|
||||||
$Object->setDataSource($connection);
|
|
||||||
$table = $db->fullTableName($Object, false);
|
$table = $db->fullTableName($Object, false);
|
||||||
if (in_array($table, $currentTables)) {
|
if (in_array($table, $currentTables)) {
|
||||||
$key = array_search($table, $currentTables);
|
$key = array_search($table, $currentTables);
|
||||||
|
|
|
@ -151,7 +151,7 @@ class DboSource extends DataSource {
|
||||||
* @param array $config An array defining the new configuration settings
|
* @param array $config An array defining the new configuration settings
|
||||||
* @return boolean True on success, false on failure
|
* @return boolean True on success, false on failure
|
||||||
*/
|
*/
|
||||||
public function reconnect($config = null) {
|
function reconnect($config = array()) {
|
||||||
$this->disconnect();
|
$this->disconnect();
|
||||||
$this->setConfig($config);
|
$this->setConfig($config);
|
||||||
$this->_sources = null;
|
$this->_sources = null;
|
||||||
|
|
|
@ -1687,6 +1687,7 @@ class Model extends Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->__save($data, $options)) {
|
if (!$this->__save($data, $options)) {
|
||||||
$validationErrors[$this->alias] = $this->validationErrors;
|
$validationErrors[$this->alias] = $this->validationErrors;
|
||||||
$validates = false;
|
$validates = false;
|
||||||
|
@ -1757,7 +1758,6 @@ class Model extends Object {
|
||||||
case ($options['validate'] === 'first'):
|
case ($options['validate'] === 'first'):
|
||||||
$options['validate'] = true;
|
$options['validate'] = true;
|
||||||
$return = array();
|
$return = array();
|
||||||
continue;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ($options['atomic']) {
|
if ($options['atomic']) {
|
||||||
|
@ -1770,6 +1770,10 @@ class Model extends Object {
|
||||||
return $return;
|
return $return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ($options['atomic'] && !$validates) {
|
||||||
|
$db->rollback($this);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -1821,14 +1825,15 @@ class Model extends Object {
|
||||||
}
|
}
|
||||||
$id = $this->id;
|
$id = $this->id;
|
||||||
|
|
||||||
if ($this->exists() && $this->beforeDelete($cascade)) {
|
if ($this->beforeDelete($cascade)) {
|
||||||
$db = $this->getDataSource();
|
|
||||||
$filters = $this->Behaviors->trigger($this, 'beforeDelete', array($cascade), array(
|
$filters = $this->Behaviors->trigger($this, 'beforeDelete', array($cascade), array(
|
||||||
'break' => true, 'breakOn' => false
|
'break' => true, 'breakOn' => false
|
||||||
));
|
));
|
||||||
if (!$filters) {
|
if (!$filters || !$this->exists()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||||
|
|
||||||
$this->_deleteDependent($id, $cascade);
|
$this->_deleteDependent($id, $cascade);
|
||||||
$this->_deleteLinks($id);
|
$this->_deleteLinks($id);
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
|
|
@ -368,11 +368,11 @@ class Set {
|
||||||
$options = array_merge(array('flatten' => true), $options);
|
$options = array_merge(array('flatten' => true), $options);
|
||||||
if (!isset($contexts[0])) {
|
if (!isset($contexts[0])) {
|
||||||
$current = current($data);
|
$current = current($data);
|
||||||
if ((is_array($current) && count($data) <= 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
|
if ((is_array($current) && count($data) < 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
|
||||||
$contexts = array($data);
|
$contexts = array($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tokens = array_slice(preg_split('/(?<!=)\/(?![a-z-]*\])/', $path), 1);
|
$tokens = array_slice(preg_split('/(?<!=)\/(?![a-z-\s]*\])/', $path), 1);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$token = array_shift($tokens);
|
$token = array_shift($tokens);
|
||||||
|
|
|
@ -254,12 +254,14 @@ class FormHelper extends AppHelper {
|
||||||
'plugin' => $this->plugin,
|
'plugin' => $this->plugin,
|
||||||
'controller' => $this->_View->viewPath,
|
'controller' => $this->_View->viewPath,
|
||||||
'action' => $options['action'],
|
'action' => $options['action'],
|
||||||
0 => $id
|
|
||||||
);
|
);
|
||||||
if (!empty($options['action']) && !isset($options['id'])) {
|
if (!empty($options['action']) && !isset($options['id'])) {
|
||||||
$options['id'] = $this->domId($options['action'] . 'Form');
|
$options['id'] = $this->domId($options['action'] . 'Form');
|
||||||
}
|
}
|
||||||
$options['action'] = array_merge($actionDefaults, (array)$options['url']);
|
$options['action'] = array_merge($actionDefaults, (array)$options['url']);
|
||||||
|
if (empty($options['action'][0])) {
|
||||||
|
$options['action'][0] = $id;
|
||||||
|
}
|
||||||
} elseif (is_string($options['url'])) {
|
} elseif (is_string($options['url'])) {
|
||||||
$options['action'] = $options['url'];
|
$options['action'] = $options['url'];
|
||||||
}
|
}
|
||||||
|
@ -582,7 +584,7 @@ class FormHelper extends AppHelper {
|
||||||
*
|
*
|
||||||
* In addition to fields control, inputs() allows you to use a few additional options.
|
* In addition to fields control, inputs() allows you to use a few additional options.
|
||||||
*
|
*
|
||||||
* - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
|
* - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
|
||||||
* the classname for the fieldset element.
|
* the classname for the fieldset element.
|
||||||
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
|
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
|
||||||
* to customize the legend text.
|
* to customize the legend text.
|
||||||
|
@ -1078,7 +1080,7 @@ class FormHelper extends AppHelper {
|
||||||
array('name', 'type', 'id'), '', ' '
|
array('name', 'type', 'id'), '', ' '
|
||||||
);
|
);
|
||||||
$tagName = Inflector::camelize(
|
$tagName = Inflector::camelize(
|
||||||
$attributes['id'] . '_' . Inflector::underscore($optValue)
|
$attributes['id'] . '_' . Inflector::slug($optValue)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($label) {
|
if ($label) {
|
||||||
|
@ -1766,7 +1768,7 @@ class FormHelper extends AppHelper {
|
||||||
* - `separator` The contents of the string between select elements. Defaults to '-'
|
* - `separator` The contents of the string between select elements. Defaults to '-'
|
||||||
* - `empty` - If true, the empty select option is shown. If a string,
|
* - `empty` - If true, the empty select option is shown. If a string,
|
||||||
* that string is displayed as the empty element.
|
* that string is displayed as the empty element.
|
||||||
* - `value` | `default` The default value to be used by the input. A value in `$this->data`
|
* - `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.
|
* 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 $fieldName Prefix name for the SELECT element
|
||||||
|
@ -1986,6 +1988,7 @@ class FormHelper extends AppHelper {
|
||||||
));
|
));
|
||||||
|
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
|
$name = $attributes['escape'] ? h($name) : $name;
|
||||||
if ($attributes['style'] === 'checkbox') {
|
if ($attributes['style'] === 'checkbox') {
|
||||||
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
|
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2019,7 +2022,7 @@ class FormHelper extends AppHelper {
|
||||||
$htmlOptions['value'] = $name;
|
$htmlOptions['value'] = $name;
|
||||||
|
|
||||||
$tagName = Inflector::camelize(
|
$tagName = Inflector::camelize(
|
||||||
$this->model() . '_' . $this->field().'_'.Inflector::underscore($name)
|
$this->model() . '_' . $this->field().'_'.Inflector::slug($name)
|
||||||
);
|
);
|
||||||
$htmlOptions['id'] = $tagName;
|
$htmlOptions['id'] = $tagName;
|
||||||
$label = array('for' => $tagName);
|
$label = array('for' => $tagName);
|
||||||
|
|
|
@ -251,14 +251,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
||||||
$options['url'] = $url;
|
$options['url'] = $url;
|
||||||
if (isset($options['update'])) {
|
if (isset($options['update'])) {
|
||||||
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
|
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
|
||||||
if ($wrapCallbacks) {
|
$success = '';
|
||||||
$success = $this->jQueryObject . '("' . $options['update'] . '").html(data);';
|
if(isset($options['success']) AND !empty($options['success'])) {
|
||||||
} else {
|
$success .= $options['success'];
|
||||||
$success = sprintf(
|
}
|
||||||
'function (data, textStatus) {%s("%s").html(data);}',
|
$success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);';
|
||||||
$this->jQueryObject,
|
if (!$wrapCallbacks) {
|
||||||
$options['update']
|
$success = 'function (data, textStatus) {' . $success . '}';
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$options['dataType'] = 'html';
|
$options['dataType'] = 'html';
|
||||||
$options['success'] = $success;
|
$options['success'] = $success;
|
||||||
|
|
|
@ -390,8 +390,8 @@ class View extends Object {
|
||||||
if ($layout && $this->autoLayout) {
|
if ($layout && $this->autoLayout) {
|
||||||
$out = $this->renderLayout($out, $layout);
|
$out = $this->renderLayout($out, $layout);
|
||||||
$isCached = (
|
$isCached = (
|
||||||
isset($this->Helpers->Cache) &&
|
isset($this->Helpers->Cache) ||
|
||||||
(($this->cacheAction != false)) && (Configure::read('Cache.check') === true)
|
Configure::read('Cache.check') === true
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($isCached) {
|
if ($isCached) {
|
||||||
|
@ -562,6 +562,7 @@ class View extends Object {
|
||||||
if (
|
if (
|
||||||
($count == 1 && !empty($this->association)) ||
|
($count == 1 && !empty($this->association)) ||
|
||||||
($count == 1 && $this->model != $this->entityPath) ||
|
($count == 1 && $this->model != $this->entityPath) ||
|
||||||
|
($count == 1 && empty($this->association) && !empty($this->field)) ||
|
||||||
($count == 2 && !empty($this->fieldSuffix)) ||
|
($count == 2 && !empty($this->fieldSuffix)) ||
|
||||||
is_numeric($path[0]) && !empty($assoc)
|
is_numeric($path[0]) && !empty($assoc)
|
||||||
) {
|
) {
|
||||||
|
|
46
cake/tests/cases/libs/cache/memcache.test.php
vendored
46
cake/tests/cases/libs/cache/memcache.test.php
vendored
|
@ -20,6 +20,20 @@
|
||||||
if (!class_exists('Cache')) {
|
if (!class_exists('Cache')) {
|
||||||
require LIBS . 'cache.php';
|
require LIBS . 'cache.php';
|
||||||
}
|
}
|
||||||
|
App::import('Core', 'cache/Memcache');
|
||||||
|
|
||||||
|
|
||||||
|
class TestMemcacheEngine extends MemcacheEngine {
|
||||||
|
/**
|
||||||
|
* public accessor to _parseServerString
|
||||||
|
*
|
||||||
|
* @param string $server
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function parseServerString($server) {
|
||||||
|
return $this->_parseServerString($server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MemcacheEngineTest class
|
* MemcacheEngineTest class
|
||||||
|
@ -121,6 +135,38 @@ class MemcacheEngineTest extends CakeTestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test connecting to an ipv6 server.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testConnectIpv6() {
|
||||||
|
$Memcache =& new MemcacheEngine();
|
||||||
|
$result = $Memcache->init(array(
|
||||||
|
'prefix' => 'cake_',
|
||||||
|
'duration' => 200,
|
||||||
|
'engine' => 'Memcache',
|
||||||
|
'servers' => array(
|
||||||
|
'[::1]:11211'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test non latin domains.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testParseServerStringNonLatin() {
|
||||||
|
$Memcache =& new TestMemcacheEngine();
|
||||||
|
$result = $Memcache->parseServerString('schülervz.net:13211');
|
||||||
|
$this->assertEqual($result, array('schülervz.net', '13211'));
|
||||||
|
|
||||||
|
$result = $Memcache->parseServerString('sülül:1111');
|
||||||
|
$this->assertEqual($result, array('sülül', '1111'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testReadAndWriteCache method
|
* testReadAndWriteCache method
|
||||||
*
|
*
|
||||||
|
|
|
@ -565,7 +565,15 @@ class AppImportTest extends CakeTestCase {
|
||||||
$this->assertTrue($file);
|
$this->assertTrue($file);
|
||||||
$this->assertTrue(class_exists('DboSource'));
|
$this->assertTrue(class_exists('DboSource'));
|
||||||
}
|
}
|
||||||
|
App::build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test import() with plugins
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testPluginImporting() {
|
||||||
App::build(array(
|
App::build(array(
|
||||||
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
|
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||||
|
@ -587,10 +595,15 @@ class AppImportTest extends CakeTestCase {
|
||||||
$result = App::import('Helper', 'TestPlugin.OtherHelper');
|
$result = App::import('Helper', 'TestPlugin.OtherHelper');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(class_exists('OtherHelperHelper'));
|
$this->assertTrue(class_exists('OtherHelperHelper'));
|
||||||
|
|
||||||
|
$result = App::import('Helper', 'TestPlugin.TestPluginApp');
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertTrue(class_exists('TestPluginAppHelper'));
|
||||||
|
|
||||||
$result = App::import('Datasource', 'TestPlugin.TestSource');
|
$result = App::import('Datasource', 'TestPlugin.TestSource');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(class_exists('TestSource'));
|
$this->assertTrue(class_exists('TestSource'));
|
||||||
|
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1054,6 +1054,7 @@ DIGEST;
|
||||||
DIGEST;
|
DIGEST;
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'username' => 'Mufasa',
|
'username' => 'Mufasa',
|
||||||
|
'realm' => 'testrealm@host.com',
|
||||||
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
||||||
'uri' => '/dir/index.html',
|
'uri' => '/dir/index.html',
|
||||||
'qop' => 'auth',
|
'qop' => 'auth',
|
||||||
|
@ -1088,6 +1089,7 @@ DIGEST;
|
||||||
DIGEST;
|
DIGEST;
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'username' => 'Mufasa',
|
'username' => 'Mufasa',
|
||||||
|
'realm' => 'testrealm@host.com',
|
||||||
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
||||||
'uri' => '/dir/index.html',
|
'uri' => '/dir/index.html',
|
||||||
'qop' => 'auth',
|
'qop' => 'auth',
|
||||||
|
@ -1103,6 +1105,39 @@ DIGEST;
|
||||||
$this->assertNull($result);
|
$this->assertNull($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test parsing digest information with email addresses
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testParseDigestAuthEmailAddress() {
|
||||||
|
$this->Controller->Security->startup($this->Controller);
|
||||||
|
$digest = <<<DIGEST
|
||||||
|
Digest username="mark@example.com",
|
||||||
|
realm="testrealm@host.com",
|
||||||
|
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
|
||||||
|
uri="/dir/index.html",
|
||||||
|
qop=auth,
|
||||||
|
nc=00000001,
|
||||||
|
cnonce="0a4f113b",
|
||||||
|
response="6629fae49393a05397450978507c4ef1",
|
||||||
|
opaque="5ccc069c403ebaf9f0171e9517f40e41"
|
||||||
|
DIGEST;
|
||||||
|
$expected = array(
|
||||||
|
'username' => 'mark@example.com',
|
||||||
|
'realm' => 'testrealm@host.com',
|
||||||
|
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
||||||
|
'uri' => '/dir/index.html',
|
||||||
|
'qop' => 'auth',
|
||||||
|
'nc' => '00000001',
|
||||||
|
'cnonce' => '0a4f113b',
|
||||||
|
'response' => '6629fae49393a05397450978507c4ef1',
|
||||||
|
'opaque' => '5ccc069c403ebaf9f0171e9517f40e41'
|
||||||
|
);
|
||||||
|
$result = $this->Controller->Security->parseDigestAuthData($digest);
|
||||||
|
$this->assertIdentical($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testFormDisabledFields method
|
* testFormDisabledFields method
|
||||||
*
|
*
|
||||||
|
|
|
@ -680,17 +680,17 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
'name' => 'TestApp',
|
'name' => 'TestApp',
|
||||||
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
||||||
));
|
));
|
||||||
unset($read['tables']['missing']);
|
|
||||||
$this->assertTrue(isset($read['tables']['posts']));
|
$this->assertTrue(isset($read['tables']['posts']));
|
||||||
$this->assertFalse(isset($read['tables']['cross_database']));
|
$this->assertFalse(isset($read['tables']['cross_database']), 'Cross database should not appear');
|
||||||
|
$this->assertFalse(isset($read['tables']['missing']['cross_database']), 'Cross database should not appear');
|
||||||
|
|
||||||
$read = $this->Schema->read(array(
|
$read = $this->Schema->read(array(
|
||||||
'connection' => 'test2',
|
'connection' => 'test2',
|
||||||
'name' => 'TestApp',
|
'name' => 'TestApp',
|
||||||
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
||||||
));
|
));
|
||||||
unset($read['tables']['missing']);
|
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
|
||||||
$this->assertFalse(isset($read['tables']['posts']));
|
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
|
||||||
$this->assertTrue(isset($read['tables']['cross_database']));
|
$this->assertTrue(isset($read['tables']['cross_database']));
|
||||||
|
|
||||||
$fixture->drop($db2);
|
$fixture->drop($db2);
|
||||||
|
|
|
@ -267,446 +267,489 @@ class ModelDeleteTest extends BaseModelTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that delete() updates the correct records counterCache() records.
|
* test that delete() updates the correct records counterCache() records.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testDeleteUpdatingCounterCacheCorrectly() {
|
function testDeleteUpdatingCounterCacheCorrectly() {
|
||||||
$this->loadFixtures('CounterCacheUser', 'CounterCachePost');
|
$this->loadFixtures('CounterCacheUser', 'CounterCachePost');
|
||||||
$User = new CounterCacheUser();
|
$User = new CounterCacheUser();
|
||||||
|
|
||||||
$User->Post->delete(3);
|
$User->Post->delete(3);
|
||||||
$result = $User->read(null, 301);
|
$result = $User->read(null, 301);
|
||||||
$this->assertEqual($result['User']['post_count'], 0);
|
$this->assertEqual($result['User']['post_count'], 0);
|
||||||
|
|
||||||
$result = $User->read(null, 66);
|
$result = $User->read(null, 66);
|
||||||
$this->assertEqual($result['User']['post_count'], 2);
|
$this->assertEqual($result['User']['post_count'], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testDeleteAll method
|
* testDeleteAll method
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testDeleteAll() {
|
function testDeleteAll() {
|
||||||
$this->loadFixtures('Article');
|
$this->loadFixtures('Article');
|
||||||
$TestModel = new Article();
|
$TestModel = new Article();
|
||||||
|
|
||||||
$data = array('Article' => array(
|
$data = array('Article' => array(
|
||||||
'user_id' => 2,
|
'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,
|
'id' => 4,
|
||||||
|
'user_id' => 2,
|
||||||
'title' => 'Fourth Article',
|
'title' => 'Fourth Article',
|
||||||
'published' => 'N'
|
'published' => 'N'
|
||||||
));
|
)),
|
||||||
$result = $TestModel->set($data) && $TestModel->save();
|
array('Article' => array(
|
||||||
$this->assertTrue($result);
|
|
||||||
|
|
||||||
$data = array('Article' => array(
|
|
||||||
'user_id' => 2,
|
|
||||||
'id' => 5,
|
'id' => 5,
|
||||||
|
'user_id' => 2,
|
||||||
'title' => 'Fifth Article',
|
'title' => 'Fifth Article',
|
||||||
'published' => 'Y'
|
'published' => 'Y'
|
||||||
));
|
)),
|
||||||
$result = $TestModel->set($data) && $TestModel->save();
|
array('Article' => array(
|
||||||
$this->assertTrue($result);
|
|
||||||
|
|
||||||
$data = array('Article' => array(
|
|
||||||
'user_id' => 1,
|
|
||||||
'id' => 6,
|
'id' => 6,
|
||||||
|
'user_id' => 1,
|
||||||
'title' => 'Sixth Article',
|
'title' => 'Sixth Article',
|
||||||
'published' => 'N'
|
'published' => 'N'
|
||||||
));
|
)));
|
||||||
$result = $TestModel->set($data) && $TestModel->save();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
|
|
||||||
$TestModel->recursive = -1;
|
$this->assertEqual($result, $expected);
|
||||||
$result = $TestModel->find('all', array(
|
|
||||||
'fields' => array('id', 'user_id', 'title', 'published')
|
|
||||||
));
|
|
||||||
|
|
||||||
$expected = array(
|
$result = $TestModel->deleteAll(array('Article.published' => 'N'));
|
||||||
array('Article' => array(
|
$this->assertTrue($result);
|
||||||
'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);
|
$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);
|
||||||
|
|
||||||
$result = $TestModel->deleteAll(array('Article.published' => 'N'));
|
$data = array('Article.user_id' => array(2, 3));
|
||||||
$this->assertTrue($result);
|
$result = $TestModel->deleteAll($data, true, true);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$TestModel->recursive = -1;
|
$TestModel->recursive = -1;
|
||||||
$result = $TestModel->find('all', array(
|
$result = $TestModel->find('all', array(
|
||||||
'fields' => array('id', 'user_id', 'title', 'published')
|
'fields' => array('id', 'user_id', 'title', 'published')
|
||||||
));
|
));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array('Article' => array(
|
array('Article' => array(
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'title' => 'First Article',
|
'title' => 'First Article',
|
||||||
'published' => 'Y'
|
'published' => 'Y'
|
||||||
)),
|
)),
|
||||||
array('Article' => array(
|
array('Article' => array(
|
||||||
'id' => 2,
|
'id' => 3,
|
||||||
'user_id' => 3,
|
'user_id' => 1,
|
||||||
'title' => 'Second Article',
|
'title' => 'Third Article',
|
||||||
'published' => 'Y'
|
'published' => 'Y'
|
||||||
)),
|
)));
|
||||||
array('Article' => array(
|
$this->assertEqual($result, $expected);
|
||||||
'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(array('Article.user_id' => 999));
|
||||||
$result = $TestModel->deleteAll($data, true, true);
|
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||||
$this->assertTrue($result);
|
|
||||||
|
|
||||||
$TestModel->recursive = -1;
|
$this->expectError();
|
||||||
$result = $TestModel->find('all', array(
|
ob_start();
|
||||||
'fields' => array('id', 'user_id', 'title', 'published')
|
$result = $TestModel->deleteAll(array('Article.non_existent_field' => 999));
|
||||||
));
|
ob_get_clean();
|
||||||
$expected = array(
|
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
|
||||||
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();
|
||||||
|
|
||||||
$this->expectError();
|
$result = $TestModel->delete(2);
|
||||||
ob_start();
|
$this->assertTrue($result);
|
||||||
$result = $TestModel->deleteAll(array('Article.non_existent_field' => 999));
|
|
||||||
ob_get_clean();
|
|
||||||
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$TestModel->recursive = 2;
|
||||||
* testRecursiveDel method
|
$result = $TestModel->read(null, 2);
|
||||||
*
|
$this->assertFalse($result);
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testRecursiveDel() {
|
|
||||||
$this->loadFixtures('Article', 'Comment', 'Attachment');
|
|
||||||
$TestModel = new Article();
|
|
||||||
|
|
||||||
$result = $TestModel->delete(2);
|
$result = $TestModel->Comment->read(null, 5);
|
||||||
$this->assertTrue($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$TestModel->recursive = 2;
|
$result = $TestModel->Comment->read(null, 6);
|
||||||
$result = $TestModel->read(null, 2);
|
$this->assertFalse($result);
|
||||||
$this->assertFalse($result);
|
|
||||||
|
|
||||||
$result = $TestModel->Comment->read(null, 5);
|
$result = $TestModel->Comment->Attachment->read(null, 1);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$result = $TestModel->Comment->read(null, 6);
|
$result = $TestModel->find('count');
|
||||||
$this->assertFalse($result);
|
$this->assertEqual($result, 2);
|
||||||
|
|
||||||
$result = $TestModel->Comment->Attachment->read(null, 1);
|
$result = $TestModel->Comment->find('count');
|
||||||
$this->assertFalse($result);
|
$this->assertEqual($result, 4);
|
||||||
|
|
||||||
$result = $TestModel->find('count');
|
$result = $TestModel->Comment->Attachment->find('count');
|
||||||
$this->assertEqual($result, 2);
|
$this->assertEqual($result, 0);
|
||||||
|
}
|
||||||
|
|
||||||
$result = $TestModel->Comment->find('count');
|
/**
|
||||||
$this->assertEqual($result, 4);
|
* testDependentExclusiveDelete method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDependentExclusiveDelete() {
|
||||||
|
$this->loadFixtures('Article', 'Comment');
|
||||||
|
$TestModel = new Article10();
|
||||||
|
|
||||||
$result = $TestModel->Comment->Attachment->find('count');
|
$result = $TestModel->find('all');
|
||||||
$this->assertEqual($result, 0);
|
$this->assertEqual(count($result[0]['Comment']), 4);
|
||||||
}
|
$this->assertEqual(count($result[1]['Comment']), 2);
|
||||||
|
$this->assertEqual($TestModel->Comment->find('count'), 6);
|
||||||
|
|
||||||
/**
|
$TestModel->delete(1);
|
||||||
* testDependentExclusiveDelete method
|
$this->assertEqual($TestModel->Comment->find('count'), 2);
|
||||||
*
|
}
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testDependentExclusiveDelete() {
|
|
||||||
$this->loadFixtures('Article', 'Comment');
|
|
||||||
$TestModel = new Article10();
|
|
||||||
|
|
||||||
$result = $TestModel->find('all');
|
/**
|
||||||
$this->assertEqual(count($result[0]['Comment']), 4);
|
* testDeleteLinks method
|
||||||
$this->assertEqual(count($result[1]['Comment']), 2);
|
*
|
||||||
$this->assertEqual($TestModel->Comment->find('count'), 6);
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDeleteLinks() {
|
||||||
|
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
||||||
|
$TestModel = new Article();
|
||||||
|
|
||||||
$TestModel->delete(1);
|
$result = $TestModel->ArticlesTag->find('all');
|
||||||
$this->assertEqual($TestModel->Comment->find('count'), 2);
|
$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);
|
||||||
* testDeleteLinks method
|
$result = $TestModel->ArticlesTag->find('all');
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testDeleteLinks() {
|
|
||||||
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
|
|
||||||
$TestModel = new Article();
|
|
||||||
|
|
||||||
$result = $TestModel->ArticlesTag->find('all');
|
$expected = array(
|
||||||
$expected = array(
|
array('ArticlesTag' => array(
|
||||||
array('ArticlesTag' => array(
|
'article_id' => '2',
|
||||||
'article_id' => '1',
|
'tag_id' => '1'
|
||||||
'tag_id' => '1'
|
)),
|
||||||
)),
|
array('ArticlesTag' => array(
|
||||||
array('ArticlesTag' => array(
|
'article_id' => '2',
|
||||||
'article_id' => '1',
|
'tag_id' => '3'
|
||||||
'tag_id' => '2'
|
)));
|
||||||
)),
|
$this->assertEqual($result, $expected);
|
||||||
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->deleteAll(array('Article.user_id' => 999));
|
||||||
$result = $TestModel->ArticlesTag->find('all');
|
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||||
|
}
|
||||||
|
|
||||||
$expected = array(
|
/**
|
||||||
array('ArticlesTag' => array(
|
* test deleteLinks with Multiple habtm associations
|
||||||
'article_id' => '2',
|
*
|
||||||
'tag_id' => '1'
|
* @return void
|
||||||
)),
|
*/
|
||||||
array('ArticlesTag' => array(
|
function testDeleteLinksWithMultipleHabtmAssociations() {
|
||||||
'article_id' => '2',
|
$this->loadFixtures('JoinA', 'JoinB', 'JoinC', 'JoinAB', 'JoinAC');
|
||||||
'tag_id' => '3'
|
$JoinA = new JoinA();
|
||||||
)));
|
|
||||||
$this->assertEqual($result, $expected);
|
|
||||||
|
|
||||||
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
|
//create two new join records to expose the issue.
|
||||||
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
$JoinA->JoinAsJoinC->create(array(
|
||||||
}
|
'join_a_id' => 1,
|
||||||
|
'join_c_id' => 2,
|
||||||
|
));
|
||||||
|
$JoinA->JoinAsJoinC->save();
|
||||||
|
$JoinA->JoinAsJoinB->create(array(
|
||||||
|
'join_a_id' => 1,
|
||||||
|
'join_b_id' => 2,
|
||||||
|
));
|
||||||
|
$JoinA->JoinAsJoinB->save();
|
||||||
|
|
||||||
/**
|
$result = $JoinA->delete(1);
|
||||||
* test deleteLinks with Multiple habtm associations
|
$this->assertTrue($result, 'Delete failed %s');
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testDeleteLinksWithMultipleHabtmAssociations() {
|
|
||||||
$this->loadFixtures('JoinA', 'JoinB', 'JoinC', 'JoinAB', 'JoinAC');
|
|
||||||
$JoinA = new JoinA();
|
|
||||||
|
|
||||||
//create two new join records to expose the issue.
|
$joinedBs = $JoinA->JoinAsJoinB->find('count', array(
|
||||||
$JoinA->JoinAsJoinC->create(array(
|
'conditions' => array('JoinAsJoinB.join_a_id' => 1)
|
||||||
'join_a_id' => 1,
|
));
|
||||||
'join_c_id' => 2,
|
$this->assertEqual($joinedBs, 0, 'JoinA/JoinB link records left over. %s');
|
||||||
));
|
|
||||||
$JoinA->JoinAsJoinC->save();
|
|
||||||
$JoinA->JoinAsJoinB->create(array(
|
|
||||||
'join_a_id' => 1,
|
|
||||||
'join_b_id' => 2,
|
|
||||||
));
|
|
||||||
$JoinA->JoinAsJoinB->save();
|
|
||||||
|
|
||||||
$result = $JoinA->delete(1);
|
$joinedBs = $JoinA->JoinAsJoinC->find('count', array(
|
||||||
$this->assertTrue($result, 'Delete failed %s');
|
'conditions' => array('JoinAsJoinC.join_a_id' => 1)
|
||||||
|
));
|
||||||
|
$this->assertEqual($joinedBs, 0, 'JoinA/JoinC link records left over. %s');
|
||||||
|
}
|
||||||
|
|
||||||
$joinedBs = $JoinA->JoinAsJoinB->find('count', array(
|
/**
|
||||||
'conditions' => array('JoinAsJoinB.join_a_id' => 1)
|
* testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method
|
||||||
));
|
*
|
||||||
$this->assertEqual($joinedBs, 0, 'JoinA/JoinB link records left over. %s');
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() {
|
||||||
|
|
||||||
$joinedBs = $JoinA->JoinAsJoinC->find('count', array(
|
$this->loadFixtures('Apple', 'Device', 'ThePaperMonkies');
|
||||||
'conditions' => array('JoinAsJoinC.join_a_id' => 1)
|
$ThePaper = new ThePaper();
|
||||||
));
|
$ThePaper->id = 1;
|
||||||
$this->assertEqual($joinedBs, 0, 'JoinA/JoinC link records left over. %s');
|
$ThePaper->save(array('Monkey' => array(2, 3)));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$result = $ThePaper->findById(1);
|
||||||
* testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method
|
$expected = array(
|
||||||
*
|
array(
|
||||||
* @access public
|
'id' => '2',
|
||||||
* @return void
|
'device_type_id' => '1',
|
||||||
*/
|
'name' => 'Device 2',
|
||||||
function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() {
|
'typ' => '1'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'id' => '3',
|
||||||
|
'device_type_id' => '1',
|
||||||
|
'name' => 'Device 3',
|
||||||
|
'typ' => '2'
|
||||||
|
));
|
||||||
|
$this->assertEqual($result['Monkey'], $expected);
|
||||||
|
|
||||||
$this->loadFixtures('Apple', 'Device', 'ThePaperMonkies');
|
$ThePaper = new ThePaper();
|
||||||
$ThePaper = new ThePaper();
|
$ThePaper->id = 2;
|
||||||
$ThePaper->id = 1;
|
$ThePaper->save(array('Monkey' => array(2, 3)));
|
||||||
$ThePaper->save(array('Monkey' => array(2, 3)));
|
|
||||||
|
|
||||||
$result = $ThePaper->findById(1);
|
$result = $ThePaper->findById(2);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array(
|
array(
|
||||||
'id' => '2',
|
'id' => '2',
|
||||||
'device_type_id' => '1',
|
'device_type_id' => '1',
|
||||||
'name' => 'Device 2',
|
'name' => 'Device 2',
|
||||||
'typ' => '1'
|
'typ' => '1'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'id' => '3',
|
'id' => '3',
|
||||||
'device_type_id' => '1',
|
'device_type_id' => '1',
|
||||||
'name' => 'Device 3',
|
'name' => 'Device 3',
|
||||||
'typ' => '2'
|
'typ' => '2'
|
||||||
));
|
));
|
||||||
$this->assertEqual($result['Monkey'], $expected);
|
$this->assertEqual($result['Monkey'], $expected);
|
||||||
|
|
||||||
$ThePaper = new ThePaper();
|
$ThePaper->delete(1);
|
||||||
$ThePaper->id = 2;
|
$result = $ThePaper->findById(2);
|
||||||
$ThePaper->save(array('Monkey' => array(2, 3)));
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
$result = $ThePaper->findById(2);
|
/**
|
||||||
$expected = array(
|
* test that beforeDelete returning false can abort deletion.
|
||||||
array(
|
*
|
||||||
'id' => '2',
|
* @return void
|
||||||
'device_type_id' => '1',
|
*/
|
||||||
'name' => 'Device 2',
|
function testBeforeDeleteDeleteAbortion() {
|
||||||
'typ' => '1'
|
$this->loadFixtures('Post');
|
||||||
),
|
$Model = new CallbackPostTestModel();
|
||||||
array(
|
$Model->beforeDeleteReturn = false;
|
||||||
'id' => '3',
|
|
||||||
'device_type_id' => '1',
|
|
||||||
'name' => 'Device 3',
|
|
||||||
'typ' => '2'
|
|
||||||
));
|
|
||||||
$this->assertEqual($result['Monkey'], $expected);
|
|
||||||
|
|
||||||
$ThePaper->delete(1);
|
$result = $Model->delete(1);
|
||||||
$result = $ThePaper->findById(2);
|
$this->assertFalse($result);
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$exists = $Model->findById(1);
|
||||||
* test that beforeDelete returning false can abort deletion.
|
$this->assertTrue(is_array($exists));
|
||||||
*
|
}
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testBeforeDeleteDeleteAbortion() {
|
|
||||||
$this->loadFixtures('Post');
|
|
||||||
$Model = new CallbackPostTestModel();
|
|
||||||
$Model->beforeDeleteReturn = false;
|
|
||||||
|
|
||||||
$result = $Model->delete(1);
|
/**
|
||||||
$this->assertFalse($result);
|
* test for a habtm deletion error that occurs in postgres but should not.
|
||||||
|
* And should not occur in any dbo.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDeleteHabtmPostgresFailure() {
|
||||||
|
$this->loadFixtures('Article', 'Tag', 'ArticlesTag');
|
||||||
|
|
||||||
$exists = $Model->findById(1);
|
$Article = ClassRegistry::init('Article');
|
||||||
$this->assertTrue(is_array($exists));
|
$Article->hasAndBelongsToMany['Tag']['unique'] = true;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$Tag = ClassRegistry::init('Tag');
|
||||||
* test for a habtm deletion error that occurs in postgres but should not.
|
$Tag->bindModel(array('hasAndBelongsToMany' => array(
|
||||||
* And should not occur in any dbo.
|
'Article' => array(
|
||||||
*
|
'className' => 'Article',
|
||||||
* @return void
|
'unique' => true
|
||||||
*/
|
)
|
||||||
function testDeleteHabtmPostgresFailure() {
|
)), true);
|
||||||
$this->loadFixtures('Article', 'Tag', 'ArticlesTag');
|
|
||||||
|
|
||||||
$Article = ClassRegistry::init('Article');
|
// Article 1 should have Tag.1 and Tag.2
|
||||||
$Article->hasAndBelongsToMany['Tag']['unique'] = true;
|
$before = $Article->find("all", array(
|
||||||
|
"conditions" => array("Article.id" => 1),
|
||||||
|
));
|
||||||
|
$this->assertEqual(count($before[0]['Tag']), 2, 'Tag count for Article.id = 1 is incorrect, should be 2 %s');
|
||||||
|
|
||||||
$Tag = ClassRegistry::init('Tag');
|
// From now on, Tag #1 is only associated with Post #1
|
||||||
$Tag->bindModel(array('hasAndBelongsToMany' => array(
|
$submitted_data = array(
|
||||||
'Article' => array(
|
"Tag" => array("id" => 1, 'tag' => 'tag1'),
|
||||||
'className' => 'Article',
|
"Article" => array(
|
||||||
'unique' => true
|
"Article" => array(1)
|
||||||
)
|
)
|
||||||
)), true);
|
);
|
||||||
|
$Tag->save($submitted_data);
|
||||||
|
|
||||||
// Article 1 should have Tag.1 and Tag.2
|
// One more submission (The other way around) to make sure the reverse save looks good.
|
||||||
$before = $Article->find("all", array(
|
$submitted_data = array(
|
||||||
"conditions" => array("Article.id" => 1),
|
"Article" => array("id" => 2, 'title' => 'second article'),
|
||||||
));
|
"Tag" => array(
|
||||||
$this->assertEqual(count($before[0]['Tag']), 2, 'Tag count for Article.id = 1 is incorrect, should be 2 %s');
|
"Tag" => array(2, 3)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// ERROR:
|
||||||
|
// Postgresql: DELETE FROM "articles_tags" WHERE tag_id IN ('1', '3')
|
||||||
|
// MySQL: DELETE `ArticlesTag` FROM `articles_tags` AS `ArticlesTag` WHERE `ArticlesTag`.`article_id` = 2 AND `ArticlesTag`.`tag_id` IN (1, 3)
|
||||||
|
$Article->save($submitted_data);
|
||||||
|
|
||||||
// From now on, Tag #1 is only associated with Post #1
|
// Want to make sure Article #1 has Tag #1 and Tag #2 still.
|
||||||
$submitted_data = array(
|
$after = $Article->find("all", array(
|
||||||
"Tag" => array("id" => 1, 'tag' => 'tag1'),
|
"conditions" => array("Article.id" => 1),
|
||||||
"Article" => array(
|
));
|
||||||
"Article" => array(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$Tag->save($submitted_data);
|
|
||||||
|
|
||||||
// One more submission (The other way around) to make sure the reverse save looks good.
|
// Removing Article #2 from Tag #1 is all that should have happened.
|
||||||
$submitted_data = array(
|
$this->assertEqual(count($before[0]["Tag"]), count($after[0]["Tag"]));
|
||||||
"Article" => array("id" => 2, 'title' => 'second article'),
|
}
|
||||||
"Tag" => array(
|
|
||||||
"Tag" => array(2, 3)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// ERROR:
|
|
||||||
// Postgresql: DELETE FROM "articles_tags" WHERE tag_id IN ('1', '3')
|
|
||||||
// MySQL: DELETE `ArticlesTag` FROM `articles_tags` AS `ArticlesTag` WHERE `ArticlesTag`.`article_id` = 2 AND `ArticlesTag`.`tag_id` IN (1, 3)
|
|
||||||
$Article->save($submitted_data);
|
|
||||||
|
|
||||||
// Want to make sure Article #1 has Tag #1 and Tag #2 still.
|
/**
|
||||||
$after = $Article->find("all", array(
|
* test that deleting records inside the beforeDelete doesn't truncate the table.
|
||||||
"conditions" => array("Article.id" => 1),
|
*
|
||||||
));
|
* @return void
|
||||||
|
*/
|
||||||
|
function testBeforeDeleteWipingTable() {
|
||||||
|
$this->loadFixtures('Comment');
|
||||||
|
|
||||||
// Removing Article #2 from Tag #1 is all that should have happened.
|
$Comment =& new BeforeDeleteComment();
|
||||||
$this->assertEqual(count($before[0]["Tag"]), count($after[0]["Tag"]));
|
// Delete 3 records.
|
||||||
}
|
$Comment->delete(4);
|
||||||
|
$result = $Comment->find('count');
|
||||||
|
|
||||||
|
$this->assertTrue($result > 1, 'Comments are all gone.');
|
||||||
|
$Comment->create(array(
|
||||||
|
'article_id' => 1,
|
||||||
|
'user_id' => 2,
|
||||||
|
'comment' => 'new record',
|
||||||
|
'published' => 'Y'
|
||||||
|
));
|
||||||
|
$Comment->save();
|
||||||
|
|
||||||
|
$Comment->delete(5);
|
||||||
|
$result = $Comment->find('count');
|
||||||
|
|
||||||
|
$this->assertTrue($result > 1, 'Comments are all gone.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that deleting the same record from the beforeDelete and the delete doesn't truncate the table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testBeforeDeleteWipingTableWithDuplicateDelete() {
|
||||||
|
$this->loadFixtures('Comment');
|
||||||
|
|
||||||
|
$Comment =& new BeforeDeleteComment();
|
||||||
|
$Comment->delete(1);
|
||||||
|
|
||||||
|
$result = $Comment->find('count');
|
||||||
|
$this->assertTrue($result > 1, 'Comments are all gone.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2954,7 +2954,7 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSaveAllTransactionNoRollback() {
|
function testSaveAllManyRowsTransactionNoRollback() {
|
||||||
$this->loadFixtures('Post');
|
$this->loadFixtures('Post');
|
||||||
|
|
||||||
$this->getMock('DboSource', array(), array(), 'MockTransactionDboSource');
|
$this->getMock('DboSource', array(), array(), 'MockTransactionDboSource');
|
||||||
|
@ -2984,6 +2984,44 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
$Post->saveAll($data, array('atomic' => true));
|
$Post->saveAll($data, array('atomic' => true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test saveAll with transactions and ensure there is no missing rollback.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testSaveAllAssociatedTransactionNoRollback() {
|
||||||
|
$testDb = ConnectionManager::getDataSource('test_suite');
|
||||||
|
|
||||||
|
Mock::generate('DboSource', 'MockTransactionAssociatedDboSource');
|
||||||
|
$db = ConnectionManager::create('mock_transaction_assoc', array(
|
||||||
|
'datasource' => 'MockTransactionAssociatedDbo',
|
||||||
|
));
|
||||||
|
$db->columns = $testDb->columns;
|
||||||
|
|
||||||
|
$db->expectOnce('rollback');
|
||||||
|
|
||||||
|
$Post =& new Post();
|
||||||
|
$Post->useDbConfig = 'mock_transaction_assoc';
|
||||||
|
$Post->Author->useDbConfig = 'mock_transaction_assoc';
|
||||||
|
|
||||||
|
$Post->Author->validate = array(
|
||||||
|
'user' => array('rule' => array('notEmpty'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'Post' => array(
|
||||||
|
'title' => 'New post',
|
||||||
|
'body' => 'Content',
|
||||||
|
'published' => 'Y'
|
||||||
|
),
|
||||||
|
'Author' => array(
|
||||||
|
'user' => '',
|
||||||
|
'password' => "sekret"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$Post->saveAll($data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSaveAllTransaction method
|
* testSaveAllTransaction method
|
||||||
*
|
*
|
||||||
|
|
|
@ -284,6 +284,24 @@ class Article extends CakeTestModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model stub for beforeDelete testing
|
||||||
|
*
|
||||||
|
* @see #250
|
||||||
|
* @package cake.tests
|
||||||
|
*/
|
||||||
|
class BeforeDeleteComment extends CakeTestModel {
|
||||||
|
var $name = 'BeforeDeleteComment';
|
||||||
|
|
||||||
|
var $useTable = 'comments';
|
||||||
|
|
||||||
|
function beforeDelete($cascade = true) {
|
||||||
|
$db =& $this->getDataSource();
|
||||||
|
$db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NumericArticle class
|
* NumericArticle class
|
||||||
*
|
*
|
||||||
|
|
|
@ -855,6 +855,39 @@ class SetTest extends CakeTestCase {
|
||||||
$r = Set::extract('/file/.[type=application/zip]', $f);
|
$r = Set::extract('/file/.[type=application/zip]', $f);
|
||||||
$this->assertEqual($r, $expected);
|
$this->assertEqual($r, $expected);
|
||||||
|
|
||||||
|
$f = array(
|
||||||
|
array(
|
||||||
|
'file' => array(
|
||||||
|
'name' => 'zipfile.zip',
|
||||||
|
'type' => 'application/zip',
|
||||||
|
'tmp_name' => '/tmp/php178.tmp',
|
||||||
|
'error' => 0,
|
||||||
|
'size' => '564647'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'file' => array(
|
||||||
|
'name' => 'zipfile2.zip',
|
||||||
|
'type' => 'application/x zip compressed',
|
||||||
|
'tmp_name' => '/tmp/php179.tmp',
|
||||||
|
'error' => 0,
|
||||||
|
'size' => '354784'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'file' => array(
|
||||||
|
'name' => 'picture.jpg',
|
||||||
|
'type' => 'image/jpeg',
|
||||||
|
'tmp_name' => '/tmp/php180.tmp',
|
||||||
|
'error' => 0,
|
||||||
|
'size' => '21324'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$expected = array(array('name' => 'zipfile2.zip','type' => 'application/x zip compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784'));
|
||||||
|
$r = Set::extract('/file/.[type=application/x zip compressed]', $f);
|
||||||
|
$this->assertEqual($r, $expected);
|
||||||
|
|
||||||
$hasMany = array(
|
$hasMany = array(
|
||||||
'Node' => array(
|
'Node' => array(
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
|
@ -1132,6 +1165,27 @@ class SetTest extends CakeTestCase {
|
||||||
$expected = array(0 => array('Article' => array('id' => 1, 'approved' => 1)));
|
$expected = array(0 => array('Article' => array('id' => 1, 'approved' => 1)));
|
||||||
$result = Set::extract('/Article[approved=1]', $startingAtOne);
|
$result = Set::extract('/Article[approved=1]', $startingAtOne);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$items = array(
|
||||||
|
240 => array(
|
||||||
|
'A' => array(
|
||||||
|
'field1' => 'a240',
|
||||||
|
'field2' => 'a240',
|
||||||
|
),
|
||||||
|
'B' => array(
|
||||||
|
'field1' => 'b240',
|
||||||
|
'field2' => 'b240'
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
0 => 'b240'
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = Set::extract('/B/field1', $items);
|
||||||
|
$this->assertIdentical($result, $expected);
|
||||||
|
$this->assertIdentical($result, Set::extract('{n}.B.field1', $items));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testExtractWithArrays method
|
* testExtractWithArrays method
|
||||||
|
|
|
@ -595,6 +595,13 @@ class HelperTest extends CakeTestCase {
|
||||||
$this->assertEqual($this->View->association, null);
|
$this->assertEqual($this->View->association, null);
|
||||||
$this->assertEqual($this->View->fieldSuffix, null);
|
$this->assertEqual($this->View->fieldSuffix, null);
|
||||||
|
|
||||||
|
$this->Helper->setEntity('HelperTestTag');
|
||||||
|
$this->assertEqual($this->View->model, 'HelperTestTag');
|
||||||
|
$this->assertEqual($this->View->field, 'HelperTestTag');
|
||||||
|
$this->assertEqual($this->View->modelId, null);
|
||||||
|
$this->assertEqual($this->View->association, null);
|
||||||
|
$this->assertEqual($this->View->fieldSuffix, null);
|
||||||
|
$this->assertEqual($this->View->entityPath, 'HelperTestTag');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1871,7 +1871,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
|
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'input checkbox'),
|
'div' => array('class' => 'input checkbox'),
|
||||||
|
@ -2249,6 +2249,33 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertPattern('/input type="radio"/', $result);
|
$this->assertPattern('/input type="radio"/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fields with the same name as the model should work.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testInputWithMatchingFieldAndModelName() {
|
||||||
|
$this->Form->create('User');
|
||||||
|
$this->Form->fieldset = array(
|
||||||
|
'User' => array(
|
||||||
|
'fields' => array(
|
||||||
|
'User' => array('type' => 'text')
|
||||||
|
),
|
||||||
|
'validates' => array(),
|
||||||
|
'key' => 'id'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->Form->data['User']['User'] = 'ABC, Inc.';
|
||||||
|
$result = $this->Form->input('User', array('type' => 'text'));
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input text'),
|
||||||
|
'label' => array('for' => 'UserUser'), 'User', '/label',
|
||||||
|
'input' => array('name' => 'data[User][User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testFormInputs method
|
* testFormInputs method
|
||||||
*
|
*
|
||||||
|
@ -2475,6 +2502,18 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/div',
|
'/div',
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), null, array('multiple' => 'checkbox'));
|
||||||
|
$expected = array(
|
||||||
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
||||||
|
array('div' => array('class' => 'checkbox')),
|
||||||
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
|
||||||
|
array('label' => array('for' => 'ModelMultiField12')),
|
||||||
|
'half',
|
||||||
|
'/label',
|
||||||
|
'/div',
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2664,6 +2703,16 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->radio('Model.field', array('1/2' => 'half'));
|
||||||
|
$expected = array(
|
||||||
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
||||||
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')),
|
||||||
|
'label' => array('for' => 'ModelField12'),
|
||||||
|
'half',
|
||||||
|
'/label'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'fieldset' => array(),
|
'fieldset' => array(),
|
||||||
|
@ -3066,6 +3115,47 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that select() with optiongroups listens to the escape param.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testSelectOptionGroupEscaping() {
|
||||||
|
$options = array(
|
||||||
|
'>< Key' => array(
|
||||||
|
1 => 'One',
|
||||||
|
2 => 'Two'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$result = $this->Form->select('Model.field', $options, null, array('empty' => false));
|
||||||
|
$expected = array(
|
||||||
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
||||||
|
'optgroup' => array('label' => '>< Key'),
|
||||||
|
array('option' => array('value' => '1')), 'One', '/option',
|
||||||
|
array('option' => array('value' => '2')), 'Two', '/option',
|
||||||
|
'/optgroup',
|
||||||
|
'/select'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
'>< Key' => array(
|
||||||
|
1 => 'One',
|
||||||
|
2 => 'Two'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$result = $this->Form->select('Model.field', $options, null, array('empty' => false, 'escape' => false));
|
||||||
|
$expected = array(
|
||||||
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
||||||
|
'optgroup' => array('label' => '>< Key'),
|
||||||
|
array('option' => array('value' => '1')), 'One', '/option',
|
||||||
|
array('option' => array('value' => '2')), 'Two', '/option',
|
||||||
|
'/optgroup',
|
||||||
|
'/select'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
|
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
|
||||||
*
|
*
|
||||||
|
@ -3448,7 +3538,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testInputMultipleCheckboxes() {
|
function testInputMultipleCheckboxes() {
|
||||||
$result = $this->Form->input('Model.multi_field', array(
|
$result = $this->Form->input('Model.multi_field', array(
|
||||||
'options' => array('first', 'second', 'third'),
|
'options' => array('first', 'second', 'third'),
|
||||||
'multiple' => 'checkbox'
|
'multiple' => 'checkbox'
|
||||||
));
|
));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -3531,7 +3621,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$result = $this->Form->input('Model.multi_field', array(
|
$result = $this->Form->input('Model.multi_field', array(
|
||||||
'options' => array('2' => 'second'),
|
'options' => array('2' => 'second'),
|
||||||
'multiple' => 'checkbox',
|
'multiple' => 'checkbox',
|
||||||
'label' => false,
|
'label' => false,
|
||||||
'div' => false
|
'div' => false
|
||||||
));
|
));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -5484,6 +5574,36 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected, true);
|
$this->assertTags($result, $expected, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that create() doesn't add in extra passed params.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCreatePassedArgs() {
|
||||||
|
$encoding = strtolower(Configure::read('App.encoding'));
|
||||||
|
$this->Form->data['Contact']['id'] = 1;
|
||||||
|
$result = $this->Form->create('Contact', array(
|
||||||
|
'type' => 'post',
|
||||||
|
'escape' => false,
|
||||||
|
'url' => array(
|
||||||
|
'action' => 'edit',
|
||||||
|
'myparam'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$expected = array(
|
||||||
|
'form' => array(
|
||||||
|
'id' => 'ContactAddForm',
|
||||||
|
'method' => 'post',
|
||||||
|
'action' => '/contacts/edit/myparam',
|
||||||
|
'accept-charset' => $encoding
|
||||||
|
),
|
||||||
|
'div' => array('style' => 'display:none;'),
|
||||||
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test creating a get form, and get form inputs.
|
* test creating a get form, and get form inputs.
|
||||||
*
|
*
|
||||||
|
|
|
@ -189,7 +189,7 @@ class JqueryEngineHelperTest extends CakeTestCase {
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'wrapCallbacks' => false
|
'wrapCallbacks' => false
|
||||||
));
|
));
|
||||||
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Jquery->request('/people/edit/1', array(
|
$result = $this->Jquery->request('/people/edit/1', array(
|
||||||
|
@ -200,7 +200,7 @@ class JqueryEngineHelperTest extends CakeTestCase {
|
||||||
'data' => '$("#someId").serialize()',
|
'data' => '$("#someId").serialize()',
|
||||||
'wrapCallbacks' => false
|
'wrapCallbacks' => false
|
||||||
));
|
));
|
||||||
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Jquery->request('/people/edit/1', array(
|
$result = $this->Jquery->request('/people/edit/1', array(
|
||||||
|
@ -230,7 +230,7 @@ class JqueryEngineHelperTest extends CakeTestCase {
|
||||||
'data' => '$j("#someId").serialize()',
|
'data' => '$j("#someId").serialize()',
|
||||||
'wrapCallbacks' => false
|
'wrapCallbacks' => false
|
||||||
));
|
));
|
||||||
$expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
$expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -799,6 +799,75 @@ class ViewTest extends CakeTestCase {
|
||||||
@unlink($path);
|
@unlink($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that render() will remove the cake:nocache tags when only the cachehelper is present.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testRenderStrippingNoCacheTagsOnlyCacheHelper() {
|
||||||
|
Configure::write('Cache.check', false);
|
||||||
|
$View =& new View($this->PostsController);
|
||||||
|
$View->set(array('superman' => 'clark', 'variable' => 'var'));
|
||||||
|
$View->helpers = array('Html', 'Form', 'Cache');
|
||||||
|
$View->layout = 'cache_layout';
|
||||||
|
$result = $View->render('index');
|
||||||
|
$this->assertNoPattern('/cake:nocache/', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that render() will remove the cake:nocache tags when only the Cache.check is true.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testRenderStrippingNoCacheTagsOnlyCacheCheck() {
|
||||||
|
Configure::write('Cache.check', true);
|
||||||
|
$View =& new View($this->PostsController);
|
||||||
|
$View->set(array('superman' => 'clark', 'variable' => 'var'));
|
||||||
|
$View->helpers = array('Html', 'Form');
|
||||||
|
$View->layout = 'cache_layout';
|
||||||
|
$result = $View->render('index');
|
||||||
|
$this->assertNoPattern('/cake:nocache/', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testRenderNocache method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This is a new test case for a pending enhancement
|
||||||
|
function testRenderNocache() {
|
||||||
|
$this->PostsController->helpers = array('Cache', 'Html');
|
||||||
|
$this->PostsController->constructClasses();
|
||||||
|
$this->PostsController->cacheAction = 21600;
|
||||||
|
$this->PostsController->here = '/posts/nocache_multiple_element';
|
||||||
|
$this->PostsController->action = 'nocache_multiple_element';
|
||||||
|
$this->PostsController->nocache_multiple_element();
|
||||||
|
Configure::write('Cache.check', true);
|
||||||
|
Configure::write('Cache.disable', false);
|
||||||
|
|
||||||
|
$filename = CACHE . 'views' . DS . 'posts_nocache_multiple_element.php';
|
||||||
|
|
||||||
|
$View = new TestView($this->PostsController);
|
||||||
|
$View->render();
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$View->renderCache($filename, getMicroTime());
|
||||||
|
$result = ob_get_clean();
|
||||||
|
@unlink($filename);
|
||||||
|
|
||||||
|
$this->assertPattern('/php echo \$foo;/', $result);
|
||||||
|
$this->assertPattern('/php echo \$bar;/', $result);
|
||||||
|
$this->assertPattern('/php \$barfoo = \'in sub2\';/', $result);
|
||||||
|
$this->assertPattern('/php echo \$barfoo;/', $result);
|
||||||
|
$this->assertPattern('/printing: "in sub2"/', $result);
|
||||||
|
$this->assertPattern('/php \$foobar = \'in sub1\';/', $result);
|
||||||
|
$this->assertPattern('/php echo \$foobar;/', $result);
|
||||||
|
$this->assertPattern('/printing: "in sub1"/', $result);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSet method
|
* testSet method
|
||||||
*
|
*
|
||||||
|
@ -854,6 +923,15 @@ class ViewTest extends CakeTestCase {
|
||||||
$View->entityPath = '0.Node.title';
|
$View->entityPath = '0.Node.title';
|
||||||
$expected = array(0, 'Node', 'title');
|
$expected = array(0, 'Node', 'title');
|
||||||
$this->assertEqual($View->entity(), $expected);
|
$this->assertEqual($View->entity(), $expected);
|
||||||
|
|
||||||
|
$View->model = 'HelperTestTag';
|
||||||
|
$View->field = 'HelperTestTag';
|
||||||
|
$View->modelId = null;
|
||||||
|
$View->association = null;
|
||||||
|
$View->fieldSuffix = null;
|
||||||
|
$View->entityPath = 'HelperTestTag';
|
||||||
|
$expected = array('HelperTestTag', 'HelperTestTag');
|
||||||
|
$this->assertEqual($View->entity(), $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,7 @@ App::import('Core', 'Xml');
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs
|
* @subpackage cake.tests.cases.libs
|
||||||
*/
|
*/
|
||||||
class Article extends CakeTestModel {
|
class XmlArticle extends CakeTestModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* name property
|
* name property
|
||||||
|
@ -39,7 +39,12 @@ class Article extends CakeTestModel {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $belongsTo = array('User');
|
public $belongsTo = array(
|
||||||
|
'XmlUser' => array(
|
||||||
|
'className' => 'XmlArticle',
|
||||||
|
'foreignKey' => 'user_id'
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +53,7 @@ class Article extends CakeTestModel {
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs
|
* @subpackage cake.tests.cases.libs
|
||||||
*/
|
*/
|
||||||
class User extends CakeTestModel {
|
class XmlUser extends CakeTestModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* name property
|
* name property
|
||||||
|
@ -822,7 +827,7 @@ class XmlTest extends CakeTestCase {
|
||||||
public function testWithModel() {
|
public function testWithModel() {
|
||||||
$this->loadFixtures('User', 'Article');
|
$this->loadFixtures('User', 'Article');
|
||||||
|
|
||||||
$user = new User();
|
$user = new XmlUser();
|
||||||
$data = $user->read(null, 1);
|
$data = $user->read(null, 1);
|
||||||
|
|
||||||
$obj = Xml::build(compact('data'));
|
$obj = Xml::build(compact('data'));
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TestPluginAppHelper extends AppHelper {
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue