Merge branch 'master' into 2.5

This commit is contained in:
ADmad 2013-09-08 20:36:40 +05:30
commit c27aa99af9
19 changed files with 272 additions and 89 deletions

View file

@ -98,12 +98,12 @@ Configure::write('Dispatcher.filters', array(
*/ */
App::uses('CakeLog', 'Log'); App::uses('CakeLog', 'Log');
CakeLog::config('debug', array( CakeLog::config('debug', array(
'engine' => 'FileLog', 'engine' => 'File',
'types' => array('notice', 'info', 'debug'), 'types' => array('notice', 'info', 'debug'),
'file' => 'debug', 'file' => 'debug',
)); ));
CakeLog::config('error', array( CakeLog::config('error', array(
'engine' => 'FileLog', 'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error', 'file' => 'error',
)); ));

View file

@ -210,7 +210,10 @@ class FileEngine extends CacheEngine {
} }
$path = $this->_File->getRealPath(); $path = $this->_File->getRealPath();
$this->_File = null; $this->_File = null;
return unlink($path);
//@codingStandardsIgnoreStart
return @unlink($path);
//@codingStandardsIgnoreEnd
} }
/** /**
@ -289,9 +292,12 @@ class FileEngine extends CacheEngine {
} }
} }
if ($file->isFile()) { if ($file->isFile()) {
$_path = $file->getRealPath(); $filePath = $file->getRealPath();
$file = null; $file = null;
unlink($_path);
//@codingStandardsIgnoreStart
@unlink($filePath);
//@codingStandardsIgnoreEnd
} }
} }
} }
@ -411,7 +417,11 @@ class FileEngine extends CacheEngine {
$containsGroup = strpos($object->getPathName(), DS . $group . DS) !== false; $containsGroup = strpos($object->getPathName(), DS . $group . DS) !== false;
$hasPrefix = strpos($object->getBaseName(), $this->settings['prefix']) === 0; $hasPrefix = strpos($object->getBaseName(), $this->settings['prefix']) === 0;
if ($object->isFile() && $containsGroup && $hasPrefix) { if ($object->isFile() && $containsGroup && $hasPrefix) {
unlink($object->getPathName()); $path = $object->getPathName();
$object = null;
//@codingStandardsIgnoreStart
@unlink($path);
//@codingStandardsIgnoreEnd
} }
} }
return true; return true;

View file

@ -89,12 +89,12 @@ Configure::write('Dispatcher.filters', array(
*/ */
App::uses('CakeLog', 'Log'); App::uses('CakeLog', 'Log');
CakeLog::config('debug', array( CakeLog::config('debug', array(
'engine' => 'FileLog', 'engine' => 'File',
'types' => array('notice', 'info', 'debug'), 'types' => array('notice', 'info', 'debug'),
'file' => 'debug', 'file' => 'debug',
)); ));
CakeLog::config('error', array( CakeLog::config('error', array(
'engine' => 'FileLog', 'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error', 'file' => 'error',
)); ));

View file

