You are here

public function TransactionLegacyAPITest::testTransactionCommit in Transaction 5

Verify that the commit behaves correctly.

File

tests/transaction_legacy.test, line 177
Contains the test for the pressflow_transaction legacy API provided in the transaction module (formerly pressflow_transaction).

Class

TransactionLegacyAPITest
Implements the test cases for the pressflow_transaction legacy API.

Code

public function testTransactionCommit() {

  // 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 pressflow_transaction();
  pressflow_transaction_update(self::$table, 'id', array(
    'first_name' => 'Louis',
    'last_name' => 'Pasteur',
    'status' => 1,
  ));
  $txn2 = new pressflow_transaction();
  pressflow_transaction_update(self::$table, 'id', array(
    'first_name' => 'Frank',
    'last_name' => 'Miller',
    'status' => 5,
  ));
  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 + 2, $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 + 2, $count_test, $msg);
}