diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2016-03-25 17:55:51 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2016-03-25 17:55:51 +0100 |
commit | a3388622287e218beddfa14a47ed677d4307b36b (patch) | |
tree | 1b4c7ac8597b1cc798b6683d4a81c90d38de12f6 /tests/unit/Data/SqlMap/ActiveRecordSqlMapTest.php | |
parent | c7fd3e1167b6f2fa7746edbd0fb8f8c1694c61f9 (diff) |
Removed simpletest and moved all tests in the unit tree
Tests are executed now, but a lot of them need fixing.
Diffstat (limited to 'tests/unit/Data/SqlMap/ActiveRecordSqlMapTest.php')
-rw-r--r-- | tests/unit/Data/SqlMap/ActiveRecordSqlMapTest.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/unit/Data/SqlMap/ActiveRecordSqlMapTest.php b/tests/unit/Data/SqlMap/ActiveRecordSqlMapTest.php new file mode 100644 index 00000000..c2eef7a1 --- /dev/null +++ b/tests/unit/Data/SqlMap/ActiveRecordSqlMapTest.php @@ -0,0 +1,88 @@ +<?php + +require_once(dirname(__FILE__).'/BaseCase.php'); + +Prado::using('System.Data.ActiveRecord.TActiveRecord'); + +/** + * @package System.Data.SqlMap + */ +class ActiveAccount extends TActiveRecord +{ + public $Account_Id; + public $Account_FirstName; + public $Account_LastName; + public $Account_Email; + + public $Account_Banner_Option; + public $Account_Cart_Option; + + const TABLE='Accounts'; + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} + +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->isCleanObject($record)); + } + } + + function testLoadWithActiveRecord() + { + $records = ActiveAccount::finder()->findAll(); + $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); + foreach($records as $record) + { + $this->assertEqual(get_class($record), 'ActiveAccount'); + //$this->assertTrue($registry->isCleanObject($record)); //? not clean anymore? + } + } + + function testLoadWithSqlMap_SaveWithActiveRecord() + { + $record = $this->sqlmap->queryForObject('GetActiveRecordAccounts'); + $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); + $record->Account_FirstName = "Testing 123"; + $this->assertTrue($registry->isDirtyObject($record)); + + $this->assertTrue($record->save()); + + $check1 = $this->sqlmap->queryForObject('GetActiveRecordAccounts'); + $finder = ActiveAccount::finder(); + $check2 = $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}); + } +} |