Merge remote branch 'origin/2.0' into feature/2.0/pdo

This commit is contained in:
José Lorenzo Rodríguez 2010-10-16 14:20:58 -04:30
commit 25915bd931
42 changed files with 2102 additions and 3665 deletions

View file

@ -143,13 +143,18 @@ if (!function_exists('sortByKey')) {
* Convenience method for htmlspecialchars. * Convenience method for htmlspecialchars.
* *
* @param string $text Text to wrap through htmlspecialchars * @param string $text Text to wrap through htmlspecialchars
* @param boolean $double Encode existing html entities
* @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8' * @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
* @return string Wrapped text * @return string Wrapped text
* @link http://book.cakephp.org/view/1132/h * @link http://book.cakephp.org/view/1132/h
*/ */
function h($text, $charset = null) { function h($text, $double = true, $charset = null) {
if (is_array($text)) { if (is_array($text)) {
return array_map('h', $text); $texts = array();
foreach ($text as $t) {
$texts[] = h($t, $double, $charset);
}
return $texts;
} }
static $defaultCharset = false; static $defaultCharset = false;
@ -159,10 +164,13 @@ if (!function_exists('sortByKey')) {
$defaultCharset = 'UTF-8'; $defaultCharset = 'UTF-8';
} }
} }
if (is_string($double)) {
$charset = $double;
}
if ($charset) { if ($charset) {
return htmlspecialchars($text, ENT_QUOTES, $charset); return htmlspecialchars($text, ENT_QUOTES, $charset, $double);
} else { } else {
return htmlspecialchars($text, ENT_QUOTES, $defaultCharset); return htmlspecialchars($text, ENT_QUOTES, $defaultCharset, $double);
} }
} }

View file

@ -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

View file

@ -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

View file

@ -172,15 +172,15 @@ class RequestHandlerComponent extends Component {
} }
if ($this->requestedWith('xml')) { if ($this->requestedWith('xml')) {
if (!class_exists('XmlNode')) { if (!class_exists('Xml')) {
App::import('Core', 'Xml'); App::import('Core', 'Xml');
} }
$xml = new Xml(trim(file_get_contents('php://input'))); $xml = Xml::build(trim(file_get_contents('php://input')));
if (count($xml->children) == 1 && is_object($dataNode = $xml->child('data'))) { if (isset($xml->data)) {
$controller->data = $dataNode->toArray(); $controller->data = Xml::toArray($xml->data);
} else { } else {
$controller->data = $xml->toArray(); $controller->data = Xml::toArray($xml);
} }
} }
} }

View file

@ -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];

View file

