From 0ec8ee1335ea20f568a5afd7b4dfd42591c59e75 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 14 Mar 2011 16:47:44 +1300 Subject: [PATCH] MINOR Added PostgreSQLDatabaseTest with a database specific readonly transaction test (moved here from sapphire/tests/TransactionTest.php --- tests/PostgreSQLDatabaseTest.php | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/PostgreSQLDatabaseTest.php diff --git a/tests/PostgreSQLDatabaseTest.php b/tests/PostgreSQLDatabaseTest.php new file mode 100644 index 0000000..6c65184 --- /dev/null +++ b/tests/PostgreSQLDatabaseTest.php @@ -0,0 +1,48 @@ +supportsTransactions() == true + && DB::getConn() instanceof PostgreSQLDatabase + ){ + + $page=new Page(); + $page->Title='Read only success'; + $page->write(); + + DB::getConn()->transactionStart('READ ONLY'); + + try { + $page=new Page(); + $page->Title='Read only page failed'; + $page->write(); + } catch (Exception $e) { + //could not write this record + //We need to do a rollback or a commit otherwise we'll get error messages + DB::getConn()->transactionRollback(); + } + + DB::getConn()->transactionEnd(); + + DataObject::flush_and_destroy_cache(); + + $success=DataObject::get('Page', "\"Title\"='Read only success'"); + $fail=DataObject::get('Page', "\"Title\"='Read only page failed'"); + + //This page should be in the system + $this->assertTrue(is_object($success) && $success->exists()); + + //This page should NOT exist, we had 'read only' permissions + $this->assertFalse(is_object($fail) && $fail->exists()); + + } else { + $this->markTestSkipped('Current database is not PostgreSQL'); + } + + } +} \ No newline at end of file