Skip to content
Permalink
Browse files

Added afterValidate callback to maintain consistency across all other…

… callbacks in the model layer
  • Loading branch information...
lorenzo committed May 7, 2012
1 parent 7bfc47a commit 52c7b2383c5b435476a401792417948badedd045
@@ -744,6 +744,7 @@ public function implementedEvents() {
'Model.beforeFind' => array('callable' => 'beforeFind', 'passParams' => true),
'Model.afterFind' => array('callable' => 'afterFind', 'passParams' => true),
'Model.beforeValidate' => array('callable' => 'beforeValidate', 'passParams' => true),
'Model.afterValidate' => array('callable' => 'afterValidate'),
'Model.beforeSave' => array('callable' => 'beforeSave', 'passParams' => true),
'Model.afterSave' => array('callable' => 'afterSave', 'passParams' => true),
'Model.beforeDelete' => array('callable' => 'beforeDelete', 'passParams' => true),
@@ -3311,6 +3312,14 @@ public function beforeValidate($options = array()) {
return true;
}
/**
* Called after data has been checked for errors
*
* @return void
*/
public function afterValidate() {
}
/**
* Called when a DataSource-level error occurs.
*
@@ -229,6 +229,7 @@ public function errors($options = array()) {
}
}
$model->getEventManager()->dispatch(new CakeEvent('Model.afterValidate', $model));
return $model->validationErrors;
}
@@ -1880,4 +1880,19 @@ public function testRemoveRule() {
$this->assertFalse(isset($Validator['other']['numeric']));
$this->assertTrue(isset($Validator['other']['range']));
}
/**
* Tests validation callbacks are triggered
*
* @return void
*/
public function testValidateCallbacks() {
$TestModel = $this->getMock('Article', array('beforeValidate', 'afterValidate'));
$TestModel->expects($this->once())->method('beforeValidate');
$TestModel->expects($this->once())->method('afterValidate');
$TestModel->set(array('title' => '', 'body' => 'body'));
$TestModel->validates();
}
}
@@ -313,4 +313,4 @@ public function testRemoveRule() {
$this->assertFalse(isset($Set['other']));
}
}
}

0 comments on commit 52c7b23

Please sign in to comment.
You can’t perform that action at this time.