@ -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();
} }
/** /**

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -85,6 +85,7 @@ class Sanitize {
* - remove (boolean) if true strips all HTML tags before encoding * - remove (boolean) if true strips all HTML tags before encoding
* - charset (string) the charset used to encode the string * - charset (string) the charset used to encode the string
* - quotes (int) see http://php.net/manual/en/function.htmlentities.php * - quotes (int) see http://php.net/manual/en/function.htmlentities.php
* - double (boolean) doube encode html entities
* *
* @param string $string String from where to strip tags * @param string $string String from where to strip tags
* @param array $options Array of options to use. * @param array $options Array of options to use.
@ -101,7 +102,8 @@ class Sanitize {
$default = array( $default = array(
'remove' => false, 'remove' => false,
'charset' => $defaultCharset, 'charset' => $defaultCharset,
'quotes' => ENT_QUOTES 'quotes' => ENT_QUOTES,
'double' => true
); );
$options = array_merge($default, $options); $options = array_merge($default, $options);
@ -110,7 +112,7 @@ class Sanitize {
$string = strip_tags($string); $string = strip_tags($string);
} }
return htmlentities($string, $options['quotes'], $options['charset']); return htmlentities($string, $options['quotes'], $options['charset'], $options['double']);
} }
/** /**

View file

@ -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);
@ -941,9 +941,8 @@ class Set {
*/ */
public static function reverse($object) { public static function reverse($object) {
$out = array(); $out = array();
if (is_a($object, 'XmlNode')) { if ($object instanceof SimpleXMLElement) {
$out = $object->toArray(); return Xml::toArray($object);
return $out;
} else if (is_object($object)) { } else if (is_object($object)) {
$keys = get_object_vars($object); $keys = get_object_vars($object);
if (isset($keys['_name_'])) { if (isset($keys['_name_'])) {

View file

@ -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);

View file

@ -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;

View file

@ -17,18 +17,16 @@
* @since CakePHP(tm) v 1.2 * @since CakePHP(tm) v 1.2
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
App::import('Helper', 'Xml'); App::import('Core', 'Xml');
/** /**
* XML Helper class for easy output of XML structures. * RSS Helper class for easy output RSS structures.
*
* XmlHelper encloses all methods needed while working with XML documents.
* *
* @package cake * @package cake
* @subpackage cake.cake.libs.view.helpers * @subpackage cake.cake.libs.view.helpers
* @link http://book.cakephp.org/view/1460/RSS * @link http://book.cakephp.org/view/1460/RSS
*/ */
class RssHelper extends XmlHelper { class RssHelper extends AppHelper {
/** /**
* Helpers used by RSS Helper * Helpers used by RSS Helper
@ -270,7 +268,7 @@ class RssHelper extends XmlHelper {
if (!empty($elements)) { if (!empty($elements)) {
$content = implode('', $elements); $content = implode('', $elements);
} }
return $this->elem('item', $att, $content, !($content === null)); return $this->elem('item', (array)$att, $content, !($content === null));
} }
/** /**
@ -283,4 +281,62 @@ class RssHelper extends XmlHelper {
function time($time) { function time($time) {
return $this->Time->toRSS($time); return $this->Time->toRSS($time);
} }
/**
* Generates an XML element
*
* @param string $name The name of the XML element
* @param array $attrib The attributes of the XML element
* @param mixed $content XML element content
* @param boolean $endTag Whether the end tag of the element should be printed
* @return string XML
*/
function elem($name, $attrib = array(), $content = null, $endTag = true) {
$namespace = null;
if (isset($attrib['namespace'])) {
$namespace = $attrib['namespace'];
unset($attrib['namespace']);
}
$cdata = false;
if (is_array($content) && isset($content['cdata'])) {
$cdata = true;
unset($content['cdata']);
}
if (is_array($content) && array_key_exists('value', $content)) {
$content = $content['value'];
}
$children = array();
if (is_array($content)) {
$children = $content;
$content = null;
}
$xml = '<' . $name;
if (!empty($namespace)) {
$xml .= ' xmlns:"' . $namespace . '"';
}
if (strpos($name, ':') !== false) {
list($prefix, ) = explode(':', $name, 2);
switch ($prefix) {
case 'atom':
$xml .= ' xmlns:atom="http://www.w3.org/2005/Atom"';
break;
}
}
if ($cdata && !empty($content)) {
$content = '<![CDATA[' . $content . ']]>';
}
$xml .= '>' . $content . '</' . $name. '>';
$elem = Xml::build($xml);
foreach ($attrib as $key => $value) {
$elem->addAttribute($key, $value);
}
foreach ($children as $child) {
$elem->addChild($child);
}
$xml = $elem->asXML();
$xml = trim(substr($xml, strpos($xml, '?>') + 2));
return $xml;
}
} }

View file

@ -1,179 +0,0 @@
<?php
/**
* XML Helper class file.
*
* Simplifies the output of XML documents.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @since CakePHP(tm) v 1.2
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', array('Xml', 'Set'));
/**
* XML Helper class for easy output of XML structures.
*
* XmlHelper encloses all methods needed while working with XML documents.
*
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @link http://book.cakephp.org/view/1473/XML
*/
class XmlHelper extends AppHelper {
/**
* Default document encoding
*
* @access public
* @var string
*/
public $encoding = 'UTF-8';
/**
* Xml instance
*
* @var Xml
*/
public $Xml;
/**
* Constructor
*
* @return void
*/
function __construct(View $View, $settings = array()) {
parent::__construct($View, $settings);
$this->Xml =& new Xml();
$this->Xml->options(array('verifyNs' => false));
}
/**
* Returns an XML document header
*
* @param array $attrib Header tag attributes
* @return string XML header
* @access public
* @link http://book.cakephp.org/view/1476/header
*/
public function header($attrib = array()) {
if (Configure::read('App.encoding') !== null) {
$this->encoding = Configure::read('App.encoding');
}
if (is_array($attrib)) {
$attrib = array_merge(array('encoding' => $this->encoding), $attrib);
}
if (is_string($attrib) && strpos($attrib, 'xml') !== 0) {
$attrib = 'xml ' . $attrib;
}
return $this->Xml->header($attrib);
}
/**
* Adds a namespace to any documents generated
*
* @param string $name The namespace name
* @param string $url The namespace URI; can be empty if in the default namespace map
* @return boolean False if no URL is specified, and the namespace does not exist
* default namespace map, otherwise true
* @deprecated
* @see Xml::addNs()
*/
function addNs($name, $url = null) {
return $this->Xml->addNamespace($name, $url);
}
/**
* Removes a namespace added in addNs()
*
* @param string $name The namespace name or URI
* @deprecated
* @see Xml::removeNs()
*/
public function removeNs($name) {
return $this->Xml->removeGlobalNamespace($name);
}
/**
* Generates an XML element
*
* @param string $name The name of the XML element
* @param array $attrib The attributes of the XML element
* @param mixed $content XML element content
* @param boolean $endTag Whether the end tag of the element should be printed
* @return string XML
* @access public
* @link http://book.cakephp.org/view/1475/elem
*/
public function elem($name, $attrib = array(), $content = null, $endTag = true) {
$namespace = null;
if (isset($attrib['namespace'])) {
$namespace = $attrib['namespace'];
unset($attrib['namespace']);
}
$cdata = false;
if (is_array($content) && isset($content['cdata'])) {
$cdata = true;
unset($content['cdata']);
}
if (is_array($content) && array_key_exists('value', $content)) {
$content = $content['value'];
}
$children = array();
if (is_array($content)) {
$children = $content;
$content = null;
}
$elem =& $this->Xml->createElement($name, $content, $attrib, $namespace);
foreach ($children as $child) {
$elem->createElement($child);
}
$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
if (!$endTag) {
$this->Xml =& $elem;
}
return $out;
}
/**
* Create closing tag for current element
*
* @return string
*/
public function closeElem() {
$name = $this->Xml->name();
if ($parent =& $this->Xml->parent()) {
$this->Xml =& $parent;
}
return '</' . $name . '>';
}
/**
* Serializes a model resultset into XML
*
* @param mixed $data The content to be converted to XML
* @param array $options The data formatting options. For a list of valid options, see
* Xml::__construct().
* @return string A copy of $data in XML format
* @see Xml::__construct()
* @access public
* @link http://book.cakephp.org/view/1474/serialize
*/
public function serialize($data, $options = array()) {
$options += array('attributes' => false, 'format' => 'attributes');
$data =& new Xml($data, $options);
return $data->toString($options + array('header' => false));
}
}

View file

@ -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)
) { ) {

File diff suppressed because it is too large Load diff

View file

@ -200,6 +200,34 @@ class BasicsTest extends CakeTestCase {
$result = h($in); $result = h($in);
$expected = array('this &amp; that', '&lt;p&gt;Which one&lt;/p&gt;'); $expected = array('this &amp; that', '&lt;p&gt;Which one&lt;/p&gt;');
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$string = '<foo> & &nbsp;';
$result = h($string);
$this->assertEqual('&lt;foo&gt; &amp; &amp;nbsp;', $result);
$string = '<foo> & &nbsp;';
$result = h($string, false);
$this->assertEqual('&lt;foo&gt; &amp; &nbsp;', $result);
$string = '<foo> & &nbsp;';
$result = h($string, 'UTF-8');
$this->assertEqual('&lt;foo&gt; &amp; &amp;nbsp;', $result);
$arr = array('<foo>', '&nbsp;');
$result = h($arr);
$expected = array(
'&lt;foo&gt;',
'&amp;nbsp;'
);
$this->assertEqual($expected, $result);
$arr = array('<foo>', '&nbsp;');
$result = h($arr, false);
$expected = array(
'&lt;foo&gt;',
'&nbsp;'
);
$this->assertEqual($expected, $result);
} }
/** /**

View file

@ -38,7 +38,6 @@ class AllXmlTest extends PHPUnit_Framework_TestSuite {
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'xml.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'xml.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'rss.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'rss.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'xml.test.php');
return $suite; return $suite;
} }
} }

View file

@ -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
* *

View file

@ -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();
} }

View file

@ -331,11 +331,11 @@ class RequestHandlerComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
function testRenderAs() { function testRenderAs() {
$this->assertFalse(in_array('Xml', $this->Controller->helpers)); $this->assertFalse(in_array('Rss', $this->Controller->helpers));
$this->RequestHandler->renderAs($this->Controller, 'xml'); $this->RequestHandler->renderAs($this->Controller, 'rss');
$this->assertTrue(in_array('Xml', $this->Controller->helpers)); $this->assertTrue(in_array('Rss', $this->Controller->helpers));
$this->Controller->viewPath = 'request_handler_test\\xml'; $this->Controller->viewPath = 'request_handler_test\\rss';
$this->RequestHandler->renderAs($this->Controller, 'js'); $this->RequestHandler->renderAs($this->Controller, 'js');
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js'); $this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
} }
@ -425,8 +425,6 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'xml'); $this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'xml');
$this->assertEqual($this->Controller->layoutPath, 'xml'); $this->assertEqual($this->Controller->layoutPath, 'xml');
$this->assertTrue(in_array('Xml', $this->Controller->helpers));
$this->RequestHandler->renderAs($this->Controller, 'js'); $this->RequestHandler->renderAs($this->Controller, 'js');
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js'); $this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
$this->assertEqual($this->Controller->layoutPath, 'js'); $this->assertEqual($this->Controller->layoutPath, 'js');

View file

@ -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
* *

View file

@ -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);

View file

@ -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.');
}
} }

View file

@ -631,7 +631,7 @@ class ModelValidationTest extends BaseModelTest {
$Something->create(); $Something->create();
$result = $Something->saveAll($data, array('validate' => 'first')); $result = $Something->saveAll($data, array('validate' => 'first'));
$this->assertEquals($result, array()); $this->assertFalse($result);
$this->assertEqual($JoinThing->validationErrors, $expectedError); $this->assertEqual($JoinThing->validationErrors, $expectedError);
$count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id']))); $count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id'])));

View file

@ -2737,7 +2737,7 @@ class ModelWriteTest extends BaseModelTest {
'Attachment' => array('attachment' => '') 'Attachment' => array('attachment' => '')
), ),
array('validate' => 'first') array('validate' => 'first')
), array()); ), false);
$expected = array( $expected = array(
'Comment' => array('comment' => 'This field cannot be left blank'), 'Comment' => array('comment' => 'This field cannot be left blank'),
'Attachment' => array('attachment' => 'This field cannot be left blank') 'Attachment' => array('attachment' => 'This field cannot be left blank')
@ -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,54 @@ 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');
$mock = $this->getMock('DboSource', array(), array(), 'MockTransactionAssociatedDboSource', false);
$db =& ConnectionManager::create('mock_transaction_assoc', array(
'datasource' => 'MockTransactionAssociatedDbo',
));
$this->mockObjects[] = $db;
$db->columns = $testDb->columns;
$db->expects($this->once())->method('rollback');
$db->expects($this->any())->method('isInterfaceSupported')
->will($this->returnValue(true));
$db->expects($this->any())->method('describe')
->will($this->returnValue(array(
'id' => array('type' => 'integer'),
'title' => array('type' => 'string'),
'body' => array('type' => 'text'),
'published' => array('type' => 'string')
)));
$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
* *
@ -3451,7 +3499,7 @@ class ModelWriteTest extends BaseModelTest {
) )
), array('validate' => 'first')); ), array('validate' => 'first'));
$this->assertEquals($result, array()); $this->assertFalse($result);
$result = $model->find('all'); $result = $model->find('all');
$this->assertEqual($result, array()); $this->assertEqual($result, array());

View file

@ -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
* *

View file

@ -236,6 +236,16 @@ class SanitizeTest extends CakeTestCase {
$expected = 'The &quot;lazy&quot; dog &#039;jumped&#039; &amp; flew over the moon. If (1+1) = 2 &lt;em&gt;is&lt;/em&gt; true, (2-1) = 1 is also true'; $expected = 'The &quot;lazy&quot; dog &#039;jumped&#039; &amp; flew over the moon. If (1+1) = 2 &lt;em&gt;is&lt;/em&gt; true, (2-1) = 1 is also true';
$result = Sanitize::html($string); $result = Sanitize::html($string);
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$string = 'The "lazy" dog & his friend Apple&reg; conquered the world';
$expected = 'The &quot;lazy&quot; dog &amp; his friend Apple&amp;reg; conquered the world';
$result = Sanitize::html($string);
$this->assertEqual($result, $expected);
$string = 'The "lazy" dog & his friend Apple&reg; conquered the world';
$expected = 'The &quot;lazy&quot; dog &amp; his friend Apple&reg; conquered the world';
$result = Sanitize::html($string, array('double' => false));
$this->assertEqual($result, $expected);
} }
/** /**

View file

@ -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
@ -2674,20 +2728,20 @@ class SetTest extends CakeTestCase {
</item> </item>
</channel> </channel>
</rss>'; </rss>';
$xml = new Xml($string); $xml = Xml::build($string);
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = array('Rss' => array( $expected = array('rss' => array(
'version' => '2.0', 'version' => '2.0',
'Channel' => array( 'channel' => array(
'title' => 'Cake PHP Google Group', 'title' => 'Cake PHP Google Group',
'link' => 'http://groups.google.com/group/cake-php', 'link' => 'http://groups.google.com/group/cake-php',
'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.', 'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
'language' => 'en', 'language' => 'en',
'Item' => array( 'item' => array(
array( array(
'title' => 'constructng result array when using findall', 'title' => 'constructng result array when using findall',
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(", 'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(",
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)', 'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
@ -2706,43 +2760,43 @@ class SetTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$string ='<data><post title="Title of this post" description="cool"/></data>'; $string ='<data><post title="Title of this post" description="cool"/></data>';
$xml = new Xml($string); $xml = Xml::build($string);
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool'))); $expected = array('data' => array('post' => array('title' => 'Title of this post', 'description' => 'cool')));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>'); $xml = Xml::build('<example><item><title>An example of a correctly reversed SimpleXMLElement</title><desc/></item></example>');
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = array('Example' => $expected = array('example' =>
array( array(
'Item' => array( 'item' => array(
'title' => 'An example of a correctly reversed XMLNode', 'title' => 'An example of a correctly reversed SimpleXMLElement',
'desc' => array(), 'desc' => '',
) )
) )
); );
$this->assertEquals($result, $expected); $this->assertEquals($result, $expected);
$xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>'); $xml = Xml::build('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = $expected =
array('Example' => array( array('example' => array(
'Item' => array( 'item' => array(
'attr' => '123', 'attr' => '123',
'Titles' => array( 'titles' => array(
'Title' => array('title1', 'title2') 'title' => array('title1', 'title2')
) )
) )
) )
); );
$this->assertEquals($result, $expected); $this->assertEquals($result, $expected);
$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>'); $xml = Xml::build('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = $expected =
array('Example' => array( array('example' => array(
'attr' => 'ex_attr', 'attr' => 'ex_attr',
'Item' => array( 'item' => array(
'attr' => '123', 'attr' => '123',
'titles' => 'list', 'titles' => 'list',
'value' => 'textforitems' 'value' => 'textforitems'
@ -2752,7 +2806,7 @@ class SetTest extends CakeTestCase {
$this->assertEquals($result, $expected); $this->assertEquals($result, $expected);
$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0"> <rss version="2.0" xmlns:dc="http://www.cakephp.org/">
<channel> <channel>
<title>Cake PHP Google Group</title> <title>Cake PHP Google Group</title>
<link>http://groups.google.com/group/cake-php</link> <link>http://groups.google.com/group/cake-php</link>
@ -2783,23 +2837,23 @@ class SetTest extends CakeTestCase {
</channel> </channel>
</rss>'; </rss>';
$xml = new Xml($string); $xml = Xml::build($string);
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = array('Rss' => array( $expected = array('rss' => array(
'version' => '2.0', 'version' => '2.0',
'Channel' => array( 'channel' => array(
'title' => 'Cake PHP Google Group', 'title' => 'Cake PHP Google Group',
'link' => 'http://groups.google.com/group/cake-php', 'link' => 'http://groups.google.com/group/cake-php',
'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.', 'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
'language' => 'en', 'language' => 'en',
'Item' => array( 'item' => array(
array( array(
'title' => 'constructng result array when using findall', 'title' => 'constructng result array when using findall',
'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(", 'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(",
'creator' => 'cakephp', 'creator' => 'cakephp',
'Category' => array('cakephp', 'model'), 'category' => array('cakephp', 'model'),
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)', 'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
@ -2809,7 +2863,7 @@ class SetTest extends CakeTestCase {
'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8', 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other', 'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',
'creator' => 'cakephp', 'creator' => 'cakephp',
'Category' => array('cakephp', 'model'), 'category' => array('cakephp', 'model'),
'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'), 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)', 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT' 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
@ -2841,15 +2895,13 @@ class SetTest extends CakeTestCase {
</XRD> </XRD>
</XRDS>'; </XRDS>';
$xml = new Xml($text); $xml = Xml::build($text);
$result = Set::reverse($xml); $result = Set::reverse($xml);
$expected = array('XRDS' => array( $expected = array('XRDS' => array(
'xmlns' => 'xri://$xrds',
'XRD' => array( 'XRD' => array(
array( array(
'xml:id' => 'oauth', 'id' => 'oauth',
'xmlns' => 'xri://$XRD*($v*2.0)',
'version' => '2.0', 'version' => '2.0',
'Type' => 'xri://$xrds*simple', 'Type' => 'xri://$xrds*simple',
'Expires' => '2008-04-13T07:34:58Z', 'Expires' => '2008-04-13T07:34:58Z',
@ -2872,7 +2924,6 @@ class SetTest extends CakeTestCase {
) )
), ),
array( array(
'xmlns' => 'xri://$XRD*($v*2.0)',
'version' => '2.0', 'version' => '2.0',
'Type' => 'xri://$xrds*simple', 'Type' => 'xri://$xrds*simple',
'Service' => array( 'Service' => array(

View file

@ -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');
} }
/** /**

View file

@ -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->request->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' => '&gt;&lt; 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->request->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.
* *

View file

@ -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);
} }

View file

@ -38,9 +38,6 @@ class RssHelperTest extends CakeTestCase {
$controller = null; $controller = null;
$this->View = new View($controller); $this->View = new View($controller);
$this->Rss = new RssHelper($this->View); $this->Rss = new RssHelper($this->View);
$manager =& XmlManager::getInstance();
$manager->namespaces = array();
} }
/** /**
@ -54,52 +51,6 @@ class RssHelperTest extends CakeTestCase {
} }
/** /**
* testAddNamespace method
*
* @access public
* @return void
*/
function testAddNamespace() {
$this->Rss->addNs('custom', 'http://example.com/dtd.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml');
$this->assertEqual($manager->namespaces, $expected);
$this->Rss->removeNs('custom');
$this->Rss->addNs('dummy', 'http://dummy.com/1.0/');
$result = $this->Rss->document();
$expected = array(
'rss' => array(
'xmlns:dummy' => 'http://dummy.com/1.0/',
'version' => '2.0'
)
);
$this->assertTags($result, $expected);
$this->Rss->removeNs('dummy');
}
/**
* testRemoveNamespace method
*
* @access public
* @return void
*/
function testRemoveNamespace() {
$this->Rss->addNs('custom', 'http://example.com/dtd.xml');
$this->Rss->addNs('custom2', 'http://example.com/dtd2.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
$this->Rss->removeNs('custom');
$expected = array('custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
}
/**
* testDocument method * testDocument method
* *
* @access public * @access public
@ -253,6 +204,7 @@ class RssHelperTest extends CakeTestCase {
'<link', 'http://example.com', '/link', '<link', 'http://example.com', '/link',
'/image', '/image',
'atom:link' => array( 'atom:link' => array(
'xmlns:atom' => 'http://www.w3.org/2005/Atom',
'href' => "http://www.example.com/rss.xml", 'href' => "http://www.example.com/rss.xml",
'rel' => "self", 'rel' => "self",
'type' =>"application/rss+xml" 'type' =>"application/rss+xml"
@ -387,22 +339,6 @@ class RssHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$item = array(
'title' => array(
'value' => 'My Title & more',
'convertEntities' => false
)
);
$result = $this->Rss->item(null, $item);
$expected = array(
'<item',
'<title',
'My Title & more',
'/title',
'/item'
);
$this->assertTags($result, $expected);
$item = array( $item = array(
'title' => array( 'title' => array(
'value' => 'My Title & more', 'value' => 'My Title & more',

View file

@ -1,289 +0,0 @@
<?php
/**
* XmlHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
App::import('Helper', 'Xml');
App::import('Core', 'View');
/**
* TestXml class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class TestXmlHelper extends Object {
/**
* content property
*
* @var string ''
* @access public
*/
public $content = '';
/**
* construct method
*
* @param mixed $content
* @access private
* @return void
*/
function __construct($content) {
$this->content = $content;
}
/**
* toString method
*
* @access public
* @return void
*/
function toString() {
return $this->content;
}
}
/**
* XmlHelperTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
*/
class XmlHelperTest extends CakeTestCase {
/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
$controller = null;
$View = new View($controller);
$this->Xml = new XmlHelper($View);
$manager =& XmlManager::getInstance();
$manager->namespaces = array();
}
/**
* tearDown method
*
* @access public
* @return void
*/
function tearDown() {
unset($this->Xml);
}
/**
* testAddNamespace method
*
* @access public
* @return void
*/
function testAddNamespace() {
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml');
$this->assertEqual($manager->namespaces, $expected);
}
/**
* testRemoveNamespace method
*
* @access public
* @return void
*/
function testRemoveNamespace() {
$this->Xml->addNs('custom', 'http://example.com/dtd.xml');
$this->Xml->addNs('custom2', 'http://example.com/dtd2.xml');
$manager =& XmlManager::getInstance();
$expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
$this->Xml->removeNs('custom');
$expected = array('custom2' => 'http://example.com/dtd2.xml');
$this->assertEqual($manager->namespaces, $expected);
}
/**
* testRenderZeroElement method
*
* @access public
* @return void
*/
function testRenderZeroElement() {
$result = $this->Xml->elem('count', null, 0);
$expected = '<count>0</count>';
$this->assertEqual($result, $expected);
$result = $this->Xml->elem('count', null, array('cdata' => true, 'value' => null));
$expected = '<count />';
$this->assertEqual($result, $expected);
}
/**
* testRenderElementWithNamespace method
*
* @access public
* @return void
*/
function testRenderElementWithNamespace() {
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), 'content');
$expected = '<myNameSpace:count>content</myNameSpace:count>';
$this->assertEqual($result, $expected);
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), 'content', false);
$expected = '<myNameSpace:count>content';
$this->assertEqual($result, $expected);
$expected .= '</myNameSpace:count>';
$result .= $this->Xml->closeElem();
$this->assertEqual($result, $expected);
}
/**
* testRenderElementWithComplexContent method
*
* @access public
* @return void
*/
function testRenderElementWithComplexContent() {
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('contrived' => 'content'));
$expected = '<myNameSpace:count><content /></myNameSpace:count>';
$this->assertEqual($result, $expected);
$result = $this->Xml->elem('count', array('namespace' => 'myNameSpace'), array('cdata' => true, 'value' => 'content'));
$expected = '<myNameSpace:count><![CDATA[content]]></myNameSpace:count>';
$this->assertEqual($result, $expected);
}
/**
* testSerialize method
*
* @access public
* @return void
*/
function testSerialize() {
$data = array(
'test1' => 'test with no quotes',
'test2' => 'test with "double quotes"'
);
$result = $this->Xml->serialize($data);
$expected = '<std_class test1="test with no quotes" test2="test with &quot;double quotes&quot;" />';
$this->assertIdentical($result, $expected);
$data = array(
'test1' => 'test with no quotes',
'test2' => 'test without double quotes'
);
$result = $this->Xml->serialize($data);
$expected = '<std_class test1="test with no quotes" test2="test without double quotes" />';
$this->assertIdentical($result, $expected);
$data = array(
'ServiceDay' => array('ServiceTime' => array('ServiceTimePrice' => array('dollar' => 1, 'cents' => '2')))
);
$result = $this->Xml->serialize($data);
$expected = '<service_day><service_time><service_time_price dollar="1" cents="2" /></service_time></service_day>';
$this->assertIdentical($result, $expected);
$data = array(
'ServiceDay' => array('ServiceTime' => array('ServiceTimePrice' => array('dollar' => 1, 'cents' => '2')))
);
$result = $this->Xml->serialize($data, array('format' => 'tags'));
$expected = '<service_day><service_time><service_time_price><dollar>1</dollar><cents>2</cents></service_time_price></service_time></service_day>';
$this->assertIdentical($result, $expected);
$data = array(
'Pages' => array('id' => 2, 'url' => 'http://www.url.com/rb/153/?id=bbbb&t=access')
);
$result = $this->Xml->serialize($data);
$expected = '<pages id="2" url="http://www.url.com/rb/153/?id=bbbb&amp;t=access" />';
$this->assertIdentical($result, $expected);
$test = array(
'Test' => array('test' => true)
);
$expected = '<test test="1" />';
$result = $this->Xml->serialize($test);
$this->assertidentical($expected, $result);
}
/**
* testSerializeOnMultiDimensionalArray method
*
* @access public
* @return void
*/
function testSerializeOnMultiDimensionalArray() {
$data = array(
'Statuses' => array(
array('Status' => array('id' => 1)),
array('Status' => array('id' => 2))
)
);
$result = $this->Xml->serialize($data, array('format' => 'tags'));
$expected = '<statuses><status><id>1</id></status><status><id>2</id></status></statuses>';
$this->assertIdentical($result, $expected);
}
/**
* testHeader method
*
* @access public
* @return void
*/
function testHeader() {
$expectedDefaultEncoding = Configure::read('App.encoding');
if (empty($expectedDefaultEncoding)) {
$expectedDefaultEncoding = 'UTF-8';
}
$attrib = array();
$result = $this->Xml->header($attrib);
$expected = '<?xml version="1.0" encoding="'.$expectedDefaultEncoding.'" ?>';
$this->assertIdentical($result, $expected);
$attrib = array(
'encoding' => 'UTF-8',
'version' => '1.1'
);
$result = $this->Xml->header($attrib);
$expected = '<?xml version="1.1" encoding="UTF-8" ?>';
$this->assertIdentical($result, $expected);
$attrib = array(
'encoding' => 'UTF-8',
'version' => '1.2',
'additional' => 'attribute'
);
$result = $this->Xml->header($attrib);
$expected = '<?xml version="1.2" encoding="UTF-8" additional="attribute" ?>';
$this->assertIdentical($result, $expected);
$attrib = 'encoding="UTF-8" someOther="value"';
$result = $this->Xml->header($attrib);
$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
$this->assertIdentical($result, $expected);
}
}

