Merge branch '1.3' into merger

Conflicts:
	cake/dispatcher.php
	cake/libs/cake_session.php
	cake/libs/controller/components/cookie.php
	cake/libs/controller/components/email.php
	cake/libs/controller/controller.php
	cake/libs/controller/scaffold.php
	cake/libs/set.php
	cake/libs/validation.php
	cake/libs/view/view.php
	cake/tests/cases/dispatcher.test.php
	cake/tests/cases/libs/controller/components/security.test.php
	cake/tests/cases/libs/controller/controller.test.php
	cake/tests/cases/libs/validation.test.php
	cake/tests/cases/libs/view/view.test.php
This commit is contained in:
mark_story 2010-12-10 22:24:31 -05:00
commit b9f0fc0724
26 changed files with 268 additions and 93 deletions

View file

@ -22,6 +22,9 @@
* @since CakePHP(tm) v .0.10.0.1222
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!class_exists('Security')) {
App::import('Core', 'Security');
}
/**
* Session class for Cake.

View file

@ -193,7 +193,7 @@ class CookieComponent extends Component {
/**
* Write a value to the $_COOKIE[$key];
*
* Optional [Name.], reguired key, optional $value, optional $encrypt, optional $expires
* Optional [Name.], required key, optional $value, optional $encrypt, optional $expires
* $this->Cookie->write('[Name.]key, $value);
*
* By default all values are encrypted.
@ -222,7 +222,6 @@ class CookieComponent extends Component {
if (strpos($name, '.') === false) {
$this->_values[$name] = $value;
$this->_write("[$name]", $value);
} else {
$names = explode('.', $name, 2);
if (!isset($this->_values[$names[0]])) {
@ -238,7 +237,7 @@ class CookieComponent extends Component {
/**
* Read the value of the $_COOKIE[$key];
*
* Optional [Name.], reguired key
* Optional [Name.], required key
* $this->Cookie->read(Name.key);
*
* @param mixed $key Key of the value to be obtained. If none specified, obtain map key => values
@ -252,7 +251,7 @@ class CookieComponent extends Component {
if (is_null($key)) {
return $this->_values;
}
if (strpos($key, '.') !== false) {
$names = explode('.', $key, 2);
$key = $names[0];
@ -270,7 +269,7 @@ class CookieComponent extends Component {
/**
* Delete a cookie value
*
* Optional [Name.], reguired key
* Optional [Name.], required key
* $this->Cookie->read('Name.key);
*
* You must use this method before any output is sent to the browser.
@ -348,11 +347,11 @@ class CookieComponent extends Component {
return $this->_expires;
}
$this->_reset = $this->_expires;
if ($expires == 0) {
return $this->_expires = 0;
}
if (is_integer($expires) || is_numeric($expires)) {
return $this->_expires = $now + intval($expires);
}
@ -433,7 +432,7 @@ class CookieComponent extends Component {
$decrypted = array();
$type = $this->_type;
foreach ($values as $name => $value) {
foreach ((array)$values as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
$pos = strpos($val, 'Q2FrZQ==.');

View file

@ -97,6 +97,15 @@ class EmailComponent extends Component {
*/
public $bcc = array();
/**
* The date to put in the Date: header. This should be a date
* conformant with the RFC2822 standard. Leave null, to have
* today's date generated.
*
* @var string
*/
var $date = null;
/**
* The subject of the email
*
@ -148,6 +157,18 @@ class EmailComponent extends Component {
*/
public $lineLength = 70;
/**
* Line feed character(s) to be used when sending using mail() function
* If null PHP_EOL is used.
* RFC2822 requires it to be CRLF but some Unix
* mail transfer agents replace LF by CRLF automatically
* (which leads to doubling CR if CRLF is used).
*
* @var string
* @access public
*/
var $lineFeed = null;
/**
* @deprecated see lineLength
*/
@ -261,6 +282,9 @@ class EmailComponent extends Component {
* it be handled by sendmail (or similar) or a string
* to completely override the Message-ID.
*
* If you are sending Email from a shell, be sure to set this value. As you
* could encounter delivery issues if you do not.
*
* @var mixed
* @access public
*/
@ -412,6 +436,7 @@ class EmailComponent extends Component {
$this->bcc = array();
$this->subject = null;
$this->additionalParams = null;
$this->date = null;
$this->smtpError = null;
$this->attachments = array();
$this->htmlMessage = null;
@ -576,6 +601,12 @@ class EmailComponent extends Component {
}
}
$date = $this->date;
if ($date == false) {
$date = date(DATE_RFC2822);
}
$headers['Date'] = $date;
$headers['X-Mailer'] = $this->xMailer;
if (!empty($this->headers)) {
@ -790,8 +821,13 @@ class EmailComponent extends Component {
* @access private
*/
function _mail() {
$header = implode("\r\n", $this->_header);
$message = implode("\r\n", $this->_message);
if ($this->lineFeed === null) {
$lineFeed = PHP_EOL;
} else {
$lineFeed = $this->lineFeed;
}
$header = implode($lineFeed, $this->_header);
$message = implode($lineFeed, $this->_message);
if (is_array($this->to)) {
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {

View file

@ -619,15 +619,11 @@ class SecurityComponent extends Component {
}
unset($check['_Token']);
$locked = str_rot13($locked);
if (preg_match('/(\A|;|{|})O\:[0-9]+/', $locked)) {
return false;
}
$locked = explode('|', $locked);
$lockedFields = array();
$fields = Set::flatten($check);
$fieldList = array_keys($fields);
$locked = unserialize($locked);
$multi = array();
foreach ($fieldList as $i => $key) {

View file

@ -247,7 +247,7 @@ class Scaffold {
}
if (!$this->ScaffoldModel->exists()) {
$message = __(sprintf("Invalid id for %s::edit()", Inflector::humanize($this->modelKey)));
$message = sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey));
return $this->_sendMessage($message);
}
}
@ -259,8 +259,10 @@ class Scaffold {
if ($this->ScaffoldModel->save($request->data)) {
if ($this->controller->_afterScaffoldSave($action)) {
$message = __(
sprintf('The %1$s has been %2$s', Inflector::humanize($this->modelKey), $success)
$message = sprintf(
__('The %1$s has been %2$s', true),
Inflector::humanize($this->modelKey),
$success
);
return $this->_sendMessage($message);
} else {
@ -306,8 +308,9 @@ class Scaffold {
*/
protected function _scaffoldDelete(CakeRequest $request) {
if ($this->controller->_beforeScaffold('delete')) {
$message = __(
sprintf("No id set for %s::delete()", Inflector::humanize($this->modelKey))
$message = sprintf(
__("No id set for %s::delete()", true),
Inflector::humanize($this->modelKey)
);
if (isset($request->params['pass'][0])) {
$id = $request->params['pass'][0];
@ -316,13 +319,14 @@ class Scaffold {
}
if ($this->ScaffoldModel->delete($id)) {
$message = __(
sprintf('The %1$s with id: %2$d has been deleted.', Inflector::humanize($this->modelClass), $id)
$message = sprintf(
__('The %1$s with id: %2$d has been deleted.', true),
Inflector::humanize($this->modelClass), $id
);
return $this->_sendMessage($message);
} else {
$message = __(sprintf(
'There was an error deleting the %1$s with id: %2$d',
$message = sprintf(
__('There was an error deleting the %1$s with id: %2$d', true),
Inflector::humanize($this->modelClass), $id
));
return $this->_sendMessage($message);

View file

@ -90,7 +90,6 @@ class File {
* @param string $path Path to file
* @param boolean $create Create file if it does not exist (if true)
* @param integer $mode Mode to apply to the folder holding the file
* @access private
*/
function __construct($path, $create = false, $mode = 0755) {
$this->Folder = new Folder(dirname($path), $create, $mode);
@ -104,7 +103,6 @@ class File {
/**
* Closes the current file if it is opened
*
* @access private
*/
function __destruct() {
$this->close();

View file

@ -384,7 +384,7 @@ class DataSource extends Object {
}
/**
* Returns the ID generated from the previous INSERT operation.
* Returns the number of rows returned by last operation.
*
* @param unknown_type $source
* @return integer Number of rows returned by last operation
@ -394,7 +394,7 @@ class DataSource extends Object {
}
/**
* Returns the ID generated from the previous INSERT operation.
* Returns the number of rows affected by last query.
*
* @param unknown_type $source
* @return integer Number of rows affected by last query.
@ -413,6 +413,7 @@ class DataSource extends Object {
public function enabled() {
return true;
}
/**
* Returns true if the DataSource supports the given interface (method)
*

View file

@ -679,7 +679,7 @@ class DboSource extends DataSource {
return $return;
}
$data = trim($data);
if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string
if (preg_match('/^[\w-]+(?:\.[^ \*]*)*$/', $data)) { // string, string.string
if (strpos($data, '.') === false) { // string
return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote);
}

View file

@ -1042,6 +1042,10 @@ class Set {
* @return array Sorted array of data
*/
public static function sort($data, $path, $dir) {
$originalKeys = array_keys($data);
if (is_numeric(implode('', $originalKeys))) {
$data = array_values($data);
}
$result = Set::__flatten(Set::extract($data, $path));
list($keys, $values) = array(Set::extract($result, '{n}.id'), Set::extract($result, '{n}.value'));
@ -1053,7 +1057,6 @@ class Set {
}
array_multisort($values, $dir, $keys, $dir);
$sorted = array();
$keys = array_unique($keys);
foreach ($keys as $k) {

View file

@ -668,7 +668,7 @@ class Validation {
*/
public static function url($check, $strict = false) {
self::__populateIp();
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z]|(%[0-9a-f]{2}))';
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))';
$regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
'(?:' . self::$__pattern['IPv4'] . '|' . self::$__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' .
'(?:\/?|\/' . $validChars . '*)?' .

View file

@ -401,7 +401,7 @@ class FormHelper extends AppHelper {
$fields += $locked;
$fields = Security::hash(serialize($fields) . Configure::read('Security.salt'));
$locked = str_rot13(serialize(array_keys($locked)));
$locked = implode(array_keys($locked), '|');
$out = $this->hidden('_Token.fields', array(
'value' => urlencode($fields . ':' . $locked),

View file

@ -835,7 +835,7 @@ class HtmlHelper extends AppHelper {
/**
* Internal function to build a nested list (UL/OL) out of an associative array.
*
* @param array $list Set of elements to list
* @param array $items Set of elements to list
* @param array $options Additional HTML attributes of the list (ol/ul) tag
* @param array $itemOptions Additional HTML attributes of the list item (LI) tag
* @param string $tag Type of list tag to use (ol/ul)

View file

@ -458,6 +458,19 @@ class CookieComponentTest extends CakeTestCase {
unset($_COOKIE['CakeTestCookie']);
}
/**
* test that no error is issued for non array data.
*
* @return void
*/
function testNoErrorOnNonArrayData() {
$this->Controller->Cookie->destroy();
$_COOKIE['CakeTestCookie'] = 'kaboom';
$this->assertNull($this->Controller->Cookie->read('value'));
}
/**
* encrypt method
*

View file

@ -501,6 +501,7 @@ TEMPDOC;
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
$date = date(DATE_RFC2822);
$message = <<<MSGBLOC
<pre>To: postmaster@localhost
From: noreply@example.com
@ -509,6 +510,7 @@ Header:
From: noreply@example.com
Reply-To: noreply@example.com
Date: $date
X-Mailer: CakePHP Email Component
Content-Type: {CONTENTTYPE}
Content-Transfer-Encoding: 7bitParameters:
@ -552,6 +554,7 @@ MSGBLOC;
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
$date = date(DATE_RFC2822);
$header = <<<HEADBLOC
To: postmaster@localhost
From: noreply@example.com
@ -560,6 +563,7 @@ Header:
From: noreply@example.com
Reply-To: noreply@example.com
Date: $date
X-Mailer: CakePHP Email Component
Content-Type: {CONTENTTYPE}
Content-Transfer-Encoding: 7bitParameters:
@ -633,22 +637,30 @@ HTMLBLOC;
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . '</pre>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
}
return;
/**
* test that elements used in email templates get helpers.
*
* @return void
*/
function testTemplateNestedElements() {
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$text = <<<TEXTBLOC
$this->Controller->EmailTest->delivery = 'debug';
$this->Controller->EmailTest->messageId = false;
$this->Controller->EmailTest->layout = 'default';
$this->Controller->EmailTest->template = 'nested_element';
$this->Controller->EmailTest->sendAs = 'html';
$this->Controller->helpers = array('Html');
This element has some text that is just too wide to comply with email
standards.
This is the body of the message
This email was sent using the CakePHP Framework, http://cakephp.org.
TEXTBLOC;
$this->Controller->EmailTest->sendAs = 'text';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'wide', 'default'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
$this->Controller->EmailTest->send();
$result = $this->Controller->Session->read('Message.email.message');
$this->assertPattern('/Test/', $result);
$this->assertPattern('/http\:\/\/example\.com/', $result);
}
/**
@ -697,6 +709,7 @@ TEXTBLOC;
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
@ -724,6 +737,7 @@ TEXTBLOC;
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
@ -857,7 +871,24 @@ HTMLBLOC;
$this->assertPattern('/First line\n/', $result);
$this->assertPattern('/Second line\n/', $result);
$this->assertPattern('/Third line\n/', $result);
}
/**
* test setting a custom date.
*
* @return void
*/
function testDateProperty() {
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->date = 'Today!';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'debug';
$this->assertTrue($this->Controller->EmailTest->send('test message'));
$result = $this->Controller->Session->read('Message.email.message');
$this->assertPattern('/Date: Today!\n/', $result);
}
/**
@ -1051,6 +1082,7 @@ HTMLBLOC;
$this->Controller->EmailTest->return = 'test.return@example.com';
$this->Controller->EmailTest->cc = array('cc1@example.com', 'cc2@example.com');
$this->Controller->EmailTest->bcc = array('bcc1@example.com', 'bcc2@example.com');
$this->Controller->EmailTest->date = 'Today!';
$this->Controller->EmailTest->subject = 'Test subject';
$this->Controller->EmailTest->additionalParams = 'X-additional-header';
$this->Controller->EmailTest->delivery = 'smtp';
@ -1072,6 +1104,7 @@ HTMLBLOC;
$this->assertNull($this->Controller->EmailTest->return);
$this->assertIdentical($this->Controller->EmailTest->cc, array());
$this->assertIdentical($this->Controller->EmailTest->bcc, array());
$this->assertNull($this->Controller->EmailTest->date);
$this->assertNull($this->Controller->EmailTest->subject);
$this->assertNull($this->Controller->EmailTest->additionalParams);
$this->assertIdentical($this->Controller->EmailTest->getHeaders(), array());
@ -1200,10 +1233,10 @@ HTMLBLOC;
$result = $this->Controller->EmailTest->formatAddress('email@example.com', true);
$this->assertEqual($result, '<email@example.com>');
$result = $this->Controller->EmailTest->formatAddress('<email@example.com>', true);
$this->assertEqual($result, '<email@example.com>');
$result = $this->Controller->EmailTest->formatAddress('alias name <email@example.com>', true);
$this->assertEqual($result, '<email@example.com>');
}

View file

@ -578,9 +578,9 @@ DIGEST;
*/
function testValidatePost() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3An%3A1%3A%7Bv%3A0%3B';
$fields .= 'f%3A11%3A%22Zbqry.inyvq%22%3B%7D';
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$this->Controller->request->data = array(
'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'),
@ -597,8 +597,7 @@ DIGEST;
function testValidatePostFormHacking() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3An%3A1%3A%7Bv%3A0%3B';
$fields .= 'f%3A11%3A%22Zbqry.inyvq%22%3B%7D';
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$this->Controller->request->data = array(
'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'),
@ -639,8 +638,9 @@ DIGEST;
*/
function testValidatePostArray() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'f7d573650a295b94e0938d32b323fde775e5f32b%3An%3A0%3A%7B%7D';
$fields = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
$this->Controller->request->data = array(
'Model' => array('multi_field' => array('1', '3')),
@ -657,8 +657,9 @@ DIGEST;
*/
function testValidatePostNoModel() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '540ac9c60d323c22bafe997b72c0790f39a8bdef%3An%3A0%3A%7B%7D';
$fields = '540ac9c60d323c22bafe997b72c0790f39a8bdef%3A';
$this->Controller->request->data = array(
'anything' => 'some_data',
@ -677,8 +678,9 @@ DIGEST;
*/
function testValidatePostSimple() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '69f493434187b867ea14b901fdf58b55d27c935d%3An%3A0%3A%7B%7D';
$fields = '69f493434187b867ea14b901fdf58b55d27c935d%3A';
$this->Controller->request->data = $data = array(
'Model' => array('username' => '', 'password' => ''),
@ -697,9 +699,9 @@ DIGEST;
*/
function testValidatePostComplex() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'c9118120e680a7201b543f562e5301006ccfcbe2%3An%3A2%3A%7Bv%3A0%3Bf%3A14%3A%';
$fields .= '22Nqqerffrf.0.vq%22%3Bv%3A1%3Bf%3A14%3A%22Nqqerffrf.1.vq%22%3B%7D';
$fields = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
$this->Controller->request->data = array(
'Addresses' => array(
@ -725,8 +727,9 @@ DIGEST;
*/
function testValidatePostMultipleSelect() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '422cde416475abc171568be690a98cad20e66079%3An%3A0%3A%7B%7D';
$fields = '422cde416475abc171568be690a98cad20e66079%3A';
$this->Controller->request->data = array(
'Tag' => array('Tag' => array(1, 2)),
@ -749,7 +752,7 @@ DIGEST;
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$fields = '19464422eafe977ee729c59222af07f983010c5f%3An%3A0%3A%7B%7D';
$fields = '19464422eafe977ee729c59222af07f983010c5f%3A';
$this->Controller->request->data = array(
'User.password' => 'bar', 'User.name' => 'foo', 'User.is_valid' => '1',
'Tag' => array('Tag' => array(1)), '_Token' => compact('key', 'fields'),
@ -770,8 +773,7 @@ DIGEST;
function testValidatePostCheckbox() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3An%3A1%3A%7Bv%3A0%';
$fields .= '3Bf%3A11%3A%22Zbqry.inyvq%22%3B%7D';
$fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid';
$this->Controller->request->data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
@ -781,7 +783,7 @@ DIGEST;
$result = $this->Controller->Security->validatePost($this->Controller);
$this->assertTrue($result);
$fields = '874439ca69f89b4c4a5f50fb9c36ff56a28f5d42%3An%3A0%3A%7B%7D';
$fields = '874439ca69f89b4c4a5f50fb9c36ff56a28f5d42%3A';
$this->Controller->request->data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
@ -814,8 +816,8 @@ DIGEST;
function testValidatePostHidden() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '51ccd8cb0997c7b3d4523ecde5a109318405ef8c%3An%3A2%3A%7Bv%3A0%3Bf%3A12%3A';
$fields .= '%22Zbqry.uvqqra%22%3Bv%3A1%3Bf%3A18%3A%22Zbqry.bgure_uvqqra%22%3B%7D';
$fields = '51ccd8cb0997c7b3d4523ecde5a109318405ef8c%3AModel.hidden%7CModel.other_hidden';
$fields .= '';
$this->Controller->request->data = array(
'Model' => array(
@ -838,8 +840,7 @@ DIGEST;
$this->Controller->Security->disabledFields = array('Model.username', 'Model.password');
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'ef1082968c449397bcd849f963636864383278b1%3An%3A1%3A%7Bv%';
$fields .= '3A0%3Bf%3A12%3A%22Zbqry.uvqqra%22%3B%7D';
$fields = 'ef1082968c449397bcd849f963636864383278b1%3AModel.hidden';
$this->Controller->request->data = array(
'Model' => array(
@ -861,9 +862,7 @@ DIGEST;
function testValidateHiddenMultipleModel() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = 'a2d01072dc4660eea9d15007025f35a7a5b58e18%3An%3A3%3A%7Bv%3A0%3Bf%3A11';
$fields .= '%3A%22Zbqry.inyvq%22%3Bv%3A1%3Bf%3A12%3A%22Zbqry2.inyvq%22%3Bv%3A2%';
$fields .= '3Bf%3A12%3A%22Zbqry3.inyvq%22%3B%7D';
$fields = 'a2d01072dc4660eea9d15007025f35a7a5b58e18%3AModel.valid%7CModel2.valid%7CModel3.valid';
$this->Controller->request->data = array(
'Model' => array('username' => '', 'password' => '', 'valid' => '0'),
@ -884,9 +883,8 @@ DIGEST;
function testValidateHasManyModel() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3An%3A4%3A%7Bv%3A0%3Bf%3A14%3A%2';
$fields .= '2Zbqry.0.uvqqra%22%3Bv%3A1%3Bf%3A13%3A%22Zbqry.0.inyvq%22%3Bv%3A2%3Bf%3';
$fields .= 'A14%3A%22Zbqry.1.uvqqra%22%3Bv%3A3%3Bf%3A13%3A%22Zbqry.1.inyvq%22%3B%7D';
$fields = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
$fields .= '%7CModel.1.hidden%7CModel.1.valid';
$this->Controller->request->data = array(
'Model' => array(
@ -915,9 +913,8 @@ DIGEST;
function testValidateHasManyRecordsPass() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3An%3A4%3A%7Bv%3A0%3Bf%3A12%3A%2';
$fields .= '2Nqqerff.0.vq%22%3Bv%3A1%3Bf%3A17%3A%22Nqqerff.0.cevznel%22%3Bv%3A2%3Bf%';
$fields .= '3A12%3A%22Nqqerff.1.vq%22%3Bv%3A3%3Bf%3A17%3A%22Nqqerff.1.cevznel%22%3B%7D';
$fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C';
$fields .= 'Address.1.id%7CAddress.1.primary';
$this->Controller->request->data = array(
'Address' => array(
@ -960,9 +957,8 @@ DIGEST;
function testValidateHasManyRecordsFail() {
$this->Controller->Security->startup($this->Controller);
$key = $this->Controller->request->params['_Token']['key'];
$fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3An%3A4%3A%7Bv%3A0%3Bf%3A12%3A%2';
$fields .= '2Nqqerff.0.vq%22%3Bv%3A1%3Bf%3A17%3A%22Nqqerff.0.cevznel%22%3Bv%3A2%3Bf%';
$fields .= '3A12%3A%22Nqqerff.1.vq%22%3Bv%3A3%3Bf%3A17%3A%22Nqqerff.1.cevznel%22%3B%7D';
$fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C';
$fields .= 'Address.1.id%7CAddress.1.primary';
$this->Controller->request->data = array(
'Address' => array(

View file

@ -1287,8 +1287,9 @@ class ControllerTest extends CakeTestCase {
$this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
$TestController = new AnotherTestController($request);
$expected = array('ControllerComment', 'ControllerAlias', 'ControllerPost');
$this->assertEqual($expected, $TestController->uses, '$uses was merged incorrectly, AppController models should be last.');
$TestController->constructClasses();
$appVars = get_class_vars('AppController');

View file

@ -578,6 +578,10 @@ class DboSourceTest extends CakeTestCase {
$result = $this->testDb->name(array('my-name', 'Foo-Model.*'));
$expected = array('`my-name`', '`Foo-Model`.*');
$this->assertEqual($result, $expected);
$result = $this->testDb->name(array('Team.P%', 'Team.G/G'));
$expected = array('`Team`.`P%`', '`Team`.`G/G`');
$this->assertEqual($result, $expected);
}
/**

View file

@ -354,6 +354,33 @@ class SetTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
/**
* test sorting with out of order keys.
*
* @return void
*/
function testSortWithOutOfOrderKeys() {
$data = array(
9 => array('class' => 510, 'test2' => 2),
1 => array('class' => 500, 'test2' => 1),
2 => array('class' => 600, 'test2' => 2),
5 => array('class' => 625, 'test2' => 4),
0 => array('class' => 605, 'test2' => 3),
);
$expected = array(
array('class' => 500, 'test2' => 1),
array('class' => 510, 'test2' => 2),
array('class' => 600, 'test2' => 2),
array('class' => 605, 'test2' => 3),
array('class' => 625, 'test2' => 4),
);
$result = Set::sort($data, '{n}.class', 'asc');
$this->assertEqual($expected, $result);
$result = Set::sort($data, '{n}.test2', 'asc');
$this->assertEqual($expected, $result);
}
/**
* testExtract method
*

View file

@ -1813,6 +1813,39 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
$this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
$this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed');
$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));
$this->assertTrue(Validation::url('http://cakephp.org:2000'));
$this->assertTrue(Validation::url('http://cakephp.org:27000'));
$this->assertTrue(Validation::url('http://cakephp.org:65000'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('[::1]'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('[::1]:80'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('http://[::1]'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('http://[::1]:80'));
$this->assertFalse(Validation::url('[1::2::3]'));
}
function testUuid() {
$this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000'));
$this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000'));
$this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b11d4-a716-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a716-4466440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a71-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29b-11d-a716-446655440000'));
$this->assertFalse(Validation::uuid('550e8400-e29-11d4-a716-446655440000'));
}
/**

View file

@ -829,7 +829,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->secure($fields);
$expected = Security::hash(serialize($fields) . Configure::read('Security.salt'));
$expected .= ':' . str_rot13(serialize(array('Model.valid')));
$expected .= ':' . 'Model.valid';
$expected = array(
'div' => array('style' => 'display:none;'),
@ -891,9 +891,8 @@ class FormHelperTest extends CakeTestCase {
$this->Form->request['_Token'] = array('key' => $key);
$result = $this->Form->secure($fields);
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3An%3A4%3A%7Bv%3A0%3Bf%3A14%3A%22Zbqry.';
$hash .= '0.uvqqra%22%3Bv%3A1%3Bf%3A13%3A%22Zbqry.0.inyvq%22%3Bv%3A2%3Bf%3A14%3A%22Zbqry.1';
$hash .= '.uvqqra%22%3Bv%3A3%3Bf%3A13%3A%22Zbqry.1.inyvq%22%3B%7D';
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
$hash .= '%7CModel.1.hidden%7CModel.1.valid';
$expected = array(
'div' => array('style' => 'display:none;'),
@ -982,8 +981,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->secure($this->Form->fields);
$hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3An%3A2%3A%7Bv%3A0%3Bf%3A14%';
$hash .= '3A%22Nqqerffrf.0.vq%22%3Bv%3A1%3Bf%3A14%3A%22Nqqerffrf.1.vq%22%3B%7D';
$hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
$expected = array(
'div' => array('style' => 'display:none;'),
@ -1028,8 +1026,7 @@ class FormHelperTest extends CakeTestCase {
$this->Form->input('Addresses.1.phone');
$result = $this->Form->secure($this->Form->fields);
$hash = '774df31936dc850b7d8a5277dc0b890123788b09%3An%3A2%3A%7Bv%3A0%3Bf%3A14%3A%22Nqqerf';
$hash .= 'frf.0.vq%22%3Bv%3A1%3Bf%3A14%3A%22Nqqerffrf.1.vq%22%3B%7D';
$hash = '774df31936dc850b7d8a5277dc0b890123788b09%3AAddresses.0.id%7CAddresses.1.id';
$expected = array(
'div' => array('style' => 'display:none;'),
@ -1075,8 +1072,7 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->secure($expected);
$hash = '449b7e889128e8e52c5e81d19df68f5346571492%3An%3A1%3A%';
$hash .= '7Bv%3A0%3Bf%3A12%3A%22Nqqerffrf.vq%22%3B%7D';
$hash = '449b7e889128e8e52c5e81d19df68f5346571492%3AAddresses.id';
$expected = array(
'div' => array('style' => 'display:none;'),
'input' => array(
@ -1180,8 +1176,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertEqual($result, $expected);
$hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3An%3A2%3A%7Bv%3A0%3Bf%3A15%3';
$hash .= 'A%22HfreSbez.uvqqra%22%3Bv%3A1%3Bf%3A14%3A%22HfreSbez.fghss%22%3B%7D';
$hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
$result = $this->Form->secure($this->Form->fields);
$expected = array(
@ -3567,7 +3562,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertEqual($this->Form->fields, array('Model.multi_field'));
$result = $this->Form->secure($this->Form->fields);
$key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3An%3A0%3A%7B%7D';
$key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
$this->assertPattern('/"' . $key . '"/', $result);
}

View file

@ -322,6 +322,14 @@ class NumberHelperTest extends CakeTestCase {
$expected = '&#163;1,234,568';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('1234567.8912345', null, array('before' => 'GBP', 'places' => 3));
$expected = 'GBP1,234,567.891';
$this->assertEqual($expected, $result);
$result = $this->Number->currency('650.120001', null, array('before' => 'GBP', 'places' => 4));
$expected = 'GBP650.1200';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, 'GBP', array('escape' => true));
$expected = '&amp;#163;1,234,567.89';
$this->assertEqual($expected, $result);

View file

@ -455,6 +455,24 @@ class ViewTest extends CakeTestCase {
$this->View->element('test_element', array(), true);
$this->mockObjects[] = $this->View->ElementCallbackMockHtml;
}
/**
* test that additional element viewVars don't get overwritten with helpers.
*
* @return void
*/
function testElementParamsDontOverwriteHelpers() {
$Controller = new ViewPostsController();
$Controller->helpers = array('Form');
$View = new View($Controller);
$result = $View->element('type_check', array('form' => 'string'), true);
$this->assertEqual('string', $result);
$View->set('form', 'string');
$result = $View->element('type_check', array(), true);
$this->assertEqual('string', $result);
}
/**
* testElementCacheHelperNoCache method
*

View file

@ -62,7 +62,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
*/
public function paintTestMenu() {
$cases = $this->baseUrl() . '?show=cases';
$plugins = App::objects('plugin');
$plugins = App::objects('plugin', null, false);
sort($plugins);
include CAKE_TESTS_LIB . 'templates' . DS . 'menu.php';
}

View file

@ -0,0 +1,3 @@
Before the element.
<?php echo $this->element('html_call'); ?>
After the element.

View file

@ -0,0 +1,3 @@
<?php
echo $this->Html->link('Test', 'http://example.com');
?>

View file

@ -0,0 +1 @@
<?php echo gettype($form); ?>