mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix whitelist being empty during afterSave.
whitelist should only be reset after afterSave event. Refs #6028
This commit is contained in:
parent
534154f4f1
commit
a9519d39f7
2 changed files with 34 additions and 2 deletions
|
@ -1941,9 +1941,8 @@ class Model extends Object implements CakeEventListener {
|
||||||
$this->_saveMulti($joined, $this->id, $db);
|
$this->_saveMulti($joined, $this->id, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->whitelist = $_whitelist;
|
|
||||||
|
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
|
$this->whitelist = $_whitelist;
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1964,6 +1963,7 @@ class Model extends Object implements CakeEventListener {
|
||||||
|
|
||||||
$this->_clearCache();
|
$this->_clearCache();
|
||||||
$this->validationErrors = array();
|
$this->validationErrors = array();
|
||||||
|
$this->whitelist = $_whitelist;
|
||||||
$this->data = false;
|
$this->data = false;
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
|
|
|
@ -387,6 +387,38 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
$this->assertEquals($whitelist, $model->whitelist);
|
$this->assertEquals($whitelist, $model->whitelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test save() resets the whitelist after afterSave
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSaveResetWhitelistOnSuccess() {
|
||||||
|
$this->loadFixtures('Post');
|
||||||
|
|
||||||
|
$callback = array($this, 'callbackForWhitelistReset');
|
||||||
|
$model = ClassRegistry::init('Post');
|
||||||
|
$model->whitelist = array('author_id', 'title', 'body');
|
||||||
|
$model->getEventManager()->attach($callback, 'Model.afterSave');
|
||||||
|
$data = array(
|
||||||
|
'title' => 'New post',
|
||||||
|
'body' => 'Post body',
|
||||||
|
'author_id' => 1
|
||||||
|
);
|
||||||
|
$result = $model->save($data);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for testing whitelist in afterSave
|
||||||
|
*
|
||||||
|
* @param Model $model The model having save called.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function callbackForWhitelistReset($event) {
|
||||||
|
$expected = array('author_id', 'title', 'body', 'updated', 'created');
|
||||||
|
$this->assertEquals($expected, $event->subject()->whitelist);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSaveWithCounterCache method
|
* testSaveWithCounterCache method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue