/**
  * testDeleteLinks method
  *
  * @return void
  */
 public function testDeleteLinks()
 {
     $this->loadFixtures('Article', 'ArticlesTag', 'Tag');
     $TestModel = new Article();
     $result = $TestModel->ArticlesTag->find('all');
     $expected = array(array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')), array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')), array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')), array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3')));
     $this->assertEquals($expected, $result);
     $TestModel->delete(1);
     $result = $TestModel->ArticlesTag->find('all');
     $expected = array(array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')), array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3')));
     $this->assertEquals($expected, $result);
     $result = $TestModel->deleteAll(array('Article.user_id' => 999));
     $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
 }
 /**
  * testSaveAssociatedValidateFirst method
  *
  * @return void
  */
 public function testSaveAssociatedValidateFirst()
 {
     $this->loadFixtures('Article', 'Comment', 'Attachment');
     $model = new Article();
     $model->deleteAll(true);
     $model->Comment->validate = array('comment' => 'notEmpty');
     $result = $model->saveAssociated(array('Article' => 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('Article' => 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->assertSame($result, true);
     $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('Article' => 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]['Article']['title']);
     $this->assertEquals('Only new comment', $result[0]['Comment'][0]['comment']);
 }
Example #3
0
 public function testGetIssetHasManyAssociationAttribute()
 {
     $this->fixtures('users', 'articles');
     $user = User::find(2);
     $this->assertFalse(empty($user->articles));
     // remove all associated objects & recheck
     Article::deleteAll();
     $user = User::find(2);
     $this->assertTrue(empty($user->articles));
 }