Ejemplo n.º 1
0
 /**
  * testSaveAssociatedValidateFirst method
  *
  * @return void
  */
 public function testSaveAssociatedValidateFirst()
 {
     $this->loadFixtures('Boat', 'Comment', 'Attachment');
     $model = new Boat();
     $model->deleteAll(true);
     $model->Comment->validate = array('comment' => 'notBlank');
     $result = $model->saveAssociated(array('Boat' => array('title' => 'Post with Author', 'body' => 'This post will be saved author'), 'Comment' => array(array('comment' => 'First new comment'), array('comment' => ''))), array('validate' => 'first'));
     $this->assertFalse($result);
     $result = $model->find('all');
     $this->assertSame(array(), $result);
     $expected = array('Comment' => array(1 => array('comment' => array('This field cannot be left blank'))));
     $this->assertEquals($expected['Comment'], $model->Comment->validationErrors);
     $this->assertSame($model->Comment->find('count'), 0);
     $result = $model->saveAssociated(array('Boat' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array(array('comment' => 'Only new comment', 'user_id' => 2))), array('validate' => 'first'));
     $this->assertTrue($result);
     $result = $model->Comment->find('all');
     $this->assertSame(count($result), 1);
     $result = Hash::extract($result, '{n}.Comment.article_id');
     $this->assertEquals(4, $result[0]);
     $model->deleteAll(true);
     $data = array('Boat' => array('title' => 'Post with Author saveAlled from comment', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array('comment' => 'Only new comment', 'user_id' => 2));
     $result = $model->Comment->saveAssociated($data, array('validate' => 'first'));
     $this->assertFalse(empty($result));
     $result = $model->find('all');
     $this->assertEquals('Post with Author saveAlled from comment', $result[0]['Boat']['title']);
     $this->assertEquals('Only new comment', $result[0]['Comment'][0]['comment']);
 }
Ejemplo n.º 2
0
 /**
  * testDeleteLinks method
  *
  * @return void
  */
 public function testDeleteLinks()
 {
     $this->loadFixtures('Boat', 'boatsTag', 'Tag');
     $TestModel = new Boat();
     $result = $TestModel->boatsTag->find('all');
     $expected = array(array('boatsTag' => array('article_id' => '1', 'tag_id' => '1')), array('boatsTag' => array('article_id' => '1', 'tag_id' => '2')), array('boatsTag' => array('article_id' => '2', 'tag_id' => '1')), array('boatsTag' => array('article_id' => '2', 'tag_id' => '3')));
     $this->assertEquals($expected, $result);
     $TestModel->delete(1);
     $result = $TestModel->boatsTag->find('all');
     $expected = array(array('boatsTag' => array('article_id' => '2', 'tag_id' => '1')), array('boatsTag' => array('article_id' => '2', 'tag_id' => '3')));
     $this->assertEquals($expected, $result);
     $result = $TestModel->deleteAll(array('Boat.user_id' => 999));
     $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
 }