@ -320,9 +320,11 @@ class TranslateBehavior extends ModelBehavior {
* beforeValidate Callback * beforeValidate Callback
* *
* @param Model $Model Model invalidFields was called on. * @param Model $Model Model invalidFields was called on.
* @param array $options Options passed from Model::save().
* @return boolean * @return boolean
* @see Model::save()
*/ */
public function beforeValidate(Model $Model) { public function beforeValidate(Model $Model, $options = array()) {
unset($this->runtime[$Model->alias]['beforeSave']); unset($this->runtime[$Model->alias]['beforeSave']);
$this->_setRuntimeData($Model); $this->_setRuntimeData($Model);
return true; return true;
@ -335,7 +337,9 @@ class TranslateBehavior extends ModelBehavior {
* disabled. Or the runtime data hasn't been set yet. * disabled. Or the runtime data hasn't been set yet.
* *
* @param Model $Model Model save was called on. * @param Model $Model Model save was called on.
* @param array $options Options passed from Model::save().
* @return boolean true. * @return boolean true.
* @see Model::save()
*/ */
public function beforeSave(Model $Model, $options = array()) { public function beforeSave(Model $Model, $options = array()) {
if (isset($options['validate']) && !$options['validate']) { if (isset($options['validate']) && !$options['validate']) {

View file

@ -175,9 +175,11 @@ class TreeBehavior extends ModelBehavior {
* *
* @since 1.2 * @since 1.2
* @param Model $Model Model instance * @param Model $Model Model instance
* @param array $options Options passed from Model::save().
* @return boolean true to continue, false to abort the save * @return boolean true to continue, false to abort the save
* @see Model::save()
*/ */
public function beforeSave(Model $Model) { public function beforeSave(Model $Model, $options = array()) {
extract($this->settings[$Model->alias]); extract($this->settings[$Model->alias]);
$this->_addToWhitelist($Model, array($left, $right)); $this->_addToWhitelist($Model, array($left, $right));

View file

@ -346,7 +346,6 @@ class Postgres extends DboSource {
$this->cacheSources = $cache; $this->cacheSources = $cache;
} }
if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) { if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
$schema = $this->config['schema'];
if (isset($this->_sequenceMap[$table]) && $reset != true) { if (isset($this->_sequenceMap[$table]) && $reset != true) {
foreach ($this->_sequenceMap[$table] as $sequence) { foreach ($this->_sequenceMap[$table] as $sequence) {
list($schema, $sequence) = explode('.', $sequence); list($schema, $sequence) = explode('.', $sequence);

View file

@ -952,14 +952,14 @@ class DboSource extends DataSource {
if ($quote) { if ($quote) {
if ($schema && !empty($schemaName)) { if ($schema && !empty($schemaName)) {
if (false == strstr($table, '.')) { if (strstr($table, '.') === false) {
return $this->name($schemaName) . '.' . $this->name($table); return $this->name($schemaName) . '.' . $this->name($table);
} }
} }
return $this->name($table); return $this->name($table);
} }
if ($schema && !empty($schemaName)) { if ($schema && !empty($schemaName)) {
if (false == strstr($table, '.')) { if (strstr($table, '.') === false) {
return $schemaName . '.' . $table; return $schemaName . '.' . $table;
} }
} }
@ -1065,7 +1065,7 @@ class DboSource extends DataSource {
if ($bypass) { if ($bypass) {
$assocData['fields'] = false; $assocData['fields'] = false;
} }
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { if ($this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null) === true) {
$linkedModels[$type . '/' . $assoc] = true; $linkedModels[$type . '/' . $assoc] = true;
} }
} }
@ -1730,8 +1730,10 @@ class DboSource extends DataSource {
* @return string * @return string
*/ */
public function renderJoinStatement($data) { public function renderJoinStatement($data) {
extract($data); if (strtoupper($data['type']) === 'CROSS') {
return trim("{$type} JOIN {$table} {$alias} ON ({$conditions})"); return "{$data['type']} JOIN {$data['table']} {$data['alias']}";
}
return trim("{$data['type']} JOIN {$data['table']} {$data['alias']} ON ({$data['conditions']})");
} }
/** /**

View file

@ -3460,9 +3460,10 @@ class Model extends Object implements CakeEventListener {
* Called during validation operations, before validation. Please note that custom * Called during validation operations, before validation. Please note that custom
* validation rules can be defined in $validate. * validation rules can be defined in $validate.
* *
* @param array $options Options passed from model::save(), see $options of model::save(). * @param array $options Options passed from Model::save().
* @return boolean True if validate operation should continue, false to abort * @return boolean True if validate operation should continue, false to abort
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
* @see Model::save()
*/ */
public function beforeValidate($options = array()) { public function beforeValidate($options = array()) {
return true; return true;

View file

@ -141,9 +141,11 @@ class ModelBehavior extends Object {
* will allow you to make the validation fail. * will allow you to make the validation fail.
* *
* @param Model $model Model using this behavior * @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False or null will abort the operation. Any other result will continue. * @return mixed False or null will abort the operation. Any other result will continue.
* @see Model::save()
*/ */
public function beforeValidate(Model $model) { public function beforeValidate(Model $model, $options = array()) {
return true; return true;
} }
@ -163,9 +165,11 @@ class ModelBehavior extends Object {
* will abort the save operation. * will abort the save operation.
* *
* @param Model $model Model using this behavior * @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False if the operation should abort. Any other result will continue. * @return mixed False if the operation should abort. Any other result will continue.
* @see Model::save()
*/ */
public function beforeSave(Model $model) { public function beforeSave(Model $model, $options = array()) {
return true; return true;
} }

View file

@ -104,10 +104,12 @@ class TestBehavior extends ModelBehavior {
/** /**
* beforeSave method * beforeSave method
* *
* @param Model $model * @param Model $model Model using this behavior
* @return void * @param array $options Options passed from Model::save().
* @return mixed False if the operation should abort. Any other result will continue.
* @see Model::save()
*/ */
public function beforeSave(Model $model) { public function beforeSave(Model $model, $options = array()) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['beforeSave']) || $settings['beforeSave'] === 'off') { if (!isset($settings['beforeSave']) || $settings['beforeSave'] === 'off') {
return parent::beforeSave($model); return parent::beforeSave($model);
@ -155,12 +157,14 @@ class TestBehavior extends ModelBehavior {
} }
/** /**
* beforeValidate method * beforeValidate Callback
* *
* @param Model $model * @param Model $Model Model invalidFields was called on.
* @return void * @param array $options Options passed from Model::save().
* @return boolean
* @see Model::save()
*/ */
public function beforeValidate(Model $model) { public function beforeValidate(Model $model, $options = array()) {
$settings = $this->settings[$model->alias]; $settings = $this->settings[$model->alias];
if (!isset($settings['validate']) || $settings['validate'] === 'off') { if (!isset($settings['validate']) || $settings['validate'] === 'off') {
return parent::beforeValidate($model); return parent::beforeValidate($model);

View file

@ -1111,8 +1111,14 @@ class DboSourceTest extends CakeTestCase {
* *
* @return array * @return array
*/ */
public static function joinStatements($schema) { public static function joinStatements() {
return array( return array(
array(array(
'type' => 'CROSS',
'alias' => 'PostsTag',
'table' => 'posts_tags',
'conditions' => array('1 = 1')
), 'CROSS JOIN cakephp.posts_tags AS PostsTag'),
array(array( array(array(
'type' => 'LEFT', 'type' => 'LEFT',
'alias' => 'PostsTag', 'alias' => 'PostsTag',

View file

@ -2039,7 +2039,9 @@ class CallbackPostTestModel extends CakeTestModel {
/** /**
* beforeValidate callback * beforeValidate callback
* *
* @return boolean * @param array $options Options passed from Model::save().
* @return boolean True if validate operation should continue, false to abort
* @see Model::save()
*/ */
public function beforeValidate($options = array()) { public function beforeValidate($options = array()) {
return $this->beforeValidateReturn; return $this->beforeValidateReturn;
@ -4980,7 +4982,9 @@ class CustomArticle extends AppModel {
/** /**
* Alters title data * Alters title data
* *
* @return void * @param array $options Options passed from Model::save().
* @return boolean True if validate operation should continue, false to abort
* @see Model::save()
*/ */
public function beforeValidate($options = array()) { public function beforeValidate($options = array()) {
$this->data[$this->alias]['title'] = 'foo'; $this->data[$this->alias]['title'] = 'foo';

View file

@ -4077,6 +4077,26 @@ class FormHelperTest extends CakeTestCase {
$this->assertTextNotContains('"Model1Field"', $result); $this->assertTextNotContains('"Model1Field"', $result);
} }
/**
* Test that radio() accepts an array for label
*
* @return void
*/
public function testRadioLabelArray() {
$result = $this->Form->input('Model.field', array(
'type' => 'radio',
'legend' => false,
'label' => array(
'class' => 'checkbox float-left',
),
'options' => array('1' => 'Option A', '2' => 'Option B.')
));
$this->assertTextContains(
'<label for="ModelField1" class="checkbox float-left">Option A</label>',
$result
);
}
/** /**
* testSelect method * testSelect method
* *

View file

@ -610,7 +610,7 @@ class RssHelperTest extends CakeTestCase {
$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile); $this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
if (50300 <= PHP_VERSION_ID) { if (PHP_VERSION_ID >= 50300) {
clearstatcache(true, $tmpFile); clearstatcache(true, $tmpFile);
} else { } else {
clearstatcache(); clearstatcache();

View file

@ -36,25 +36,149 @@ class JsonViewTest extends CakeTestCase {
} }
/** /**
* testRenderWithoutView method * Generates testRenderWithoutView data.
*
* Note: array($data, $serialize, expected)
* *
* @return void * @return void
*/ */
public function testRenderWithoutView() { public static function renderWithoutViewProvider() {
$Request = new CakeRequest(); return array(
$Response = new CakeResponse(); // Test render with a valid string in _serialize.
$Controller = new Controller($Request, $Response); array(
$data = array('user' => 'fake', 'list' => array('item1', 'item2')); array('data' => array('user' => 'fake', 'list' => array('item1', 'item2'))),
$Controller->set(array('data' => $data, '_serialize' => 'data')); 'data',
$View = new JsonView($Controller); json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')))
$output = $View->render(false); ),
$this->assertSame(json_encode($data), $output); // Test render with a string with an invalid key in _serialize.
$this->assertSame('application/json', $Response->type()); array(
array('data' => array('user' => 'fake', 'list' => array('item1', 'item2'))),
'no_key',
json_encode(null)
),
// Test render with a valid array in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('no', 'user'),
json_encode(array('no' => 'nope', 'user' => 'fake'))
),
// Test render with an empty array in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array(),
json_encode(null)
),
// Test render with a valid array with an invalid key in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('no', 'user', 'no_key'),
json_encode(array('no' => 'nope', 'user' => 'fake'))
),
// Test render with a valid array with only an invalid key in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('no_key'),
json_encode(null)
),
// Test render with Null in _serialize (unset).
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
null,
null
),
// Test render with False in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
false,
json_encode(null)
),
// Test render with True in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
true,
json_encode(null)
),
// Test render with empty string in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
'',
json_encode(null)
),
// Test render with a valid array in _serialize and alias.
array(
array('original_name' => 'my epic name', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('new_name' => 'original_name', 'user'),
json_encode(array('new_name' => 'my epic name', 'user' => 'fake'))
),
// Test render with an a valid array in _serialize and alias of a null value.
array(
array('null' => null),
array('null'),
json_encode(array('null' => null))
),
// Test render with a False value to be serialized.
array(
array('false' => false),
'false',
json_encode(false)
),
// Test render with a True value to be serialized.
array(
array('true' => true),
'true',
json_encode(true)
),
// Test render with an empty string value to be serialized.
array(
array('empty' => ''),
'empty',
json_encode('')
),
// Test render with a zero value to be serialized.
array(
array('zero' => 0),
'zero',
json_encode(0)
),
);
} }
/** /**
* Test that rendering with _serialize does not load helpers * Test render with a valid string in _serialize.
*
* @dataProvider renderWithoutViewProvider
* @return void
*/
public function testRenderWithoutView($data, $serialize, $expected) {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->set($data);
$Controller->set('_serialize', $serialize);
$View = new JsonView($Controller);
$output = $View->render(false);
$this->assertSame($expected, $output);
}
/**
* Test that rendering with _serialize does not load helpers.
* *
* @return void * @return void
*/ */
@ -62,54 +186,18 @@ class JsonViewTest extends CakeTestCase {
$Request = new CakeRequest(); $Request = new CakeRequest();
$Response = new CakeResponse(); $Response = new CakeResponse();
$Controller = new Controller($Request, $Response); $Controller = new Controller($Request, $Response);
$Controller->helpers = array('Html'); $Controller->helpers = array('Html');
$Controller->set(array( $Controller->set(array(
'_serialize' => 'tags', 'tags' => array('cakephp', 'framework'),
'tags' => array('cakephp', 'framework') '_serialize' => 'tags'
)); ));
$View = new JsonView($Controller); $View = new JsonView($Controller);
$View->render(); $View->render();
$this->assertFalse(isset($View->Html), 'No helper loaded.'); $this->assertFalse(isset($View->Html), 'No helper loaded.');
} }
/**
* Test render with an array in _serialize
*
* @return void
*/
public function testRenderWithoutViewMultiple() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2'));
$Controller->set($data);
$Controller->set('_serialize', array('no', 'user'));
$View = new JsonView($Controller);
$output = $View->render(false);
$this->assertSame(json_encode(array('no' => $data['no'], 'user' => $data['user'])), $output);
$this->assertSame('application/json', $Response->type());
}
/**
* Test render with an array in _serialize and alias
*
* @return void
*/
public function testRenderWithoutViewMultipleAndAlias() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array('original_name' => 'my epic name', 'user' => 'fake', 'list' => array('item1', 'item2'));
$Controller->set($data);
$Controller->set('_serialize', array('new_name' => 'original_name', 'user'));
$View = new JsonView($Controller);
$output = $View->render(false);
$this->assertSame(json_encode(array('new_name' => $data['original_name'], 'user' => $data['user'])), $output);
$this->assertSame('application/json', $Response->type());
}
/** /**
* testJsonpResponse method * testJsonpResponse method
* *
@ -119,8 +207,13 @@ class JsonViewTest extends CakeTestCase {
$Request = new CakeRequest(); $Request = new CakeRequest();
$Response = new CakeResponse(); $Response = new CakeResponse();
$Controller = new Controller($Request, $Response); $Controller = new Controller($Request, $Response);
$data = array('user' => 'fake', 'list' => array('item1', 'item2')); $data = array('user' => 'fake', 'list' => array('item1', 'item2'));
$Controller->set(array('data' => $data, '_serialize' => 'data', '_jsonp' => true)); $Controller->set(array(
'data' => $data,
'_serialize' => 'data',
'_jsonp' => true
));
$View = new JsonView($Controller); $View = new JsonView($Controller);
$output = $View->render(false); $output = $View->render(false);
@ -141,11 +234,43 @@ class JsonViewTest extends CakeTestCase {
} }
/** /**
* testRenderWithView method * Test render with a View file specified.
* *
* @return void * @return void
*/ */
public function testRenderWithView() { public function testRenderWithView() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
));
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->name = $Controller->viewPath = 'Posts';
$data = array(
'User' => array(
'username' => 'fake'
),
'Item' => array(
array('name' => 'item1'),
array('name' => 'item2')
)
);
$Controller->set('user', $data);
$View = new JsonView($Controller);
$output = $View->render('index');
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => null));
$this->assertSame($expected, $output);
$this->assertSame('application/json', $Response->type());
}
/**
* Test render with a View file specified and named parameters.
*
* @return void
*/
public function testRenderWithViewAndNamed() {
App::build(array( App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS) 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
)); ));
@ -183,5 +308,4 @@ class JsonViewTest extends CakeTestCase {
$this->assertSame($expected, $output); $this->assertSame($expected, $output);
$this->assertSame('application/javascript', $Response->type()); $this->assertSame('application/javascript', $Response->type());
} }
} }

View file

@ -97,7 +97,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
$urlExtra = '&plugin=' . $plugin; $urlExtra = '&plugin=' . $plugin;
} }
if (1 > count($testCases)) { if (count($testCases) < 1) {
$buffer .= "<strong>EMPTY</strong>"; $buffer .= "<strong>EMPTY</strong>";
} }

View file

@ -161,7 +161,7 @@ class CakeTextReporter extends CakeBaseReporter {
$urlExtra = '&plugin=' . $plugin; $urlExtra = '&plugin=' . $plugin;
} }
if (1 > count($testCases)) { if (count($testCases) < 1) {
$buffer .= 'EMPTY'; $buffer .= 'EMPTY';
echo $buffer; echo $buffer;
} }

View file

@ -591,7 +591,7 @@ class Set {
} }
} }
return $tmp; return $tmp;
} elseif (false !== strpos($key, '{') && false !== strpos($key, '}')) { } elseif (strpos($key, '{') !== false && strpos($key, '}') !== false) {
$pattern = substr($key, 1, -1); $pattern = substr($key, 1, -1);
foreach ($data as $j => $val) { foreach ($data as $j => $val) {

View file

@ -135,8 +135,11 @@ class JsonView extends View {
if (is_numeric($alias)) { if (is_numeric($alias)) {
$alias = $key; $alias = $key;
} }
$data[$alias] = $this->viewVars[$key]; if (array_key_exists($key, $this->viewVars)) {
$data[$alias] = $this->viewVars[$key];
}
} }
$data = !empty($data) ? $data : null;
} else { } else {
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; $data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
} }