You are here

public function TransactionTest::testTransactionRollBack in Transaction 5

Verify that rollbacks behave correctly.

File

tests/transaction.test, line 143
Contains the test for the transaction module (formerly pressflow_transaction).

Class

TransactionTest
Implements the test cases for the transaction module.

Code

public function testTransactionRollBack() {

  // Get the id from the sequence table before we start
  $seq = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", db_prefix_tables(self::$sequence1)));
  $count = db_result(db_query('SELECT COUNT(*) FROM ' . self::$table));
  $txn1 = new Transaction();
  transaction_update(self::$table, 'id', array(
    'first_name' => 'Louis',
    'last_name' => 'Pasteur',
    'status' => 1,
  ));
  $txn2 = new Transaction();
  transaction_update(self::$table, 'id', array(
    'first_name' => 'Frank',
    'last_name' => 'Miller',
    'status' => 5,
  ));
  $txn2
    ->rollbackIfFalse(FALSE);
  unset($txn2);
  unset($txn1);

  // The __destruct method has now been called on each transaction object,
  // and a roll back should have taken place.
  $seq_test = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", db_prefix_tables(self::$sequence1)));
  $msg = t('Verify sequence after roll back : %s');
  $this
    ->assertEqual($seq, $seq_test, $msg);
  $count_test = db_result(db_query('SELECT COUNT(*) FROM ' . self::$table));
  $msg = t('Verify table row count after roll back : %s');
  $this
    ->assertEqual($count, $count_test, $msg);
}