1
0
mirror of synced 2025-01-18 06:21:40 +03:00
This commit is contained in:
zYne 2007-07-18 19:31:56 +00:00
parent 941a2e5761
commit 943a7c8bdc

View File

@ -32,23 +32,23 @@
*/ */
class Doctrine_AuditLog_TestCase extends Doctrine_UnitTestCase class Doctrine_AuditLog_TestCase extends Doctrine_UnitTestCase
{ {
public function prepareData()
public function prepareData()
{ } { }
public function prepareTables() public function prepareTables()
{ {
$this->tables = array('Versionable'); $this->profiler = new Doctrine_Connection_Profiler();
$this->conn->addListener($this->profiler);
$this->tables = array('VersioningTest', 'VersioningTestVersion');
parent::prepareTables(); parent::prepareTables();
} }
public function testVersionTableSqlReturnsProperQuery()
public function testVersioningListenerListensAllManipulationOperations()
{ {
$table = $this->conn->getTable('Versionable'); $entity = new VersioningTest();
$auditLog = $table->getAuditLog();
$auditLog->audit();
$entity = new Versionable();
$entity->name = 'zYne'; $entity->name = 'zYne';
$entity->save(); $entity->save();
$this->assertEqual($entity->version, 1); $this->assertEqual($entity->version, 1);
@ -58,36 +58,28 @@ class Doctrine_AuditLog_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($entity->version, 2); $this->assertEqual($entity->version, 2);
$entity->delete(); $entity->delete();
$this->assertEqual($entity->version, 3); $this->assertEqual($entity->version, 3);
$entity->revert(2); $entity->revert(2);
$this->assertEqual($entity->name, 'zYne 2'); $this->assertEqual($entity->name, 'zYne 2');
$this->assertEqual($entity->version, 2);
} }
public function testUpdateTriggerSqlReturnsProperQuery()
public function testRevertThrowsExceptionForTransientRecords()
{ {
$table = $this->conn->getTable('User'); $entity = new VersioningTest();
$auditLog = new Doctrine_AuditLog($table); try {
$entity->revert(1);
$sql = $auditLog->updateTriggerSql($table); $this->fail();
} catch (Doctrine_Record_Exception $e) {
$this->assertEqual($sql, 'CREATE TRIGGER entity_dut UPDATE ON entity BEGIN INSERT INTO entity_dvt (id, name, loginname, password, type, created, updated, email_id) VALUES (old.id, old.name, old.loginname, old.password, old.type, old.created, old.updated, old.email_id); END;'); $this->pass();
} }
public function testDeleteTriggerSqlReturnsProperQuery()
{
$table = $this->conn->getTable('User');
$auditLog = new Doctrine_AuditLog($table);
$sql = $auditLog->deleteTriggerSql($table);
$this->assertEqual($sql, 'CREATE TRIGGER entity_ddt BEFORE DELETE ON entity BEGIN INSERT INTO entity_dvt (id, name, loginname, password, type, created, updated, email_id) VALUES (old.id, old.name, old.loginname, old.password, old.type, old.created, old.updated, old.email_id); END;');
} }
} }
class Versionable extends Doctrine_Record class VersioningTest extends Doctrine_Record
{ {
public function setTableDefinition() public function setTableDefinition()
{ {
@ -96,6 +88,6 @@ class Versionable extends Doctrine_Record
} }
public function setUp() public function setUp()
{ {
$this->actAs('Versionable');
} }
} }