summaryrefslogtreecommitdiff
path: root/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php')
-rw-r--r--tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php b/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php
new file mode 100644
index 00000000..107985db
--- /dev/null
+++ b/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php
@@ -0,0 +1,85 @@
+<?php
+
+require_once(dirname(__FILE__).'/BaseCase.php');
+
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+
+class ActiveAccount extends TActiveRecord
+{
+ public $Account_Id;
+ public $Account_FirstName;
+ public $Account_LastName;
+ public $Account_Email;
+
+ public $Account_Banner_Option;
+ public $Account_Cart_Option;
+
+ private static $_tablename='accounts';
+
+ public static function finder()
+ {
+ return self::getRecordFinder('ActiveAccount');
+ }
+}
+
+class ActiveRecordSqlMapTest extends BaseCase
+{
+ function __construct()
+ {
+ parent::__construct();
+ $this->initSqlMap();
+ TActiveRecordManager::getInstance()->setDbConnection($this->getConnection());
+
+ //$this->initScript('account-init.sql');
+ }
+
+ function testLoadWithSqlMap()
+ {
+ $records = $this->sqlmap->queryForList('GetActiveRecordAccounts');
+ $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry();
+ foreach($records as $record)
+ {
+ $this->assertEqual(get_class($record), 'ActiveAccount');
+ $this->assertTrue($registry->getIsCleanObject($record));
+ }
+ }
+
+ function testLoadWithActiveRecord()
+ {
+ $records = ActiveAccount::finder()->findAll();
+ $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry();
+ foreach($records as $record)
+ {
+ $this->assertEqual(get_class($record), 'ActiveAccount');
+ $this->assertTrue($registry->getIsCleanObject($record));
+ }
+ }
+
+ function testLoadWithSqlMap_SaveWithActiveRecord()
+ {
+ $record = $this->sqlmap->queryForObject('GetActiveRecordAccounts');
+ $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry();
+ $record->Account_FirstName = "Testing 123";
+ $this->assertTrue($registry->getIsDirtyObject($record));
+
+ $this->assertTrue($record->save());
+
+ $check1 = $this->sqlmap->queryForObject('GetActiveRecordAccounts');
+ $check2 = ActiveAccount::finder()->findByAccount_FirstName($record->Account_FirstName);
+
+ $this->assertSameAccount($record,$check1);
+ $this->assertSameAccount($record,$check2);
+
+ $this->initScript('account-init.sql');
+ }
+
+ function assertSameAccount($account1,$account2)
+ {
+ $props = array('Account_Id', 'Account_FirstName', 'Account_LastName',
+ 'Account_Email', 'Account_Banner_Option', 'Account_Cart_Option');
+ foreach($props as $prop)
+ $this->assertEqual($account1->{$prop}, $account2->{$prop});
+ }
+}
+
+?> \ No newline at end of file