| @@ 2987-3031 (lines=45) @@ | ||
| 2984 | * |
|
| 2985 | * @return void |
|
| 2986 | */ |
|
| 2987 | public function testSaveAllHasOne() { |
|
| 2988 | $model = new Comment(); |
|
| 2989 | $model->deleteAll(true); |
|
| 2990 | $this->assertEquals(array(), $model->find('all')); |
|
| 2991 | ||
| 2992 | $model->Attachment->deleteAll(true); |
|
| 2993 | $this->assertEquals(array(), $model->Attachment->find('all')); |
|
| 2994 | ||
| 2995 | $this->assertTrue($model->saveAll(array( |
|
| 2996 | 'Comment' => array( |
|
| 2997 | 'comment' => 'Comment with attachment', |
|
| 2998 | 'article_id' => 1, |
|
| 2999 | 'user_id' => 1 |
|
| 3000 | ), |
|
| 3001 | 'Attachment' => array( |
|
| 3002 | 'attachment' => 'some_file.zip' |
|
| 3003 | )))); |
|
| 3004 | $result = $model->find('all', array('fields' => array( |
|
| 3005 | 'Comment.id', 'Comment.comment', 'Attachment.id', |
|
| 3006 | 'Attachment.comment_id', 'Attachment.attachment' |
|
| 3007 | ))); |
|
| 3008 | $expected = array(array( |
|
| 3009 | 'Comment' => array( |
|
| 3010 | 'id' => '1', |
|
| 3011 | 'comment' => 'Comment with attachment' |
|
| 3012 | ), |
|
| 3013 | 'Attachment' => array( |
|
| 3014 | 'id' => '1', |
|
| 3015 | 'comment_id' => '1', |
|
| 3016 | 'attachment' => 'some_file.zip' |
|
| 3017 | ))); |
|
| 3018 | $this->assertEquals($expected, $result); |
|
| 3019 | ||
| 3020 | $model->Attachment->bindModel(array('belongsTo' => array('Comment')), false); |
|
| 3021 | $data = array( |
|
| 3022 | 'Comment' => array( |
|
| 3023 | 'comment' => 'Comment with attachment', |
|
| 3024 | 'article_id' => 1, |
|
| 3025 | 'user_id' => 1 |
|
| 3026 | ), |
|
| 3027 | 'Attachment' => array( |
|
| 3028 | 'attachment' => 'some_file.zip' |
|
| 3029 | )); |
|
| 3030 | $this->assertTrue($model->saveAll($data, array('validate' => 'first'))); |
|
| 3031 | } |
|
| 3032 | ||
| 3033 | /** |
|
| 3034 | * testSaveAllBelongsTo method |
|
| @@ 5193-5237 (lines=45) @@ | ||
| 5190 | * |
|
| 5191 | * @return void |
|
| 5192 | */ |
|
| 5193 | public function testSaveAssociatedHasOne() { |
|
| 5194 | $model = new Comment(); |
|
| 5195 | $model->deleteAll(true); |
|
| 5196 | $this->assertEquals(array(), $model->find('all')); |
|
| 5197 | ||
| 5198 | $model->Attachment->deleteAll(true); |
|
| 5199 | $this->assertEquals(array(), $model->Attachment->find('all')); |
|
| 5200 | ||
| 5201 | $this->assertTrue($model->saveAssociated(array( |
|
| 5202 | 'Comment' => array( |
|
| 5203 | 'comment' => 'Comment with attachment', |
|
| 5204 | 'article_id' => 1, |
|
| 5205 | 'user_id' => 1 |
|
| 5206 | ), |
|
| 5207 | 'Attachment' => array( |
|
| 5208 | 'attachment' => 'some_file.zip' |
|
| 5209 | )))); |
|
| 5210 | $result = $model->find('all', array('fields' => array( |
|
| 5211 | 'Comment.id', 'Comment.comment', 'Attachment.id', |
|
| 5212 | 'Attachment.comment_id', 'Attachment.attachment' |
|
| 5213 | ))); |
|
| 5214 | $expected = array(array( |
|
| 5215 | 'Comment' => array( |
|
| 5216 | 'id' => '1', |
|
| 5217 | 'comment' => 'Comment with attachment' |
|
| 5218 | ), |
|
| 5219 | 'Attachment' => array( |
|
| 5220 | 'id' => '1', |
|
| 5221 | 'comment_id' => '1', |
|
| 5222 | 'attachment' => 'some_file.zip' |
|
| 5223 | ))); |
|
| 5224 | $this->assertEquals($expected, $result); |
|
| 5225 | ||
| 5226 | $model->Attachment->bindModel(array('belongsTo' => array('Comment')), false); |
|
| 5227 | $data = array( |
|
| 5228 | 'Comment' => array( |
|
| 5229 | 'comment' => 'Comment with attachment', |
|
| 5230 | 'article_id' => 1, |
|
| 5231 | 'user_id' => 1 |
|
| 5232 | ), |
|
| 5233 | 'Attachment' => array( |
|
| 5234 | 'attachment' => 'some_file.zip' |
|
| 5235 | )); |
|
| 5236 | $this->assertTrue($model->saveAssociated($data, array('validate' => 'first'))); |
|
| 5237 | } |
|
| 5238 | ||
| 5239 | /** |
|
| 5240 | * testSaveAssociatedBelongsTo method |
|