function TransactionTest::testCommittedTransaction

Tests a committed transaction.

The behavior of this test should be identical for connections that support transactions and those that do not.

File

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

Class

TransactionTest
Tests transaction support, particularly nesting.

Namespace

Drupal\system\Tests\Database

Code

function testCommittedTransaction() {
  try {

    // Create two nested transactions. The changes should be committed.
    $this
      ->transactionOuterLayer('A');

    // Because we committed, both of the inserted rows should be present.
    $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
      ':name' => 'DavidA',
    ))
      ->fetchField();
    $this
      ->assertIdentical($saved_age, '24', 'Can retrieve DavidA row after commit.');
    $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(
      ':name' => 'DanielA',
    ))
      ->fetchField();
    $this
      ->assertIdentical($saved_age, '19', 'Can retrieve DanielA row after commit.');
  } catch (Exception $e) {
    $this
      ->fail($e
      ->getMessage());
  }
}