|
|
@@ -36,6 +36,8 @@ class TestAuthor extends Author {
|
|
|
|
|
|
protected $_dataSourceObject;
|
|
|
|
|
|
+ public $dataForAfterSave;
|
|
|
+
|
|
|
/**
|
|
|
* Helper method to set a datasource object
|
|
|
*
|
|
|
@@ -74,6 +76,8 @@ class TestPost extends Post {
|
|
|
|
|
|
protected $_dataSourceObject;
|
|
|
|
|
|
+ public $dataForAfterSave;
|
|
|
+
|
|
|
/**
|
|
|
* Helper method to set a datasource object
|
|
|
*
|
|
|
@@ -4378,23 +4382,55 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
public function testSaveAllManyRowsTransactionNoRollback() {
|
|
|
$this->loadFixtures('Post');
|
|
|
|
|
|
- $db = $this->getMock('DboSource', array('begin', 'connect', 'rollback', 'describe'));
|
|
|
+ $Post = new TestPost();
|
|
|
+ $Post->validate = array(
|
|
|
+ 'title' => array('rule' => array('notEmpty'))
|
|
|
+ );
|
|
|
|
|
|
- $db->expects($this->once())
|
|
|
- ->method('describe')
|
|
|
- ->will($this->returnValue(array()));
|
|
|
+ // If validation error occurs, rollback() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
$db->expects($this->once())->method('rollback');
|
|
|
|
|
|
- $Post = new TestPost();
|
|
|
$Post->setDataSourceObject($db);
|
|
|
|
|
|
- $Post->validate = array(
|
|
|
- 'title' => array('rule' => array('notEmpty'))
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'New Fourth Post'),
|
|
|
+ array('author_id' => 1, 'title' => '')
|
|
|
);
|
|
|
+ $Post->saveAll($data, array('atomic' => true, 'validate' => true));
|
|
|
+
|
|
|
+ // If exception thrown, rollback() should be called too.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
+ $db->expects($this->once())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
|
|
|
$data = array(
|
|
|
array('author_id' => 1, 'title' => 'New Fourth Post'),
|
|
|
- array('author_id' => 1, 'title' => '')
|
|
|
+ array('author_id' => 1, 'title' => 'New Fifth Post', 'body' => $db->expression('PDO_EXCEPTION()'))
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ $Post->saveAll($data, array('atomic' => true, 'validate' => true));
|
|
|
+ $this->fail('No exception thrown');
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise, commit() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->once())->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'New Fourth Post'),
|
|
|
+ array('author_id' => 1, 'title' => 'New Fifth Post')
|
|
|
);
|
|
|
$Post->saveAll($data, array('atomic' => true, 'validate' => true));
|
|
|
}
|
|
|
@@ -4405,28 +4441,71 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testSaveAllAssociatedTransactionNoRollback() {
|
|
|
- $testDb = ConnectionManager::getDataSource('test');
|
|
|
+ $this->loadFixtures('Post', 'Author');
|
|
|
|
|
|
- $db = $this->getMock('DboSource', array('connect', 'rollback', 'describe', 'create', 'update', 'begin'));
|
|
|
- $db->columns = $testDb->columns;
|
|
|
+ $Post = new TestPost();
|
|
|
+ $Post->Author->validate = array(
|
|
|
+ 'user' => array('rule' => array('notEmpty'))
|
|
|
+ );
|
|
|
|
|
|
+ // If validation error occurs, rollback() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
$db->expects($this->once())->method('rollback');
|
|
|
- $db->expects($this->any())->method('describe')
|
|
|
- ->will($this->returnValue(array(
|
|
|
- 'id' => array('type' => 'integer', 'length' => 11),
|
|
|
- 'title' => array('type' => 'string'),
|
|
|
- 'body' => array('type' => 'text'),
|
|
|
- 'published' => array('type' => 'string')
|
|
|
- )));
|
|
|
|
|
|
- $Post = new TestPost();
|
|
|
$Post->setDataSourceObject($db);
|
|
|
$Post->Author->setDataSourceObject($db);
|
|
|
|
|
|
- $Post->Author->validate = array(
|
|
|
- 'user' => array('rule' => array('notEmpty'))
|
|
|
+ $data = array(
|
|
|
+ 'Post' => array(
|
|
|
+ 'title' => 'New post',
|
|
|
+ 'body' => 'Content',
|
|
|
+ 'published' => 'Y'
|
|
|
+ ),
|
|
|
+ 'Author' => array(
|
|
|
+ 'user' => '',
|
|
|
+ 'password' => "sekret"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $Post->saveAll($data, array('validate' => true));
|
|
|
+
|
|
|
+ // If exception thrown, rollback() should be called too.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
+ $db->expects($this->once())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+ $Post->Author->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'Post' => array(
|
|
|
+ 'title' => 'New post',
|
|
|
+ 'body' => $db->expression('PDO_EXCEPTION()'),
|
|
|
+ 'published' => 'Y'
|
|
|
+ ),
|
|
|
+ 'Author' => array(
|
|
|
+ 'user' => 'New user',
|
|
|
+ 'password' => "sekret"
|
|
|
+ )
|
|
|
);
|
|
|
|
|
|
+ try {
|
|
|
+ $Post->saveAll($data, array('validate' => true));
|
|
|
+ $this->fail('No exception thrown');
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise, commit() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->once())->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+ $Post->Author->setDataSourceObject($db);
|
|
|
+
|
|
|
$data = array(
|
|
|
'Post' => array(
|
|
|
'title' => 'New post',
|
|
|
@@ -4434,7 +4513,7 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
'published' => 'Y'
|
|
|
),
|
|
|
'Author' => array(
|
|
|
- 'user' => '',
|
|
|
+ 'user' => 'New user',
|
|
|
'password' => "sekret"
|
|
|
)
|
|
|
);
|
|
|
@@ -5811,23 +5890,55 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
public function testSaveManyTransactionNoRollback() {
|
|
|
$this->loadFixtures('Post');
|
|
|
|
|
|
- $db = $this->getMock('DboSource', array('begin', 'connect', 'rollback', 'describe'));
|
|
|
+ $Post = new TestPost();
|
|
|
+ $Post->validate = array(
|
|
|
+ 'title' => array('rule' => array('notEmpty'))
|
|
|
+ );
|
|
|
|
|
|
- $db->expects($this->once())
|
|
|
- ->method('describe')
|
|
|
- ->will($this->returnValue(array()));
|
|
|
+ // If validation error occurs, rollback() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
$db->expects($this->once())->method('rollback');
|
|
|
|
|
|
- $Post = new TestPost();
|
|
|
$Post->setDataSourceObject($db);
|
|
|
|
|
|
- $Post->validate = array(
|
|
|
- 'title' => array('rule' => array('notEmpty'))
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'New Fourth Post'),
|
|
|
+ array('author_id' => 1, 'title' => '')
|
|
|
+ );
|
|
|
+ $Post->saveMany($data, array('validate' => true));
|
|
|
+
|
|
|
+ // If exception thrown, rollback() should be called too.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
+ $db->expects($this->once())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'New Fourth Post'),
|
|
|
+ array('author_id' => 1, 'title' => 'New Fifth Post', 'body' => $db->expression('PDO_EXCEPTION()'))
|
|
|
);
|
|
|
|
|
|
+ try {
|
|
|
+ $Post->saveMany($data, array('validate' => true));
|
|
|
+ $this->fail('No exception thrown');
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise, commit() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->once())->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+
|
|
|
$data = array(
|
|
|
array('author_id' => 1, 'title' => 'New Fourth Post'),
|
|
|
- array('author_id' => 1, 'title' => '')
|
|
|
+ array('author_id' => 1, 'title' => 'New Fifth Post')
|
|
|
);
|
|
|
$Post->saveMany($data, array('validate' => true));
|
|
|
}
|
|
|
@@ -5838,28 +5949,71 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
* @return void
|
|
|
*/
|
|
|
public function testSaveAssociatedTransactionNoRollback() {
|
|
|
- $testDb = ConnectionManager::getDataSource('test');
|
|
|
+ $this->loadFixtures('Post', 'Author');
|
|
|
|
|
|
- $db = $this->getMock('DboSource', array('connect', 'rollback', 'describe', 'create', 'begin'));
|
|
|
- $db->columns = $testDb->columns;
|
|
|
+ $Post = new TestPost();
|
|
|
+ $Post->Author->validate = array(
|
|
|
+ 'user' => array('rule' => array('notEmpty'))
|
|
|
+ );
|
|
|
|
|
|
+ // If validation error occurs, rollback() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
$db->expects($this->once())->method('rollback');
|
|
|
- $db->expects($this->any())->method('describe')
|
|
|
- ->will($this->returnValue(array(
|
|
|
- 'id' => array('type' => 'integer', 'length' => 11),
|
|
|
- 'title' => array('type' => 'string'),
|
|
|
- 'body' => array('type' => 'text'),
|
|
|
- 'published' => array('type' => 'string')
|
|
|
- )));
|
|
|
|
|
|
- $Post = new TestPost();
|
|
|
$Post->setDataSourceObject($db);
|
|
|
$Post->Author->setDataSourceObject($db);
|
|
|
|
|
|
- $Post->Author->validate = array(
|
|
|
- 'user' => array('rule' => array('notEmpty'))
|
|
|
+ $data = array(
|
|
|
+ 'Post' => array(
|
|
|
+ 'title' => 'New post',
|
|
|
+ 'body' => 'Content',
|
|
|
+ 'published' => 'Y'
|
|
|
+ ),
|
|
|
+ 'Author' => array(
|
|
|
+ 'user' => '',
|
|
|
+ 'password' => "sekret"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $Post->saveAssociated($data, array('validate' => true, 'atomic' => true));
|
|
|
+
|
|
|
+ // If exception thrown, commit() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
+ $db->expects($this->once())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+ $Post->Author->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'Post' => array(
|
|
|
+ 'title' => 'New post',
|
|
|
+ 'body' => $db->expression('PDO_EXCEPTION()'),
|
|
|
+ 'published' => 'Y'
|
|
|
+ ),
|
|
|
+ 'Author' => array(
|
|
|
+ 'user' => 'New user',
|
|
|
+ 'password' => "sekret"
|
|
|
+ )
|
|
|
);
|
|
|
|
|
|
+ try {
|
|
|
+ $Post->saveAssociated($data, array('validate' => true, 'atomic' => true));
|
|
|
+ $this->fail('No exception thrown');
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // Otherwise, commit() should be called.
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->once())->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->once())->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+ $Post->Author->setDataSourceObject($db);
|
|
|
+
|
|
|
$data = array(
|
|
|
'Post' => array(
|
|
|
'title' => 'New post',
|
|
|
@@ -5867,7 +6021,7 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
'published' => 'Y'
|
|
|
),
|
|
|
'Author' => array(
|
|
|
- 'user' => '',
|
|
|
+ 'user' => 'New user',
|
|
|
'password' => "sekret"
|
|
|
)
|
|
|
);
|
|
|
@@ -7569,4 +7723,203 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
$Model = $event->subject;
|
|
|
$Model->getDataSource()->delete($Model, array($Model->alias . '.' . $Model->primaryKey => $Model->id));
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Creates a convenient mock DboSource
|
|
|
+ *
|
|
|
+ * We cannot call several methods via mock DboSource, such as DboSource::value()
|
|
|
+ * because mock DboSource has no $_connection.
|
|
|
+ * This method helps us to avoid this problem.
|
|
|
+ *
|
|
|
+ * @param array $methods Configurable method names.
|
|
|
+ * @return DboSource
|
|
|
+ */
|
|
|
+ protected function _getMockDboSource($methods = array()) {
|
|
|
+ $testDb = ConnectionManager::getDataSource('test');
|
|
|
+
|
|
|
+ $passthrough = array_diff(array('value', 'begin', 'rollback', 'commit', 'describe', 'lastInsertId', 'execute'), $methods);
|
|
|
+
|
|
|
+ $methods = array_merge($methods, $passthrough);
|
|
|
+ if (!in_array('connect', $methods)) {
|
|
|
+ $methods[] = 'connect'; // This will be called by DboSource::__construct().
|
|
|
+ }
|
|
|
+
|
|
|
+ $db = $this->getMock('DboSource', $methods);
|
|
|
+ $db->columns = $testDb->columns;
|
|
|
+ $db->startQuote = $testDb->startQuote;
|
|
|
+ $db->endQuote = $testDb->endQuote;
|
|
|
+
|
|
|
+ foreach ($passthrough as $method) {
|
|
|
+ $db->expects($this->any())
|
|
|
+ ->method($method)
|
|
|
+ ->will($this->returnCallback(array($testDb, $method)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $db;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test that transactions behave correctly on nested saveMany calls.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testTransactionOnNestedSaveMany() {
|
|
|
+ $this->loadFixtures('Post');
|
|
|
+ $Post = new TestPost();
|
|
|
+ $Post->getEventManager()->attach(array($this, 'nestedSaveMany'), 'Model.afterSave');
|
|
|
+
|
|
|
+ // begin -> [ begin -> commit ] -> commit
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->exactly(2))->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->exactly(2))->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'Outer Post'),
|
|
|
+ );
|
|
|
+ $Post->dataForAfterSave = array(
|
|
|
+ array('author_id' => 1, 'title' => 'Inner Post'),
|
|
|
+ );
|
|
|
+ $this->assertTrue($Post->saveMany($data));
|
|
|
+
|
|
|
+ // begin -> [ begin(false) ] -> commit
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->at(0))->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->at(1))->method('begin')->will($this->returnValue(false));
|
|
|
+ $db->expects($this->once())->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'Outer Post'),
|
|
|
+ );
|
|
|
+ $Post->dataForAfterSave = array(
|
|
|
+ array('author_id' => 1, 'title' => 'Inner Post'),
|
|
|
+ );
|
|
|
+ $this->assertTrue($Post->saveMany($data));
|
|
|
+
|
|
|
+ // begin -> [ begin -> rollback ] -> rollback
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->exactly(2))->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
+ $db->expects($this->exactly(2))->method('rollback');
|
|
|
+ $Post->setDataSourceObject($db);
|
|
|
+ $data = array(
|
|
|
+ array('author_id' => 1, 'title' => 'Outer Post'),
|
|
|
+ );
|
|
|
+ $Post->dataForAfterSave = array(
|
|
|
+ array('author_id' => 1, 'title' => 'Inner Post', 'body' => $db->expression('PDO_EXCEPTION()')),
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ $Post->saveMany($data);
|
|
|
+ $this->fail('No exception thrown');
|
|
|
+ } catch(Exception $e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test that transaction behaves correctly on nested saveAssociated calls.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testTransactionOnNestedSaveAssociated() {
|
|
|
+ $this->loadFixtures('Author', 'Post');
|
|
|
+
|
|
|
+ $Author = new TestAuthor();
|
|
|
+ $Author->getEventManager()->attach(array($this, 'nestedSaveAssociated'), 'Model.afterSave');
|
|
|
+
|
|
|
+ // begin -> [ begin -> commit ] -> commit
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->exactly(2))->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->exactly(2))->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+ $Author->setDataSourceObject($db);
|
|
|
+ $Author->Post->setDataSourceObject($db);
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'Author' => array('user' => 'outer'),
|
|
|
+ 'Post' => array(
|
|
|
+ array('title' => 'Outer Post'),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $Author->dataForAfterSave = array(
|
|
|
+ 'Author' => array('user' => 'inner'),
|
|
|
+ 'Post' => array(
|
|
|
+ array('title' => 'Inner Post'),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $this->assertTrue($Author->saveAssociated($data));
|
|
|
+
|
|
|
+ // begin -> [ begin(false) ] -> commit
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->at(0))->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->at(1))->method('begin')->will($this->returnValue(false));
|
|
|
+ $db->expects($this->once())->method('commit');
|
|
|
+ $db->expects($this->never())->method('rollback');
|
|
|
+ $Author->setDataSourceObject($db);
|
|
|
+ $Author->Post->setDataSourceObject($db);
|
|
|
+ $data = array(
|
|
|
+ 'Author' => array('user' => 'outer'),
|
|
|
+ 'Post' => array(
|
|
|
+ array('title' => 'Outer Post'),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $Author->dataForAfterSave = array(
|
|
|
+ 'Author' => array('user' => 'inner'),
|
|
|
+ 'Post' => array(
|
|
|
+ array('title' => 'Inner Post'),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $this->assertTrue($Author->saveAssociated($data));
|
|
|
+
|
|
|
+ // begin -> [ begin -> rollback ] -> rollback
|
|
|
+ $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
|
|
|
+ $db->expects($this->exactly(2))->method('begin')->will($this->returnValue(true));
|
|
|
+ $db->expects($this->never())->method('commit');
|
|
|
+ $db->expects($this->exactly(2))->method('rollback');
|
|
|
+ $Author->setDataSourceObject($db);
|
|
|
+ $Author->Post->setDataSourceObject($db);
|
|
|
+ $data = array(
|
|
|
+ 'Author' => array('user' => 'outer'),
|
|
|
+ 'Post' => array(
|
|
|
+ array('title' => 'Outer Post'),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $Author->dataForAfterSave = array(
|
|
|
+ 'Author' => array('user' => 'inner', 'password' => $db->expression('PDO_EXCEPTION()')),
|
|
|
+ 'Post' => array(
|
|
|
+ array('title' => 'Inner Post'),
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ $Author->saveAssociated($data);
|
|
|
+ $this->fail('No exception thrown');
|
|
|
+ } catch(Exception $e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * A callback for testing nested saveMany.
|
|
|
+ *
|
|
|
+ * @param CakeEvent $event containing the Model
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function nestedSaveMany($event) {
|
|
|
+ $Model = $event->subject;
|
|
|
+ $Model->saveMany($Model->dataForAfterSave, array('callbacks' => false));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * A callback for testing nested saveAssociated.
|
|
|
+ *
|
|
|
+ * @param CakeEvent $event containing the Model
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function nestedSaveAssociated($event) {
|
|
|
+ $Model = $event->subject;
|
|
|
+ $Model->saveAssociated($Model->dataForAfterSave, array('callbacks' => false));
|
|
|
+ }
|
|
|
}
|