Skip to content
Browse files

Added unittest for saveAll() validation with the data no id assigned.

  • Loading branch information...
1 parent 36928d3 commit 5612d411f343faaae6556417e2a455785f5ff1da Yosuke Basuke Suzuki committed
Showing with 42 additions and 0 deletions.
  1. +42 −0 lib/Cake/Test/Case/Model/ModelValidationTest.php
View
42 lib/Cake/Test/Case/Model/ModelValidationTest.php
@@ -640,6 +640,48 @@ public function testValidatesWithModelsAndSaveAll() {
}
/**
+ * test that saveAll and with models at initial insert (no id has set yet)
+ * with validation interact well
+ *
+ * @return void
+ */
+ public function testValidatesWithModelsAndSaveAllWithoutId() {
+ $this->loadFixtures('Post', 'Author');
+
+ $data = array(
+ 'Author' => array(
+ 'name' => 'Foo Bar',
+ ),
+ 'Post' => array(
+ array('title' => 'Hello'),
+ array('title' => 'World'),
+ )
+ );
+ $Author = new Author();
+ $Post = $Author->Post;
+
+ $Post->validate = array('author_id' => array('rule' => 'numeric'));
+
+ $Author->create();
+ $result = $Author->saveAll($data, array('validate' => 'only'));
+ $this->assertTrue($result);
+
+ $Author->create();
+ $result = $Author->saveAll($data, array('validate' => 'first'));
+ $this->assertTrue($result);
+ $this->assertFalse(is_null($Author->id));
+
+ $id = $Author->id;
+ $count = $Author->find('count', array('conditions' => array('Author.id' => $id)));
+ $this->assertIdentical($count, 1);
+
+ $count = $Post->find('count', array(
+ 'conditions' => array('Post.author_id' => $id)
+ ));
+ $this->assertEqual($count, count($data['Post']));
+ }
+
+/**
* Test that missing validation methods trigger errors in development mode.
* Helps to make developement easier.
*

0 comments on commit 5612d41

Please sign in to comment.
Something went wrong with that request. Please try again.