/** * test custom find method * * @return void */ public function testfindCustom() { $this->loadFixtures('Article'); $Article = new CustomArticle(); $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N'); $Article->create($data); $Article->save(null, false); $this->assertEquals(4, $Article->id); $result = $Article->find('published'); $this->assertEquals(3, count($result)); $result = $Article->find('unPublished'); $this->assertEquals(1, count($result)); }
/** * 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'))); }