protected function DatabaseTransactionTestCase::transactionInnerLayer in SimpleTest 7
Helper method for transaction unit tests. This "inner layer" transaction is either used alone or nested inside of the "outer layer" transaction.
Parameters
$suffix: Suffix to add to field values to differentiate tests.
$rollback: Whether or not to try rolling back the transaction when we're done.
1 call to DatabaseTransactionTestCase::transactionInnerLayer()
- DatabaseTransactionTestCase::transactionOuterLayer in tests/
database_test.test - Helper method for transaction unit test. This "outer layer" transaction starts and then encapsulates the "inner layer" transaction. This nesting is used to evaluate whether the the database transaction API properly supports…
File
- tests/
database_test.test, line 2750
Class
- DatabaseTransactionTestCase
- Test transaction support, particularly nesting.
Code
protected function transactionInnerLayer($suffix, $rollback = FALSE) {
$connection = Database::getConnection();
// Start a transaction. If we're being called from ->transactionOuterLayer,
// then we're already in a transaction. Normally, that would make starting
// a transaction here dangerous, but the database API handles this problem
// for us by tracking the nesting and avoiding the danger.
$txn = db_transaction();
// Insert a single row into the testing table.
db_insert('test')
->fields(array(
'name' => 'Daniel' . $suffix,
'age' => '19',
))
->execute();
$this
->assertTrue($connection
->inTransaction(), t('In transaction inside nested transaction.'));
if ($rollback) {
// Roll back the transaction, if requested.
// This rollback should propagate to the the outer transaction, if present.
$txn
->rollback();
$this
->assertTrue($txn
->willRollback(), t('Transaction is scheduled to roll back after calling rollback().'));
}
}