1
0
mirror of https://github.com/silverstripe/silverstripe-framework synced 2024-10-22 14:05:37 +02:00
silverstripe-framework/tests/model/TransactionTest.php
Ingo Schommer 3334eafcb1 API Marked statics private, use Config API instead ()
See "Static configuration properties are now immutable, you must use Config API." in the 3.1 change log for details.
2013-03-24 17:20:53 +01:00

64 lines
1.7 KiB
PHP

<?php
/**
* @package framework
* @subpackage tests
*/
class TransactionTest extends SapphireTest {
protected $extraDataObjects = array(
'TransactionTest_Object'
);
public function testCreateWithTransaction() {
if(DB::getConn()->supportsTransactions()==true){
DB::getConn()->transactionStart();
$obj=new TransactionTest_Object();
$obj->Title='First page';
$obj->write();
$obj=new TransactionTest_Object();
$obj->Title='Second page';
$obj->write();
//Create a savepoint here:
DB::getConn()->transactionSavepoint('rollback');
$obj=new TransactionTest_Object();
$obj->Title='Third page';
$obj->write();
$obj=new TransactionTest_Object();
$obj->Title='Fourth page';
$obj->write();
//Revert to a savepoint:
DB::getConn()->transactionRollback('rollback');
DB::getConn()->transactionEnd();
$first=DataObject::get('TransactionTest_Object', "\"Title\"='First page'");
$second=DataObject::get('TransactionTest_Object', "\"Title\"='Second page'");
$third=DataObject::get('TransactionTest_Object', "\"Title\"='Third page'");
$fourth=DataObject::get('TransactionTest_Object', "\"Title\"='Fourth page'");
//These pages should be in the system
$this->assertTrue(is_object($first) && $first->exists());
$this->assertTrue(is_object($second) && $second->exists());
//These pages should NOT exist, we reverted to a savepoint:
$this->assertFalse(is_object($third) && $third->exists());
$this->assertFalse(is_object($fourth) && $fourth->exists());
} else {
$this->markTestSkipped('Current database does not support transactions');
}
}
}
class TransactionTest_Object extends DataObject implements TestOnly {
private static $db = array(
'Title' => 'Varchar(255)'
);
}