mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
MINOR Added PostgreSQLDatabaseTest with a database specific readonly transaction test (moved here from sapphire/tests/TransactionTest.php
This commit is contained in:
parent
2b0ffdb4e0
commit
0ec8ee1335
48
tests/PostgreSQLDatabaseTest.php
Normal file
48
tests/PostgreSQLDatabaseTest.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package postgresql
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class PostgreSQLDatabaseTest extends SapphireTest {
|
||||||
|
function testReadOnlyTransaction(){
|
||||||
|
|
||||||
|
if(
|
||||||
|
DB::getConn()->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');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user