Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added unittest for eef87ee.

  • Loading branch information...
commit d9c48b0d34fcb6e00892683b6bac134d87f885ec 1 parent eef87ee
Yosuke Basuke Suzuki authored
Showing with 42 additions and 0 deletions.
  1. +42 −0 cake/tests/cases/libs/model/model_validation.test.php
View
42 cake/tests/cases/libs/model/model_validation.test.php
@@ -644,6 +644,48 @@ function testValidatesWithModelsAndSaveAll() {
}
/**
+ * test that saveAll and with models at initial insert (no id has set yet)
+ * with validation interact well
+ *
+ * @return void
+ */
+ function testValidatesWithModelsAndSaveAllWithoutId() {
+ $data = array(
+ 'Article' => array(
+ 'title' => 'Extra Fields',
+ 'body' => 'Extra Fields Body',
+ 'published' => '1'
+ ),
+ 'Comment' => array(
+ array('word' => 'Hello'),
+ array('word' => 'World'),
+ )
+ );
+ $Article =& new Article();
+ $Comment =& $Article->Comment;
+
+ $Comment->validate = array('article_id' => array('rule' => 'numeric'));
+
+ $Article->create();
+ $result = $Article->saveAll($data, array('validate' => 'only'));
+ $this->assertTrue($result);
+
+ $Article->create();
+ $result = $Article->saveAll($data, array('validate' => 'first'));
+ $this->assertTrue($result);
+ $this->assertFalse(is_null($Article->id));
+
+ $id = $Article->id;
+ $count = $Article->find('count', array('conditions' => array('Article.id' => $id)));
+ $this->assertIdentical($count, 1);
+
+ $count = $Comment->find('count', array(
+ 'conditions' => array('Comment.article_id' => $id)
+ ));
+ $this->assertEqual($count, count($data['Comment']));
+ }
+
+/**
* Test that missing validation methods trigger errors in development mode.
* Helps to make developement easier.
*
Please sign in to comment.
Something went wrong with that request. Please try again.