mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
add test for saveAll deep
This commit is contained in:
parent
714ec60507
commit
247f5522c6
1 changed files with 56 additions and 0 deletions
|
@ -6605,6 +6605,62 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue