2009-10-01 23:04:18 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class TransactionTest extends SapphireTest {
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
function testCreateWithTransaction() {
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
if(DB::getConn()->supportsTransactions()==true){
|
2011-01-12 00:01:42 +01:00
|
|
|
DB::getConn()->transactionStart();
|
2009-10-01 23:04:18 +02:00
|
|
|
$page=new Page();
|
|
|
|
$page->Title='First page';
|
|
|
|
$page->write();
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
$page=new Page();
|
|
|
|
$page->Title='Second page';
|
|
|
|
$page->write();
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
//Create a savepoint here:
|
|
|
|
DB::getConn()->transactionSavepoint('rollback');
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
$page=new Page();
|
|
|
|
$page->Title='Third page';
|
|
|
|
$page->write();
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
$page=new Page();
|
|
|
|
$page->Title='Forth page';
|
|
|
|
$page->write();
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
//Revert to a savepoint:
|
|
|
|
DB::getConn()->transactionRollback('rollback');
|
2011-01-12 00:01:42 +01:00
|
|
|
|
|
|
|
DB::getConn()->transactionEnd();
|
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
$first=DataObject::get('Page', "\"Title\"='First page'");
|
|
|
|
$second=DataObject::get('Page', "\"Title\"='Second page'");
|
|
|
|
$third=DataObject::get('Page', "\"Title\"='Third page'");
|
|
|
|
$forth=DataObject::get('Page', "\"Title\"='Forth page'");
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
//These pages should be in the system
|
|
|
|
$this->assertTrue(is_object($first) && $first->exists());
|
|
|
|
$this->assertTrue(is_object($second) && $second->exists());
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2009-10-01 23:04:18 +02:00
|
|
|
//These pages should NOT exist, we reverted to a savepoint:
|
|
|
|
$this->assertFalse(is_object($third) && $third->exists());
|
2011-01-12 00:01:42 +01:00
|
|
|
$this->assertFalse(is_object($forth) && $forth->exists());
|
2011-03-14 04:45:52 +01:00
|
|
|
} else {
|
|
|
|
$this->markTestSkipped('Current database does not support transactions');
|
2009-10-01 23:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
2011-01-12 00:01:42 +01:00
|
|
|
|
2011-03-14 04:45:52 +01:00
|
|
|
}
|