diff options
author | wei <> | 2006-12-04 02:42:57 +0000 |
---|---|---|
committer | wei <> | 2006-12-04 02:42:57 +0000 |
commit | 562979c4a8fe47952edf7986d4144624e41630f7 (patch) | |
tree | b79c3fd28e1aedb40d04e148da4b0763c928a3a5 /tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php | |
parent | 91fe694c8755aa2d05743946a3681be7232420b6 (diff) |
add unit tests for active record and sqlmap
Diffstat (limited to 'tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php')
-rw-r--r-- | tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php new file mode 100644 index 00000000..5ab89206 --- /dev/null +++ b/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php @@ -0,0 +1,168 @@ +<?php +
+Prado::using('System.Data.ActiveRecord.TActiveRecordStateRegistry');
+Prado::using('System.Data.ActiveRecord.Exceptions.*');
+
+class StateTestObject
+{
+ public $propA = 'a';
+ public $propB;
+}
+
+class ActiveRecordRegistryTestCase extends UnitTestCase
+{
+ function test_new_object()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+
+ $this->assertTrue($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+ }
+
+ function test_clean_object_registers_without_error()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+ $registry->registerClean($obj);
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertTrue($registry->getIsCleanObject($obj));
+ }
+
+ function test_clean_object_becomes_dirty_when_changed()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+
+ $registry->registerClean($obj);
+
+ $obj->propB='b';
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertTrue($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+ }
+
+ function test_removed_object_must_register_as_clean_first()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+
+ try
+ {
+ $registry->registerRemoved($obj);
+ $this->fail();
+ }
+ catch(TActiveRecordException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ function test_removed_object_registers_without_error()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+ $registry->registerClean($obj);
+
+ $registry->registerRemoved($obj);
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertTrue($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+ }
+
+
+ function test_removed_object_can_not_become_clean()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+ $registry->registerClean($obj);
+
+ $registry->registerRemoved($obj);
+
+ try
+ {
+ $registry->registerClean($obj);
+ $this->fail();
+ }
+ catch(TActiveRecordException $e)
+ {
+ $this->pass();
+ }
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertTrue($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+ }
+
+ function test_remove_dirty_object()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+
+ $registry->registerClean($obj);
+
+ $obj->propB='b';
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertTrue($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+
+ $registry->registerRemoved($obj);
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertTrue($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+
+ try
+ {
+ $registry->registerClean($obj);
+ $this->fail();
+ }
+ catch(TActiveRecordException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ function test_clean_dirty_clean_object()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+
+ $registry->registerClean($obj);
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertTrue($registry->getIsCleanObject($obj));
+
+ $obj->propB='b';
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertTrue($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertFalse($registry->getIsCleanObject($obj));
+
+ $registry->registerClean($obj);
+
+ $this->assertFalse($registry->getIsNewObject($obj));
+ $this->assertFalse($registry->getIsDirtyObject($obj));
+ $this->assertFalse($registry->getIsRemovedObject($obj));
+ $this->assertTrue($registry->getIsCleanObject($obj));
+ }
+
+}
+ +?>
\ No newline at end of file |