2011-03-14 04:47:44 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package postgresql
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class PostgreSQLDatabaseTest extends SapphireTest {
|
|
|
|
function testReadOnlyTransaction(){
|
|
|
|
|
|
|
|
if(
|
2013-04-03 06:27:11 +02:00
|
|
|
DB::get_conn()->supportsTransactions() == true
|
|
|
|
&& DB::get_conn() instanceof PostgreSQLDatabase
|
2011-03-14 04:47:44 +01:00
|
|
|
){
|
|
|
|
|
|
|
|
$page=new Page();
|
|
|
|
$page->Title='Read only success';
|
|
|
|
$page->write();
|
|
|
|
|
2013-04-03 06:27:11 +02:00
|
|
|
DB::get_conn()->transactionStart('READ ONLY');
|
2011-03-14 04:47:44 +01:00
|
|
|
|
|
|
|
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
|
2013-04-03 06:27:11 +02:00
|
|
|
DB::get_conn()->transactionRollback();
|
2011-03-14 04:47:44 +01:00
|
|
|
}
|
|
|
|
|
2013-04-03 06:27:11 +02:00
|
|
|
DB::get_conn()->transactionEnd();
|
2011-03-14 04:47:44 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
}
|