Merge branch 'master' into 2.5

This commit is contained in:
mark_story 2013-09-12 19:47:13 -04:00
commit a2bd91638e
50 changed files with 186 additions and 87 deletions

View file

@ -415,7 +415,10 @@ class FileEngine extends CacheEngine {
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($contents as $object) {
$containsGroup = strpos($object->getPathName(), DS . $group . DS) !== false;
$hasPrefix = true;
if (strlen($this->settings['prefix']) !== 0) {
$hasPrefix = strpos($object->getBaseName(), $this->settings['prefix']) === 0;
}
if ($object->isFile() && $containsGroup && $hasPrefix) {
$path = $object->getPathName();
$object = null;

View file

@ -93,7 +93,7 @@
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->request->is(array('post', 'put'))) {
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));

View file

@ -361,6 +361,10 @@ class PaginatorComponent extends Component {
* @return array An array of options with sort + direction removed and replaced with order if possible.
*/
public function validateSort(Model $object, array $options, array $whitelist = array()) {
if (empty($options['order']) && is_array($object->order)) {
$options['order'] = $object->order;
}
if (isset($options['sort'])) {
$direction = null;
if (isset($options['direction'])) {
@ -401,9 +405,7 @@ class PaginatorComponent extends Component {
}
$options['order'] = $order;
}
if (empty($options['order']) && !empty($object->order)) {
$options['order'] = $object->order;
}
return $options;
}

View file

@ -226,7 +226,7 @@ class SecurityComponent extends Component {
$this->_secureRequired($controller);
$this->_authRequired($controller);
$isPost = ($this->request->is('post') || $this->request->is('put'));
$isPost = $this->request->is(array('post', 'put'));
$isNotRequestAction = (
!isset($controller->request->params['requested']) ||
$controller->request->params['requested'] != 1

View file

@ -97,9 +97,10 @@ class AclBehavior extends ModelBehavior {
*
* @param Model $model
* @param boolean $created True if this is a new record
* @param array $options Options passed from Model::save().
* @return void
*/
public function afterSave(Model $model, $created) {
public function afterSave(Model $model, $created, $options = array()) {
$types = $this->_typeMaps[$this->settings[$model->name]['type']];
if (!is_array($types)) {
$types = array($types);

View file

@ -275,7 +275,7 @@ class TranslateBehavior extends ModelBehavior {
* @param boolean $primary Did the find originate on $model.
* @return array Modified results
*/
public function afterFind(Model $Model, $results, $primary) {
public function afterFind(Model $Model, $results, $primary = false) {
$Model->virtualFields = $this->runtime[$Model->alias]['virtualFields'];
$this->runtime[$Model->alias]['virtualFields'] = $this->runtime[$Model->alias]['fields'] = array();
$locale = $this->_getLocale($Model);
@ -408,9 +408,10 @@ class TranslateBehavior extends ModelBehavior {
*
* @param Model $Model Model the callback is called on
* @param boolean $created Whether or not the save created a record.
* @param array $options Options passed from Model::save().
* @return void
*/
public function afterSave(Model $Model, $created) {
public function afterSave(Model $Model, $created, $options = array()) {
if (!isset($this->runtime[$Model->alias]['beforeValidate']) && !isset($this->runtime[$Model->alias]['beforeSave'])) {
return true;
}

View file

@ -88,9 +88,10 @@ class TreeBehavior extends ModelBehavior {
*
* @param Model $Model Model instance.
* @param boolean $created indicates whether the node just saved was created or updated
* @param array $options Options passed from Model::save().
* @return boolean true on success, false on failure
*/
public function afterSave(Model $Model, $created) {
public function afterSave(Model $Model, $created, $options = array()) {
extract($this->settings[$Model->alias]);
if ($created) {
if ((isset($Model->data[$Model->alias][$parent])) && $Model->data[$Model->alias][$parent]) {

View file

@ -538,7 +538,8 @@ class Sqlserver extends DboSource {
WHERE _cake_paging_.{$rowCounter} > {$offset}
ORDER BY _cake_paging_.{$rowCounter}
";
} elseif (strpos($limit, 'FETCH') !== false) {
}
if (strpos($limit, 'FETCH') !== false) {
return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}";
}
return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}";
@ -571,9 +572,10 @@ class Sqlserver extends DboSource {
* @return string Quoted and escaped data
*/
public function value($data, $column = null) {
if (is_array($data) || is_object($data)) {
if ($data === null || is_array($data) || is_object($data)) {
return parent::value($data, $column);
} elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) {
}
if (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) {
return $data;
}

View file

@ -3392,12 +3392,12 @@ class Model extends Object implements CakeEventListener {
* Called before each find operation. Return false if you want to halt the find
* call, otherwise return the (modified) query data.
*
* @param array $queryData Data used to execute this query, i.e. conditions, order, etc.
* @param array $query Data used to execute this query, i.e. conditions, order, etc.
* @return mixed true if the operation should continue, false if it should abort; or, modified
* $queryData to continue with new $queryData
* $query to continue with new $query
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforefind
*/
public function beforeFind($queryData) {
public function beforeFind($query) {
return true;
}
@ -3418,9 +3418,10 @@ class Model extends Object implements CakeEventListener {
* Called before each save operation, after validation. Return a non-true result
* to halt the save.
*
* @param array $options
* @param array $options Options passed from Model::save().
* @return boolean True if the operation should continue, false if it should abort
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave
* @see Model::save()
*/
public function beforeSave($options = array()) {
return true;
@ -3430,10 +3431,12 @@ class Model extends Object implements CakeEventListener {
* Called after each successful save operation.
*
* @param boolean $created True if this save created a new record
* @param array $options Options passed from Model::save().
* @return void
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#aftersave
* @see Model::save()
*/
public function afterSave($created) {
public function afterSave($created, $options = array()) {
}
/**

View file

@ -132,7 +132,7 @@ class ModelBehavior extends Object {
* @param boolean $primary Whether this model is being queried directly (vs. being queried as an association)
* @return mixed An array value will replace the value of $results - any other value will be ignored.
*/
public function afterFind(Model $model, $results, $primary) {
public function afterFind(Model $model, $results, $primary = false) {
}
/**
@ -178,9 +178,11 @@ class ModelBehavior extends Object {
*
* @param Model $model Model using this behavior
* @param boolean $created True if this save created a new record
* @param array $options Options passed from Model::save().
* @return boolean
* @see Model::save()
*/
public function afterSave(Model $model, $created) {
public function afterSave(Model $model, $created, $options = array()) {
return true;
}

View file

@ -530,4 +530,24 @@ class FileEngineTest extends CakeTestCase {
$this->assertFalse(Cache::read('test_groups5', 'file_groups2'));
$this->assertEquals('value 3', Cache::read('test_groups6', 'file_groups3'));
}
/**
* Test that clearGroup works with no prefix.
*
* @return void
*/
public function testGroupClearNoPrefix() {
Cache::config('file_groups', array(
'engine' => 'File',
'duration' => 3600,
'prefix' => '',
'groups' => array('group_a', 'group_b')
));
Cache::write('key_1', 'value', 'file_groups');
Cache::write('key_2', 'value', 'file_groups');
Cache::clearGroup('group_a', 'file_groups');
$this->assertFalse(Cache::read('key_1', 'file_groups'), 'Did not delete');
$this->assertFalse(Cache::read('key_2', 'file_groups'), 'Did not delete');
}
}

View file

@ -601,7 +601,26 @@ class PaginatorComponentTest extends CakeTestCase {
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$expected = array('2007-03-18 10:43:23', '2007-03-18 10:41:23', '2007-03-18 10:39:23');
$this->assertEquals($expected, Hash::extract($result, '{n}.PaginatorControllerPost.created'));
$this->assertEquals($Controller->PaginatorControllerPost->order, $this->Controller->request['paging']['PaginatorControllerPost']['order']);
$this->assertEquals(
$Controller->PaginatorControllerPost->order,
$Controller->request->paging['PaginatorControllerPost']['options']['order']
);
$Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertEmpty($result['order']);
$Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
$results = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertEmpty($result['order']);
$Controller->PaginatorControllerPost->order = array(
'PaginatorControllerPost.id',
'PaginatorControllerPost.created' => 'asc'
);
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$expected = array('PaginatorControllerPost.created' => 'asc');
$this->assertEquals($expected, $result['order']);
}
/**

View file

@ -1188,7 +1188,7 @@ class SecurityComponentTest extends CakeTestCase {
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->with(array('post', 'put'))
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
@ -1240,7 +1240,7 @@ class SecurityComponentTest extends CakeTestCase {
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->with(array('post', 'put'))
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
@ -1270,7 +1270,7 @@ class SecurityComponentTest extends CakeTestCase {
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->with(array('post', 'put'))
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';
@ -1326,7 +1326,7 @@ class SecurityComponentTest extends CakeTestCase {
$this->Controller->request = $this->getMock('CakeRequest', array('is'));
$this->Controller->request->expects($this->once())->method('is')
->with('post')
->with(array('post', 'put'))
->will($this->returnValue(true));
$this->Controller->request->params['action'] = 'index';

View file

@ -84,7 +84,7 @@ class TestBehavior extends ModelBehavior {
* @param boolean $primary
* @return void
*/
public function afterFind(Model $model, $results, $primary) {
public function afterFind(Model $model, $results, $primary = false) {
$settings = $this->settings[$model->alias];
if (!isset($settings['afterFind']) || $settings['afterFind'] === 'off') {
return parent::afterFind($model, $results, $primary);
@ -112,7 +112,7 @@ class TestBehavior extends ModelBehavior {
public function beforeSave(Model $model, $options = array()) {
$settings = $this->settings[$model->alias];
if (!isset($settings['beforeSave']) || $settings['beforeSave'] === 'off') {
return parent::beforeSave($model);
return parent::beforeSave($model, $options);
}
switch ($settings['beforeSave']) {
case 'on':
@ -130,12 +130,13 @@ class TestBehavior extends ModelBehavior {
*
* @param Model $model
* @param boolean $created
* @param array $options Options passed from Model::save().
* @return void
*/
public function afterSave(Model $model, $created) {
public function afterSave(Model $model, $created, $options = array()) {
$settings = $this->settings[$model->alias];
if (!isset($settings['afterSave']) || $settings['afterSave'] === 'off') {
return parent::afterSave($model, $created);
return parent::afterSave($model, $created, $options);
}
$string = 'modified after';
if ($created) {
@ -167,7 +168,7 @@ class TestBehavior extends ModelBehavior {
public function beforeValidate(Model $model, $options = array()) {
$settings = $this->settings[$model->alias];
if (!isset($settings['validate']) || $settings['validate'] === 'off') {
return parent::beforeValidate($model);
return parent::beforeValidate($model, $options);
}
switch ($settings['validate']) {
case 'on':

View file

@ -311,6 +311,10 @@ class SqlserverTest extends CakeTestCase {
$expected = "''";
$result = $this->db->value('', 'binary');
$this->assertSame($expected, $result);
$expected = 'NULL';
$result = $this->db->value(null, 'string');
$this->assertSame($expected, $result);
}
/**

View file

@ -1280,4 +1280,61 @@ class DboSourceTest extends CakeTestCase {
$this->assertNotContains($scientificNotation, $result);
}
/**
* Test insertMulti with id position.
*
* @return void
*/
public function testInsertMultiId() {
$this->loadFixtures('Article');
$Article = ClassRegistry::init('Article');
$db = $Article->getDatasource();
$datetime = date('Y-m-d H:i:s');
$data = array(
array(
'user_id' => 1,
'title' => 'test',
'body' => 'test',
'published' => 'N',
'created' => $datetime,
'updated' => $datetime,
'id' => 100,
),
array(
'user_id' => 1,
'title' => 'test 101',
'body' => 'test 101',
'published' => 'N',
'created' => $datetime,
'updated' => $datetime,
'id' => 101,
)
);
$result = $db->insertMulti('articles', array_keys($data[0]), $data);
$this->assertTrue($result, 'Data was saved');
$data = array(
array(
'id' => 102,
'user_id' => 1,
'title' => 'test',
'body' => 'test',
'published' => 'N',
'created' => $datetime,
'updated' => $datetime,
),
array(
'id' => 103,
'user_id' => 1,
'title' => 'test 101',
'body' => 'test 101',
'published' => 'N',
'created' => $datetime,
'updated' => $datetime,
)
);
$result = $db->insertMulti('articles', array_keys($data[0]), $data);
$this->assertTrue($result, 'Data was saved');
}
}

View file

@ -2731,7 +2731,7 @@ class AfterTree extends NumberTree {
*/
public $actsAs = array('Tree');
public function afterSave($created) {
public function afterSave($created, $options = array()) {
if ($created && isset($this->data['AfterTree'])) {
$this->data['AfterTree']['name'] = 'Six and One Half Changed in AfterTree::afterSave() but not in database';
}
@ -3473,7 +3473,7 @@ class TransactionTestModel extends CakeTestModel {
public $useTable = 'samples';
public function afterSave($created) {
public function afterSave($created, $options = array()) {
$data = array(
array('apple_id' => 1, 'name' => 'sample6'),
);
@ -3488,7 +3488,7 @@ class TransactionManyTestModel extends CakeTestModel {
public $useTable = 'samples';
public function afterSave($created) {
public function afterSave($created, $options = array()) {
$data = array(
array('apple_id' => 1, 'name' => 'sample6'),
);

View file

@ -184,11 +184,11 @@ class TestView extends View {
}
/**
* TestAfterHelper class
* TestBeforeAfterHelper class
*
* @package Cake.Test.Case.View
*/
class TestAfterHelper extends Helper {
class TestBeforeAfterHelper extends Helper {
/**
* property property
@ -949,10 +949,10 @@ class ViewTest extends CakeTestCase {
* @return void
*/
public function testBeforeLayout() {
$this->PostsController->helpers = array('Session', 'TestAfter', 'Html');
$this->PostsController->helpers = array('Session', 'TestBeforeAfter', 'Html');
$View = new View($this->PostsController);
$View->render('index');
$this->assertEquals('Valuation', $View->Helpers->TestAfter->property);
$this->assertEquals('Valuation', $View->Helpers->TestBeforeAfter->property);
}
/**
@ -961,7 +961,7 @@ class ViewTest extends CakeTestCase {
* @return void
*/
public function testAfterLayout() {
$this->PostsController->helpers = array('Session', 'TestAfter', 'Html');
$this->PostsController->helpers = array('Session', 'TestBeforeAfter', 'Html');
$this->PostsController->set('variable', 'values');
$View = new View($this->PostsController);

View file

@ -54,7 +54,7 @@
if (!$this->BakeArticle->exists($id)) {
throw new NotFoundException(__('Invalid bake article'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->request->is(array('post', 'put'))) {
if ($this->BakeArticle->save($this->request->data)) {
$this->Session->setFlash(__('The bake article has been saved.'));
return $this->redirect(array('action' => 'index'));

View file

@ -51,7 +51,7 @@
if (!$this->BakeArticle->exists($id)) {
throw new NotFoundException(__('Invalid bake article'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->request->is(array('post', 'put'))) {
if ($this->BakeArticle->save($this->request->data)) {
return $this->flash(__('The bake article has been saved.'), array('action' => 'index'));
}

View file

@ -25,8 +25,6 @@
*/
class TestsAppsController extends AppController {
public $name = 'TestsApps';
public $uses = array();
public $components = array('RequestHandler');

View file

@ -25,8 +25,6 @@
*/
class TestsAppsPostsController extends AppController {
public $name = 'TestsAppsPosts';
public $uses = array('Post');
public $viewPath = 'TestsApps';

View file

@ -34,11 +34,4 @@ class Comment extends AppModel {
*/
public $useTable = 'comments';
/**
* Model name
*
* @var string
*/
public $name = 'Comment';
}

View file

@ -29,8 +29,6 @@ class PersisterOne extends AppModel {
public $useTable = 'posts';
public $name = 'PersisterOne';
public $actsAs = array('PersisterOneBehavior', 'TestPlugin.TestPluginPersisterOne');
public $hasMany = array('Comment', 'TestPlugin.TestPluginComment');

View file

@ -29,8 +29,6 @@ class PersisterTwo extends AppModel {
public $useTable = 'posts';
public $name = 'PersisterTwo';
public $actsAs = array('PersisterOneBehavior', 'TestPlugin.TestPluginPersisterOne');
public $hasMany = array('Comment', 'TestPlugin.TestPluginComment');

View file

@ -29,6 +29,4 @@ class Post extends AppModel {
public $useTable = 'posts';
public $name = 'Post';
}

View file

@ -23,5 +23,5 @@
*
* @package Cake.Test.TestApp.Plugin.TestPlugin.Controller.Component
*/
class OtherComponent extends Object {
class OtherComponent extends Component {
}

View file

@ -19,12 +19,12 @@
*/
/**
* Class TestPluginComponentComponent
* Class TestPluginComponent
*
* @package Cake.Test.TestApp.Plugin.TestPlugin.Controller.Component
*/
class TestPluginComponentComponent extends Object {
class TestPluginComponent extends Component {
public $components = array('TestPlugin.TestPluginOtherComponent');
public $components = array('TestPlugin.TestPluginOther');
}

View file

@ -19,9 +19,9 @@
*/
/**
* Class TestPluginOtherComponentComponent
* Class TestPluginOtherComponent
*
* @package Cake.Test.TestApp.Plugin.TestPlugin.Controller.Component
*/
class TestPluginOtherComponentComponent extends Object {
class TestPluginOtherComponent extends Component {
}

View file

@ -25,8 +25,6 @@
*/
class TestsController extends TestPluginAppController {
public $name = 'Tests';
public $uses = array();
public $helpers = array('TestPlugin.OtherHelper', 'Html');

View file

@ -1 +1 @@
<?php __('This is a translatable string'); ?>
<?php echo __('This is a translatable string'); ?>

View file

@ -1,4 +1,4 @@
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
This email was sent using the TestPlugin.

View file

@ -6,7 +6,7 @@
</head>
<body>
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body>

View file

@ -6,7 +6,7 @@
</head>
<body>
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
<p>このメールは <a href="http://cakephp.org">CakePHP Framework</a> を利用して送信しました。</p>
</body>

View file

@ -6,7 +6,7 @@
</head>
<body>
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
<p>This email was sent using the CakePHP Framework</p>
</body>

View file

@ -1,4 +1,4 @@
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
This email was sent using the CakePHP Framework, http://cakephp.org.

View file

@ -1,4 +1,4 @@
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
CakePHP Framework を使って送信したメールです。 http://cakephp.org.

View file

@ -1 +1 @@
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>

View file

@ -1,2 +1,2 @@
Ajax!
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>

View file

@ -7,7 +7,7 @@
<body>
<!--nocache--><?php $x++; ?><!--/nocache-->
<!--nocache--><?php $x++; ?><!--/nocache-->
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
<!--nocache--><?php echo 'cached count is: ' . $x; ?><!--/nocache-->
</body>
</html>

View file

@ -3,7 +3,7 @@
<?php echo microtime(); ?>
<!--/nocache-->
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
<?php echo $superman; ?>

View file

@ -27,7 +27,7 @@ $cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework
</div>
<div id="content">
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
</div>
<div id="footer">

View file

@ -1,2 +1,2 @@
<?php echo $scripts_for_layout; ?>
<script type="text/javascript"><?php echo $content_for_layout; ?></script>
<script type="text/javascript"><?php echo $this->fetch('content'); ?></script>

View file

@ -1 +1 @@
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>

View file

@ -8,7 +8,7 @@
<p>C. Layout After Test Element But Before Content</p>
<?php $this->log('3. layout after test element but before content') ?>
<!--/nocache-->
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>
<!--nocache-->
<p>E. Layout After Content</p>
<?php $this->log('5. layout after content') ?>

View file

@ -1,5 +1,5 @@
<?php
echo $rss->header();
echo $this->Rss->header();
if (!isset($channel)) {
$channel = array();
@ -8,9 +8,9 @@ if (!isset($channel['title'])) {
$channel['title'] = $title_for_layout;
}
echo $rss->document(
$rss->channel(
array(), $channel, $content_for_layout
echo $this->Rss->document(
$this->Rss->channel(
array(), $channel, $this->fetch('content')
)
);

View file

@ -1,2 +1,2 @@
<?php echo '<?xml version="1.0" encoding="' . Configure::read('App.encoding') . '"?>'; ?>
<?php echo $content_for_layout; ?>
<?php echo $this->fetch('content'); ?>

View file

@ -1,2 +1,2 @@
default test_theme layout
<?php echo $content_for_layout ?>
<?php echo $this->fetch('content') ?>

View file

@ -504,6 +504,8 @@ class View extends Object {
if (empty($content)) {
$content = $this->Blocks->get('content');
} else {
$this->Blocks->set('content', $content);
}
$this->getEventManager()->dispatch(new CakeEvent('View.beforeLayout', $this, array($layoutFileName)));

View file

@ -245,7 +245,7 @@ if (!function_exists('pr')) {
function pr($var) {
if (Configure::read('debug') > 0) {
$template = php_sapi_name() !== 'cli' ? '<pre>%s</pre>' : "\n%s\n";
echo sprintf($template, print_r($var, true));
printf($template, print_r($var, true));
}
}