/** * Tests that altering data in a beforeValidate callback will lead to saving those * values in database, this time with belongsTo associations * * @return void */ public function testValidateFirstAssociatedWithBeforeValidate2() { $this->loadFixtures('Article', 'User'); $model = new CustomArticle(); $model->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => true))); $data = array('User' => array('user' => 'foo', 'password' => 'bar'), 'CustomArticle' => array('body' => 'a test')); $result = $model->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $this->assertEquals('foo', $model->field('title', array('body' => 'a test'))); }
/** * Tests that altering data in a beforeValidate callback will lead to saving those * values in database * * @return void */ public function testValidateFirstWithBeforeValidate() { $this->loadFixtures('Article', 'User'); $model = new CustomArticle(); $model->validate = array('title' => array('notempty' => array('rule' => 'notEmpty', 'required' => true, 'allowEmpty' => false))); $data = array('CustomArticle' => array('body' => 'foo0')); $result = $model->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $this->assertFalse($model->findMethods['unPublished'], 'beforeValidate was run twice'); $model->findMethods['unPublished'] = true; $data = array('CustomArticle' => array('body' => 'foo1')); $result = $model->saveAll($data, array('validate' => 'first', 'deep' => true)); $this->assertTrue($result); $title = $model->field('title', array('body' => 'foo1')); $this->assertEquals('foo', $title); $this->assertFalse($model->findMethods['unPublished'], 'beforeValidate was run twice'); $data = array(array('body' => 'foo2'), array('body' => 'foo3'), array('body' => 'foo4')); $result = $model->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $result = $model->saveAll($data, array('validate' => 'first', 'deep' => true)); $this->assertTrue($result); $this->assertEquals('foo', $model->field('title', array('body' => 'foo2'))); $this->assertEquals('foo', $model->field('title', array('body' => 'foo3'))); $this->assertEquals('foo', $model->field('title', array('body' => 'foo4'))); }