View file

@ -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);
} }
/** /**

File diff suppressed because it is too large Load diff

33
cake/tests/fixtures/rss.xml vendored Normal file
View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml" />
<title>The Bakery: </title>
<link>http://bakery.cakephp.org/</link>
<description>Recent Articles at The Bakery.</description>
<language>en-us</language>
<pubDate>Wed, 01 Sep 2010 12:09:25 -0500</pubDate>
<docs>http://validator.w3.org/feed/docs/rss2.html</docs>
<generator>CakePHP Bakery</generator>
<managingEditor>mariano@cricava.com (Mariano Iglesias)</managingEditor>
<webMaster>gwoo@cakephp.org (Garrett Woodworth)</webMaster>
<item>
<title>EpisodeCMS</title>
<link>http://bakery.cakephp.org/articles/view/episodecms</link>
<description>EpisodeCMS is CakePHP based content management system.
Features: control panel, events API, module management, multilanguage and translations, themes
http://episodecms.com/
Please help me to improve it. Thanks.</description>
<pubDate>Tue, 31 Aug 2010 02:07:02 -0500</pubDate>
<guid>http://bakery.cakephp.org/articles/view/episodecms</guid>
</item>
<item>
<title>Alertpay automated sales via IPN</title>
<link>http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn</link>
<description>I&#039;m going to show you how I implemented a payment module via the Alertpay payment processor.</description>
<pubDate>Tue, 31 Aug 2010 01:42:00 -0500</pubDate>
<guid>http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn</guid>
</item>
</channel>
</rss>

9
cake/tests/fixtures/sample.xml vendored Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<tags>
<tag id="1">
<name>defect</name>
</tag>
<tag id="2">
<name>enhancement</name>
</tag>
</tags>

12
cake/tests/fixtures/soap_request.xml vendored Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>

12
cake/tests/fixtures/soap_response.xml vendored Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>

View file

@ -0,0 +1,5 @@
<?php
class TestPluginAppHelper extends AppHelper {
}