mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Removed unnecessary SiteTree dependency from TransactionTest
This commit is contained in:
parent
e1b249d0d8
commit
1c213906cb
@ -5,38 +5,42 @@
|
|||||||
*/
|
*/
|
||||||
class TransactionTest extends SapphireTest {
|
class TransactionTest extends SapphireTest {
|
||||||
|
|
||||||
|
protected $extraDataObjects = array(
|
||||||
|
'TransactionTest_Object'
|
||||||
|
);
|
||||||
|
|
||||||
function testCreateWithTransaction() {
|
function testCreateWithTransaction() {
|
||||||
|
|
||||||
if(DB::getConn()->supportsTransactions()==true){
|
if(DB::getConn()->supportsTransactions()==true){
|
||||||
DB::getConn()->transactionStart();
|
DB::getConn()->transactionStart();
|
||||||
$page=new Page();
|
$obj=new TransactionTest_Object();
|
||||||
$page->Title='First page';
|
$obj->Title='First page';
|
||||||
$page->write();
|
$obj->write();
|
||||||
|
|
||||||
$page=new Page();
|
$obj=new TransactionTest_Object();
|
||||||
$page->Title='Second page';
|
$obj->Title='Second page';
|
||||||
$page->write();
|
$obj->write();
|
||||||
|
|
||||||
//Create a savepoint here:
|
//Create a savepoint here:
|
||||||
DB::getConn()->transactionSavepoint('rollback');
|
DB::getConn()->transactionSavepoint('rollback');
|
||||||
|
|
||||||
$page=new Page();
|
$obj=new TransactionTest_Object();
|
||||||
$page->Title='Third page';
|
$obj->Title='Third page';
|
||||||
$page->write();
|
$obj->write();
|
||||||
|
|
||||||
$page=new Page();
|
$obj=new TransactionTest_Object();
|
||||||
$page->Title='Forth page';
|
$obj->Title='Forth page';
|
||||||
$page->write();
|
$obj->write();
|
||||||
|
|
||||||
//Revert to a savepoint:
|
//Revert to a savepoint:
|
||||||
DB::getConn()->transactionRollback('rollback');
|
DB::getConn()->transactionRollback('rollback');
|
||||||
|
|
||||||
DB::getConn()->transactionEnd();
|
DB::getConn()->transactionEnd();
|
||||||
|
|
||||||
$first=DataObject::get('Page', "\"Title\"='First page'");
|
$first=DataObject::get('TransactionTest_Object', "\"Title\"='First page'");
|
||||||
$second=DataObject::get('Page', "\"Title\"='Second page'");
|
$second=DataObject::get('TransactionTest_Object', "\"Title\"='Second page'");
|
||||||
$third=DataObject::get('Page', "\"Title\"='Third page'");
|
$third=DataObject::get('TransactionTest_Object', "\"Title\"='Third page'");
|
||||||
$forth=DataObject::get('Page', "\"Title\"='Forth page'");
|
$forth=DataObject::get('TransactionTest_Object', "\"Title\"='Forth page'");
|
||||||
|
|
||||||
//These pages should be in the system
|
//These pages should be in the system
|
||||||
$this->assertTrue(is_object($first) && $first->exists());
|
$this->assertTrue(is_object($first) && $first->exists());
|
||||||
@ -50,4 +54,47 @@ class TransactionTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testReadOnlyTransaction(){
|
||||||
|
|
||||||
|
if(DB::getConn()->supportsTransactions()==true){
|
||||||
|
|
||||||
|
$obj=new TransactionTest_Object();
|
||||||
|
$obj->Title='Read only success';
|
||||||
|
$obj->write();
|
||||||
|
|
||||||
|
DB::getConn()->transactionStart('READ ONLY');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$obj=new TransactionTest_Object();
|
||||||
|
$obj->Title='Read only page failed';
|
||||||
|
$obj->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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransactionTest_Object extends DataObject implements TestOnly {
|
||||||
|
static $db = array(
|
||||||
|
'Title' => 'Varchar(255)'
|
||||||
|
);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user