Skip to content

Commit

Permalink
add test for saveAll deep
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Mar 20, 2012
1 parent 714ec60 commit 247f552
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -6605,6 +6605,62 @@ public function testSaveAllDeepHasManyBelongsTo() {
$this->assertEquals($expected, $result);
}

/**
* testSaveAllDeepHasManyhasMany method
*
* return @void
*/
public function testSaveAllDeepHasManyHasMany() {
$this->loadFixtures('Article', 'Comment', 'User', 'Attachment');
$TestModel = new Article();
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
$TestModel->Comment->unbindModel(array('hasOne' => array('Attachment')), false);
$TestModel->Comment->bindModel(array('hasMany' => array('Attachment')), false);

$this->db->truncate($TestModel);
$this->db->truncate(new Comment());
$this->db->truncate(new Attachment());

$result = $TestModel->saveAll(array(
'Article' => array('id' => 2, 'title' => 'I will not save'),
'Comment' => array(
array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1),
array(
'comment' => 'hasmany', 'published' => 'Y', 'user_id' => 5,
'Attachment' => array(
array('attachment' => 'first deep attachment'),
array('attachment' => 'second deep attachment'),
)
)
)
), array('deep' => true));

$result = $TestModel->Comment->find('first', array(
'conditions' => array('Comment.comment' => 'hasmany'),
'fields' => array('id', 'comment', 'published', 'user_id'),
'recursive' => -1
));
$expected = array(
'Comment' => array(
'id' => 2,
'comment' => 'hasmany',
'published' => 'Y',
'user_id' => 5
)
);
$this->assertEquals($expected, $result);

$result = $TestModel->Comment->Attachment->find('all', array(
'fields' => array('attachment', 'comment_id'),
'order' => array('Attachment.id' => 'ASC')
));
$expected = array(
array('Attachment' => array('attachment' => 'first deep attachment', 'comment_id' => 2)),
array('Attachment' => array('attachment' => 'second deep attachment', 'comment_id' => 2)),
);
$this->assertEquals($expected, $result);
}

/**
* testUpdateAllBoolean
*
Expand Down

0 comments on commit 247f552

Please sign in to comment.