@@ 4653-4724 (lines=72) @@ | ||
4650 | * |
|
4651 | * @return void |
|
4652 | */ |
|
4653 | public function testSaveAllValidateFirst() { |
|
4654 | $this->loadFixtures('Article', 'Comment', 'Attachment', 'User', 'ArticlesTag', 'Tag'); |
|
4655 | $model = new Article(); |
|
4656 | $model->deleteAll(true); |
|
4657 | ||
4658 | $model->Comment->validate = array('comment' => 'notEmpty'); |
|
4659 | $result = $model->saveAll(array( |
|
4660 | 'Article' => array( |
|
4661 | 'title' => 'Post with Author', |
|
4662 | 'body' => 'This post will be saved author' |
|
4663 | ), |
|
4664 | 'Comment' => array( |
|
4665 | array('comment' => 'First new comment'), |
|
4666 | array('comment' => '') |
|
4667 | ) |
|
4668 | ), array('validate' => 'first')); |
|
4669 | ||
4670 | $this->assertFalse($result); |
|
4671 | ||
4672 | $result = $model->find('all'); |
|
4673 | $this->assertSame(array(), $result); |
|
4674 | $expected = array('Comment' => array( |
|
4675 | 1 => array('comment' => array('This field cannot be left blank')) |
|
4676 | )); |
|
4677 | ||
4678 | $this->assertEquals($expected['Comment'], $model->Comment->validationErrors); |
|
4679 | ||
4680 | $this->assertSame($model->Comment->find('count'), 0); |
|
4681 | ||
4682 | $result = $model->saveAll( |
|
4683 | array( |
|
4684 | 'Article' => array( |
|
4685 | 'title' => 'Post with Author', |
|
4686 | 'body' => 'This post will be saved with an author', |
|
4687 | 'user_id' => 2 |
|
4688 | ), |
|
4689 | 'Comment' => array( |
|
4690 | array( |
|
4691 | 'comment' => 'Only new comment', |
|
4692 | 'user_id' => 2 |
|
4693 | ))), |
|
4694 | array('validate' => 'first') |
|
4695 | ); |
|
4696 | ||
4697 | $this->assertTrue($result); |
|
4698 | ||
4699 | $result = $model->Comment->find('all'); |
|
4700 | $this->assertSame(count($result), 1); |
|
4701 | $result = Hash::extract($result, '{n}.Comment.article_id'); |
|
4702 | $this->assertEquals(4, $result[0]); |
|
4703 | ||
4704 | $model->deleteAll(true); |
|
4705 | $data = array( |
|
4706 | 'Article' => array( |
|
4707 | 'title' => 'Post with Author saveAlled from comment', |
|
4708 | 'body' => 'This post will be saved with an author', |
|
4709 | 'user_id' => 2 |
|
4710 | ), |
|
4711 | 'Comment' => array( |
|
4712 | 'comment' => 'Only new comment', 'user_id' => 2 |
|
4713 | )); |
|
4714 | ||
4715 | $result = $model->Comment->saveAll($data, array('validate' => 'first')); |
|
4716 | $this->assertFalse(empty($result)); |
|
4717 | ||
4718 | $result = $model->find('all'); |
|
4719 | $this->assertEquals( |
|
4720 | $result[0]['Article']['title'], |
|
4721 | 'Post with Author saveAlled from comment' |
|
4722 | ); |
|
4723 | $this->assertEquals('Only new comment', $result[0]['Comment'][0]['comment']); |
|
4724 | } |
|
4725 | ||
4726 | /** |
|
4727 | * test saveAll()'s return is correct when using atomic = false and validate = first. |
|
@@ 6062-6133 (lines=72) @@ | ||
6059 | * |
|
6060 | * @return void |
|
6061 | */ |
|
6062 | public function testSaveAssociatedValidateFirst() { |
|
6063 | $this->loadFixtures('Article', 'Comment', 'Attachment'); |
|
6064 | $model = new Article(); |
|
6065 | $model->deleteAll(true); |
|
6066 | ||
6067 | $model->Comment->validate = array('comment' => 'notEmpty'); |
|
6068 | $result = $model->saveAssociated(array( |
|
6069 | 'Article' => array( |
|
6070 | 'title' => 'Post with Author', |
|
6071 | 'body' => 'This post will be saved author' |
|
6072 | ), |
|
6073 | 'Comment' => array( |
|
6074 | array('comment' => 'First new comment'), |
|
6075 | array('comment' => '') |
|
6076 | ) |
|
6077 | ), array('validate' => 'first')); |
|
6078 | ||
6079 | $this->assertFalse($result); |
|
6080 | ||
6081 | $result = $model->find('all'); |
|
6082 | $this->assertSame(array(), $result); |
|
6083 | $expected = array('Comment' => array( |
|
6084 | 1 => array('comment' => array('This field cannot be left blank')) |
|
6085 | )); |
|
6086 | ||
6087 | $this->assertEquals($expected['Comment'], $model->Comment->validationErrors); |
|
6088 | ||
6089 | $this->assertSame($model->Comment->find('count'), 0); |
|
6090 | ||
6091 | $result = $model->saveAssociated( |
|
6092 | array( |
|
6093 | 'Article' => array( |
|
6094 | 'title' => 'Post with Author', |
|
6095 | 'body' => 'This post will be saved with an author', |
|
6096 | 'user_id' => 2 |
|
6097 | ), |
|
6098 | 'Comment' => array( |
|
6099 | array( |
|
6100 | 'comment' => 'Only new comment', |
|
6101 | 'user_id' => 2 |
|
6102 | ))), |
|
6103 | array('validate' => 'first') |
|
6104 | ); |
|
6105 | ||
6106 | $this->assertTrue($result); |
|
6107 | ||
6108 | $result = $model->Comment->find('all'); |
|
6109 | $this->assertSame(count($result), 1); |
|
6110 | $result = Hash::extract($result, '{n}.Comment.article_id'); |
|
6111 | $this->assertEquals(4, $result[0]); |
|
6112 | ||
6113 | $model->deleteAll(true); |
|
6114 | $data = array( |
|
6115 | 'Article' => array( |
|
6116 | 'title' => 'Post with Author saveAlled from comment', |
|
6117 | 'body' => 'This post will be saved with an author', |
|
6118 | 'user_id' => 2 |
|
6119 | ), |
|
6120 | 'Comment' => array( |
|
6121 | 'comment' => 'Only new comment', 'user_id' => 2 |
|
6122 | )); |
|
6123 | ||
6124 | $result = $model->Comment->saveAssociated($data, array('validate' => 'first')); |
|
6125 | $this->assertFalse(empty($result)); |
|
6126 | ||
6127 | $result = $model->find('all'); |
|
6128 | $this->assertEquals( |
|
6129 | 'Post with Author saveAlled from comment', |
|
6130 | $result[0]['Article']['title'] |
|
6131 | ); |
|
6132 | $this->assertEquals('Only new comment', $result[0]['Comment'][0]['comment']); |
|
6133 | } |
|
6134 | ||
6135 | /** |
|
6136 | * test saveMany()'s return is correct when using atomic = false and validate = first. |