function TransactionTest::testTransactionRollBackNotSupported

Tests transaction rollback on a database that doesn't support transactions.

If the active driver supports transactions, this test does nothing.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php, line 188
Definition of Drupal\system\Tests\Database\TransactionTest.

Class

TransactionTest
Tests transaction support, particularly nesting.

Namespace

Drupal\system\Tests\Database

Code

function testTransactionRollBackNotSupported() {

  // This test won't work right if transactions are supported.
  if (Database::getConnection()
    ->supportsTransactions()) {
    return;
  }
  try {

    // Create two nested transactions. Attempt to roll back from the inner one.
    $this
      ->transactionOuterLayer('B', TRUE);

    // Because our current database claims to not support transactions,
    // the inserted rows should be present despite the attempt to roll back.
    $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
      ':name' => 'DavidB',
    ))
      ->fetchField();
    $this
      ->assertIdentical($saved_age, '24', 'DavidB not rolled back, since transactions are not supported.');
    $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
      ':name' => 'DanielB',
    ))
      ->fetchField();
    $this
      ->assertIdentical($saved_age, '19', 'DanielB not rolled back, since transactions are not supported.');
  } catch (\Exception $e) {
    $this
      ->fail($e
      ->getMessage());
  }
}