mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Added unittest for saveAll() validation with the data no id assigned.
This commit is contained in:
parent
36928d35f9
commit
5612d411f3
1 changed files with 42 additions and 0 deletions
|
@ -639,6 +639,48 @@ class ModelValidationTest extends BaseModelTest {
|
||||||
$this->assertEqual($joinRecords, 0, 'Records were saved on the join table. %s');
|
$this->assertEqual($joinRecords, 0, 'Records were saved on the join table. %s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Test that missing validation methods trigger errors in development mode.
|
||||||
* Helps to make developement easier.
|
* Helps to make developement easier.
|
||||||
|
|
Loading…
Add table
Reference in a new issue