diff options
Diffstat (limited to 'tests/unit')
42 files changed, 4080 insertions, 4080 deletions
diff --git a/tests/unit/Data/SqlMap/AllTests.php b/tests/unit/Data/SqlMap/AllTests.php index 66f02608..2f820f83 100644 --- a/tests/unit/Data/SqlMap/AllTests.php +++ b/tests/unit/Data/SqlMap/AllTests.php @@ -1,30 +1,30 @@ -<?php
-require_once dirname(__FILE__).'/../../phpunit.php';
-
-if(!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Data_SqlMap_AllTests::main');
-}
-
-require_once 'DynamicParameterTest.php';
-require_once 'DataMapper/AllTests.php';
-
-class Data_SqlMap_AllTests {
-
- public static function main() {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite() {
- $suite = new PHPUnit_Framework_TestSuite('System.Data.SqlMap');
-
- $suite->addTestSuite('DynamicParameterTest');
- $suite -> addTest( Data_SqlMap_DataMapper_AllTests::suite() );
-
- return $suite;
- }
-}
-
-if(PHPUnit_MAIN_METHOD == 'Data_SqlMap_AllTests::main') {
- Data_SqlMap_AllTests::main();
-}
-?>
+<?php +require_once dirname(__FILE__).'/../../phpunit.php'; + +if(!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Data_SqlMap_AllTests::main'); +} + +require_once 'DynamicParameterTest.php'; +require_once 'DataMapper/AllTests.php'; + +class Data_SqlMap_AllTests { + + public static function main() { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit_Framework_TestSuite('System.Data.SqlMap'); + + $suite->addTestSuite('DynamicParameterTest'); + $suite -> addTest( Data_SqlMap_DataMapper_AllTests::suite() ); + + return $suite; + } +} + +if(PHPUnit_MAIN_METHOD == 'Data_SqlMap_AllTests::main') { + Data_SqlMap_AllTests::main(); +} +?> diff --git a/tests/unit/Data/SqlMap/DynamicParameterTest.php b/tests/unit/Data/SqlMap/DynamicParameterTest.php index f9b39b96..0bd5334e 100644 --- a/tests/unit/Data/SqlMap/DynamicParameterTest.php +++ b/tests/unit/Data/SqlMap/DynamicParameterTest.php @@ -1,109 +1,109 @@ -<?php
-require_once dirname(__FILE__).'/../../phpunit.php';
-
-Prado::using('System.Data.*');
-Prado::using('System.Data.SqlMap.*');
-
-/**
- * @package System.Data.SqlMap
- */
-class DynamicParameterTest extends PHPUnit_Framework_TestCase
-{
-
- protected function getMysqlSqlMapManager()
- {
- static $conn;
- static $sqlMapManager;
-
- if(Prado::getApplication() === null)
- Prado::setApplication(new TApplication(dirname(__FILE__).'/app'));
-
- if($conn === null)
- $conn = new TDbConnection('mysql:host=localhost;dbname=prado_system_data_sqlmap', 'prado_unitest', 'prado_system_data_sqlmap_unitest');
-
- $conn->setActive(true);
-
- if($sqlMapManager === null)
- {
- $sqlMapManager = new TSqlMapManager($conn);
- $sqlMapManager->configureXml( dirname(__FILE__) . '/DynamicParameterTestMap.xml');
- }
-
- return $sqlMapManager;
- }
-
- public function testMysqlSelectStaticSql()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectStaticSql1');
- self::assertEquals('staticsql1', $value);
-
- $value = $gateway->queryForObject('SelectStaticSql2');
- self::assertEquals('staticsql2', $value);
- }
-
- public function testMysqlSelectDynamicTable()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest1');
- self::assertEquals('dynamictableparametertest1', $value);
-
- $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest2');
- self::assertEquals('dynamictableparametertest2', $value);
- }
-
- public function testMysqlSelectDynamicComplex()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $aParams = array(
- 'tablename' => 'dynamicparametertest1',
- 'testname' => 'dynamictable'
- );
- $value = $gateway->queryForObject('SelectDynamicComplex', $aParams);
- self::assertEquals('#dynamictableparametertest1$', $value);
-
- $aParams = array(
- 'tablename' => 'dynamicparametertest2',
- 'testname' => 'dynamictable'
- );
- $value = $gateway->queryForObject('SelectDynamicComplex', $aParams);
- self::assertEquals('#dynamictableparametertest2$', $value);
- }
-
- public function testMysqlSelectNoDynamic()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectNoDynamic', 'dynamictable');
- self::assertEquals('dynamictableparametertest1', $value);
-
- $value = $gateway->queryForObject('SelectNoDynamic', 'staticsql');
- self::assertEquals('staticsql1', $value);
- }
-
- /**
- * Issue#209 test
- */
- public function testMysqlInlineEscapeParam()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectInlineEscapeParam', "'1234567*123$456789$012345' AS foobar");
- self::assertEquals('1234567*123$456789$012345', $value);
-
- $value = $gateway->queryForObject('SelectInlineEscapeParam', '"1234567*123$456789$012345" AS foobar');
- self::assertEquals('1234567*123$456789$012345', $value);
-
- }
-
-}
-
+<?php +require_once dirname(__FILE__).'/../../phpunit.php'; + +Prado::using('System.Data.*'); +Prado::using('System.Data.SqlMap.*'); + +/** + * @package System.Data.SqlMap + */ +class DynamicParameterTest extends PHPUnit_Framework_TestCase +{ + + protected function getMysqlSqlMapManager() + { + static $conn; + static $sqlMapManager; + + if(Prado::getApplication() === null) + Prado::setApplication(new TApplication(dirname(__FILE__).'/app')); + + if($conn === null) + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_system_data_sqlmap', 'prado_unitest', 'prado_system_data_sqlmap_unitest'); + + $conn->setActive(true); + + if($sqlMapManager === null) + { + $sqlMapManager = new TSqlMapManager($conn); + $sqlMapManager->configureXml( dirname(__FILE__) . '/DynamicParameterTestMap.xml'); + } + + return $sqlMapManager; + } + + public function testMysqlSelectStaticSql() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectStaticSql1'); + self::assertEquals('staticsql1', $value); + + $value = $gateway->queryForObject('SelectStaticSql2'); + self::assertEquals('staticsql2', $value); + } + + public function testMysqlSelectDynamicTable() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest1'); + self::assertEquals('dynamictableparametertest1', $value); + + $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest2'); + self::assertEquals('dynamictableparametertest2', $value); + } + + public function testMysqlSelectDynamicComplex() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $aParams = array( + 'tablename' => 'dynamicparametertest1', + 'testname' => 'dynamictable' + ); + $value = $gateway->queryForObject('SelectDynamicComplex', $aParams); + self::assertEquals('#dynamictableparametertest1$', $value); + + $aParams = array( + 'tablename' => 'dynamicparametertest2', + 'testname' => 'dynamictable' + ); + $value = $gateway->queryForObject('SelectDynamicComplex', $aParams); + self::assertEquals('#dynamictableparametertest2$', $value); + } + + public function testMysqlSelectNoDynamic() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectNoDynamic', 'dynamictable'); + self::assertEquals('dynamictableparametertest1', $value); + + $value = $gateway->queryForObject('SelectNoDynamic', 'staticsql'); + self::assertEquals('staticsql1', $value); + } + + /** + * Issue#209 test + */ + public function testMysqlInlineEscapeParam() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectInlineEscapeParam', "'1234567*123$456789$012345' AS foobar"); + self::assertEquals('1234567*123$456789$012345', $value); + + $value = $gateway->queryForObject('SelectInlineEscapeParam', '"1234567*123$456789$012345" AS foobar'); + self::assertEquals('1234567*123$456789$012345', $value); + + } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/Data/TDbDataReaderTest.php b/tests/unit/Data/TDbDataReaderTest.php index 68f9bfe8..9d61a330 100644 --- a/tests/unit/Data/TDbDataReaderTest.php +++ b/tests/unit/Data/TDbDataReaderTest.php @@ -1,179 +1,179 @@ -<?php
-
-require_once(dirname(__FILE__).'/../phpunit2.php');
-
-Prado::using('System.Data.*');
-
-define('TEST_DB_FILE',dirname(__FILE__).'/db/test.db');
-
-class FooRecord extends TComponent
-{
- public $id;
- private $_name;
- public $param;
-
- public function __construct($param)
- {
- $this->param=$param;
- }
-
- public function getName()
- {
- return $this->_name;
- }
-
- public function setName($value)
- {
- $this->_name=$value;
- }
-}
-
-/**
- * @package System.Data.PDO
- */
-class TDbDataReaderTest extends PHPUnit2_Framework_TestCase
-{
- private $_connection;
-
- public function setUp()
- {
- @unlink(TEST_DB_FILE);
- $this->_connection=new TDbConnection('sqlite:'.TEST_DB_FILE);
- $this->_connection->Active=true;
- $this->_connection->createCommand('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(8))')->execute();
- $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name\')')->execute();
- $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name 2\')')->execute();
- }
-
- public function tearDown()
- {
- $this->_connection=null;
- }
-
- public function testRead()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $row=$reader->read();
- $this->assertTrue($row['id']==='1' && $row['name']==='my name');
- $row=$reader->read();
- $this->assertTrue($row['id']==='2' && $row['name']==='my name 2');
- $row=$reader->read();
- $this->assertFalse($row);
- }
-
- public function testReadColumn()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $this->assertEquals($reader->readColumn(0),'1');
- $this->assertEquals($reader->readColumn(1),'my name 2');
- $this->assertFalse($reader->readColumn(0));
- }
-
- public function testReadObject()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $object=$reader->readObject('FooRecord',array('object'));
- $this->assertEquals($object->id,'1');
- $this->assertEquals($object->Name,'my name');
- $this->assertEquals($object->param,'object');
- }
-
- public function testReadAll()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $rows=$reader->readAll();
- $this->assertEquals(count($rows),2);
- $row=$rows[0];
- $this->assertTrue($row['id']==='1' && $row['name']==='my name');
- $row=$rows[1];
- $this->assertTrue($row['id']==='2' && $row['name']==='my name 2');
-
- $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=3')->query();
- $rows=$reader->readAll();
- $this->assertEquals($rows,array());
- }
-
- public function testClose()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $row=$reader->read();
- $this->assertFalse($reader->IsClosed);
- $reader->close();
- $this->assertTrue($reader->IsClosed);
- try
- {
- $reader->read();
- $this->fail('Expected exception is not raised');
- }
- catch(Exception $e)
- {
- }
- }
-
- public function testRowCount()
- {
- // unable to test because SQLite doesn't support row count
- }
-
- public function testColumnCount()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $this->assertEquals($reader->ColumnCount,2);
-
- $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=11')->query();
- $this->assertEquals($reader->ColumnCount,2);
- }
-
- public function testForeach()
- {
- $ids=array();
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- foreach($reader as $row)
- $ids[]=$row['id'];
- $this->assertEquals(count($ids),2);
- $this->assertTrue($ids[0]==='1' && $ids[1]==='2');
-
- try
- {
- foreach($reader as $row)
- $ids[]=$row['id'];
- $this->fail('Expected exception is not raised');
- }
- catch(TDbException $e)
- {
- }
- }
-
- public function testFetchMode()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
-
- $reader->FetchMode=PDO::FETCH_NUM;
- $row=$reader->read();
- $this->assertFalse(isset($row['id']));
- $this->assertTrue(isset($row[0]));
-
- $reader->FetchMode=PDO::FETCH_ASSOC;
- $row=$reader->read();
- $this->assertTrue(isset($row['id']));
- $this->assertFalse(isset($row[0]));
- }
-
- public function testBindColumn()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $reader->bindColumn(1,$id);
- $reader->bindColumn(2,$name);
- $reader->read();
- $this->assertEquals($id,'1');
- $this->assertEquals($name,'my name');
- $reader->read();
- $this->assertEquals($id,'2');
- $this->assertEquals($name,'my name 2');
- $reader->read();
- $this->assertEquals($id,'2');
- $this->assertEquals($name,'my name 2');
- }
-}
-
+<?php + +require_once(dirname(__FILE__).'/../phpunit2.php'); + +Prado::using('System.Data.*'); + +define('TEST_DB_FILE',dirname(__FILE__).'/db/test.db'); + +class FooRecord extends TComponent +{ + public $id; + private $_name; + public $param; + + public function __construct($param) + { + $this->param=$param; + } + + public function getName() + { + return $this->_name; + } + + public function setName($value) + { + $this->_name=$value; + } +} + +/** + * @package System.Data.PDO + */ +class TDbDataReaderTest extends PHPUnit2_Framework_TestCase +{ + private $_connection; + + public function setUp() + { + @unlink(TEST_DB_FILE); + $this->_connection=new TDbConnection('sqlite:'.TEST_DB_FILE); + $this->_connection->Active=true; + $this->_connection->createCommand('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(8))')->execute(); + $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name\')')->execute(); + $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name 2\')')->execute(); + } + + public function tearDown() + { + $this->_connection=null; + } + + public function testRead() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $row=$reader->read(); + $this->assertTrue($row['id']==='1' && $row['name']==='my name'); + $row=$reader->read(); + $this->assertTrue($row['id']==='2' && $row['name']==='my name 2'); + $row=$reader->read(); + $this->assertFalse($row); + } + + public function testReadColumn() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $this->assertEquals($reader->readColumn(0),'1'); + $this->assertEquals($reader->readColumn(1),'my name 2'); + $this->assertFalse($reader->readColumn(0)); + } + + public function testReadObject() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $object=$reader->readObject('FooRecord',array('object')); + $this->assertEquals($object->id,'1'); + $this->assertEquals($object->Name,'my name'); + $this->assertEquals($object->param,'object'); + } + + public function testReadAll() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $rows=$reader->readAll(); + $this->assertEquals(count($rows),2); + $row=$rows[0]; + $this->assertTrue($row['id']==='1' && $row['name']==='my name'); + $row=$rows[1]; + $this->assertTrue($row['id']==='2' && $row['name']==='my name 2'); + + $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=3')->query(); + $rows=$reader->readAll(); + $this->assertEquals($rows,array()); + } + + public function testClose() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $row=$reader->read(); + $this->assertFalse($reader->IsClosed); + $reader->close(); + $this->assertTrue($reader->IsClosed); + try + { + $reader->read(); + $this->fail('Expected exception is not raised'); + } + catch(Exception $e) + { + } + } + + public function testRowCount() + { + // unable to test because SQLite doesn't support row count + } + + public function testColumnCount() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $this->assertEquals($reader->ColumnCount,2); + + $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=11')->query(); + $this->assertEquals($reader->ColumnCount,2); + } + + public function testForeach() + { + $ids=array(); + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + foreach($reader as $row) + $ids[]=$row['id']; + $this->assertEquals(count($ids),2); + $this->assertTrue($ids[0]==='1' && $ids[1]==='2'); + + try + { + foreach($reader as $row) + $ids[]=$row['id']; + $this->fail('Expected exception is not raised'); + } + catch(TDbException $e) + { + } + } + + public function testFetchMode() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + + $reader->FetchMode=PDO::FETCH_NUM; + $row=$reader->read(); + $this->assertFalse(isset($row['id'])); + $this->assertTrue(isset($row[0])); + + $reader->FetchMode=PDO::FETCH_ASSOC; + $row=$reader->read(); + $this->assertTrue(isset($row['id'])); + $this->assertFalse(isset($row[0])); + } + + public function testBindColumn() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $reader->bindColumn(1,$id); + $reader->bindColumn(2,$name); + $reader->read(); + $this->assertEquals($id,'1'); + $this->assertEquals($name,'my name'); + $reader->read(); + $this->assertEquals($id,'2'); + $this->assertEquals($name,'my name 2'); + $reader->read(); + $this->assertEquals($id,'2'); + $this->assertEquals($name,'my name 2'); + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/BaseTest.php b/tests/unit/SQLMap/BaseTest.php index 0f3ce1e2..047863ec 100644 --- a/tests/unit/SQLMap/BaseTest.php +++ b/tests/unit/SQLMap/BaseTest.php @@ -1,260 +1,260 @@ -<?php
-require_once dirname(__FILE__).'/../phpunit2.php';
-
-require_once(dirname(__FILE__).'/common.php');
-require_once(SQLMAP_DIR.'/TSqlMapClient.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class BaseTest extends PHPUnit2_Framework_TestCase
-{
- protected $sqlmap;
- protected $connection;
- private $mapper;
- private $config;
-
- public function testCase1()
- {
- $this->assertTrue(true);
- }
-
- public function testCase2()
- {
- $this->assertTrue(true);
- }
-
- public function __construct()
- {
- parent::__construct();
- $this->config = BaseTestConfig::createConfigInstance();
- $this->ScriptDirectory = $this->config->getScriptDir();
- }
-
- public function hasSupportFor($feature)
- {
- return $this->config->hasFeature($feature);
- }
-
- public function __destruct()
- {
- if(!is_null($this->mapper))
- $this->mapper->cacheConfiguration();
- }
-
- function getConnection()
- {
- if(is_null($this->connection))
- $this->connection = new TAdodbConnection($this->config->getConnectionString());
- $this->connection->open();
- return $this->connection;
- }
-
- protected static $ScriptDirectory;
-
- /**
- * Initialize an sqlMap
- */
- protected function initSqlMap()
- {
- $filename = $this->config->getSqlMapConfigFile();
- $this->mapper = new TSQLMapClient;
- $this->sqlmap = $this->mapper->configure($filename,true);
- $this->sqlmap->getTypeHandlerFactory()->register('date', new TDateTimeHandler);
- $this->sqlmap->getDataProvider()->setConnectionString($this->config->getConnectionString());
- }
-
- /**
- * Run a sql batch for the datasource.
- */
- protected function initScript($script)
- {
- $runner = $this->config->getScriptRunner();
- $runner->runScript($this->getConnection(), $this->ScriptDirectory.$script);
- }
-
- /**
- * Create a new account with id = 6
- */
- protected function NewAccount6()
- {
- $account = new Account();
- $account->setID(6);
- $account->setFirstName('Calamity');
- $account->setLastName('Jane');
- $account->setEmailAddress('no_email@provided.com');
- return $account;
- }
-
- /**
- * Verify that the input account is equal to the account(id=1).
- */
- protected function assertAccount1(Account $account)
- {
- $this->assertEquals($account->getID(), 1);
- $this->assertEquals($account->getFirstName(), 'Joe');
- $this->assertEquals($account->getEmailAddress(), 'Joe.Dalton@somewhere.com');
- }
-
- /**
- * Verify that the input account is equal to the account(id=6).
- */
- protected function assertAccount6(Account $account)
- {
- $this->assertEquals($account->getID(), 6);
- $this->assertEquals($account->getFirstName(), 'Calamity');
- $this->assertEquals($account->getLastName(), 'Jane');
- $this->assertNull($account->getEmailAddress());
- }
-
- /**
- * Verify that the input order is equal to the order(id=1).
- */
- protected function assertOrder1(Order $order)
- {
- $date = @mktime(8,15,0,2,15,2003);
-
- $this->assertEquals((int)$order->getID(), 1);
- if($order->getDate() instanceof TDateTime)
- $this->assertEquals($order->getDate()->getTimestamp(), $date);
- else
- $this->fail();
- $this->assertEquals($order->getCardType(), 'VISA');
- $this->assertEquals($order->getCardNumber(), '999999999999');
- $this->assertEquals($order->getCardExpiry(), '05/03');
- $this->assertEquals($order->getStreet(), '11 This Street');
- $this->assertEquals($order->getProvince(), 'BC');
- $this->assertEquals($order->getPostalCode(), 'C4B 4F4');
- }
-
- function assertAccount1AsHashArray($account)
- {
- $this->assertEquals(1, (int)$account["Id"]);
- $this->assertEquals("Joe", $account["FirstName"]);
- $this->assertEquals("Dalton", $account["LastName"]);
- $this->assertEquals("Joe.Dalton@somewhere.com", $account["EmailAddress"]);
- }
-
- function AssertOrder1AsHashArray($order)
- {
- $date = @mktime(8,15,0,2,15,2003);
-
- $this->assertEquals(1, $order["Id"]);
- if($order['Date'] instanceof TDateTime)
- $this->assertEquals($date, $order["Date"]->getTimestamp());
- else
- $this->fail();
- $this->assertEquals("VISA", $order["CardType"]);
- $this->assertEquals("999999999999", $order["CardNumber"]);
- $this->assertEquals("05/03", $order["CardExpiry"]);
- $this->assertEquals("11 This Street", $order["Street"]);
- $this->assertEquals("Victoria", $order["City"]);
- $this->assertEquals("BC", $order["Province"]);
- $this->assertEquals("C4B 4F4", $order["PostalCode"]);
- }
-
-}
-
-class HundredsBool implements ITypeHandlerCallback
-{
- public function getResult($string)
- {
- $value = intval($string);
- if($value == 100)
- return true;
- if($value == 200)
- return false;
- //throw new Exception('unexpected value '.$value);
- }
-
- public function getParameter($parameter)
- {
- if($parameter)
- return 100;
- else
- return 200;
- }
-
- public function createNewInstance($data=null)
- {
- throw new TDataMapperException('can not create');
- }
-}
-
-class OuiNonBool implements ITypeHandlerCallback
-{
- const YES = "Oui";
- const NO = "Non";
-
- public function getResult($string)
- {
- if($string === self::YES)
- return true;
- if($string === self::NO)
- return false;
- //throw new Exception('unexpected value '.$string);
- }
-
- public function getParameter($parameter)
- {
- if($parameter)
- return self::YES;
- else
- return self::NO;
- }
-
- public function createNewInstance($data=null)
- {
- throw new TDataMapperException('can not create');
- }
-}
-
-class TDateTimeHandler implements ITypeHandlerCallback
-{
- public function getResult($string)
- {
- $time = new TDateTime($string);
- return $time;
- }
-
- public function getParameter($parameter)
- {
- if($parameter instanceof TDateTime)
- return $parameter->getTimestamp();
- else
- return $parameter;
- }
-
- public function createNewInstance($data=null)
- {
- return new TDateTime;
- }
-}
-
-class TDateTime
-{
- private $_datetime;
-
- public function __construct($datetime=null)
- {
- if(!is_null($datetime))
- $this->setDatetime($datetime);
- }
-
- public function getTimestamp()
- {
- return strtotime($this->getDatetime());
- }
-
- public function getDateTime()
- {
- return $this->_datetime;
- }
-
- public function setDateTime($value)
- {
- $this->_datetime = $value;
- }
-}
-
+<?php +require_once dirname(__FILE__).'/../phpunit2.php'; + +require_once(dirname(__FILE__).'/common.php'); +require_once(SQLMAP_DIR.'/TSqlMapClient.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class BaseTest extends PHPUnit2_Framework_TestCase +{ + protected $sqlmap; + protected $connection; + private $mapper; + private $config; + + public function testCase1() + { + $this->assertTrue(true); + } + + public function testCase2() + { + $this->assertTrue(true); + } + + public function __construct() + { + parent::__construct(); + $this->config = BaseTestConfig::createConfigInstance(); + $this->ScriptDirectory = $this->config->getScriptDir(); + } + + public function hasSupportFor($feature) + { + return $this->config->hasFeature($feature); + } + + public function __destruct() + { + if(!is_null($this->mapper)) + $this->mapper->cacheConfiguration(); + } + + function getConnection() + { + if(is_null($this->connection)) + $this->connection = new TAdodbConnection($this->config->getConnectionString()); + $this->connection->open(); + return $this->connection; + } + + protected static $ScriptDirectory; + + /** + * Initialize an sqlMap + */ + protected function initSqlMap() + { + $filename = $this->config->getSqlMapConfigFile(); + $this->mapper = new TSQLMapClient; + $this->sqlmap = $this->mapper->configure($filename,true); + $this->sqlmap->getTypeHandlerFactory()->register('date', new TDateTimeHandler); + $this->sqlmap->getDataProvider()->setConnectionString($this->config->getConnectionString()); + } + + /** + * Run a sql batch for the datasource. + */ + protected function initScript($script) + { + $runner = $this->config->getScriptRunner(); + $runner->runScript($this->getConnection(), $this->ScriptDirectory.$script); + } + + /** + * Create a new account with id = 6 + */ + protected function NewAccount6() + { + $account = new Account(); + $account->setID(6); + $account->setFirstName('Calamity'); + $account->setLastName('Jane'); + $account->setEmailAddress('no_email@provided.com'); + return $account; + } + + /** + * Verify that the input account is equal to the account(id=1). + */ + protected function assertAccount1(Account $account) + { + $this->assertEquals($account->getID(), 1); + $this->assertEquals($account->getFirstName(), 'Joe'); + $this->assertEquals($account->getEmailAddress(), 'Joe.Dalton@somewhere.com'); + } + + /** + * Verify that the input account is equal to the account(id=6). + */ + protected function assertAccount6(Account $account) + { + $this->assertEquals($account->getID(), 6); + $this->assertEquals($account->getFirstName(), 'Calamity'); + $this->assertEquals($account->getLastName(), 'Jane'); + $this->assertNull($account->getEmailAddress()); + } + + /** + * Verify that the input order is equal to the order(id=1). + */ + protected function assertOrder1(Order $order) + { + $date = @mktime(8,15,0,2,15,2003); + + $this->assertEquals((int)$order->getID(), 1); + if($order->getDate() instanceof TDateTime) + $this->assertEquals($order->getDate()->getTimestamp(), $date); + else + $this->fail(); + $this->assertEquals($order->getCardType(), 'VISA'); + $this->assertEquals($order->getCardNumber(), '999999999999'); + $this->assertEquals($order->getCardExpiry(), '05/03'); + $this->assertEquals($order->getStreet(), '11 This Street'); + $this->assertEquals($order->getProvince(), 'BC'); + $this->assertEquals($order->getPostalCode(), 'C4B 4F4'); + } + + function assertAccount1AsHashArray($account) + { + $this->assertEquals(1, (int)$account["Id"]); + $this->assertEquals("Joe", $account["FirstName"]); + $this->assertEquals("Dalton", $account["LastName"]); + $this->assertEquals("Joe.Dalton@somewhere.com", $account["EmailAddress"]); + } + + function AssertOrder1AsHashArray($order) + { + $date = @mktime(8,15,0,2,15,2003); + + $this->assertEquals(1, $order["Id"]); + if($order['Date'] instanceof TDateTime) + $this->assertEquals($date, $order["Date"]->getTimestamp()); + else + $this->fail(); + $this->assertEquals("VISA", $order["CardType"]); + $this->assertEquals("999999999999", $order["CardNumber"]); + $this->assertEquals("05/03", $order["CardExpiry"]); + $this->assertEquals("11 This Street", $order["Street"]); + $this->assertEquals("Victoria", $order["City"]); + $this->assertEquals("BC", $order["Province"]); + $this->assertEquals("C4B 4F4", $order["PostalCode"]); + } + +} + +class HundredsBool implements ITypeHandlerCallback +{ + public function getResult($string) + { + $value = intval($string); + if($value == 100) + return true; + if($value == 200) + return false; + //throw new Exception('unexpected value '.$value); + } + + public function getParameter($parameter) + { + if($parameter) + return 100; + else + return 200; + } + + public function createNewInstance($data=null) + { + throw new TDataMapperException('can not create'); + } +} + +class OuiNonBool implements ITypeHandlerCallback +{ + const YES = "Oui"; + const NO = "Non"; + + public function getResult($string) + { + if($string === self::YES) + return true; + if($string === self::NO) + return false; + //throw new Exception('unexpected value '.$string); + } + + public function getParameter($parameter) + { + if($parameter) + return self::YES; + else + return self::NO; + } + + public function createNewInstance($data=null) + { + throw new TDataMapperException('can not create'); + } +} + +class TDateTimeHandler implements ITypeHandlerCallback +{ + public function getResult($string) + { + $time = new TDateTime($string); + return $time; + } + + public function getParameter($parameter) + { + if($parameter instanceof TDateTime) + return $parameter->getTimestamp(); + else + return $parameter; + } + + public function createNewInstance($data=null) + { + return new TDateTime; + } +} + +class TDateTime +{ + private $_datetime; + + public function __construct($datetime=null) + { + if(!is_null($datetime)) + $this->setDatetime($datetime); + } + + public function getTimestamp() + { + return strtotime($this->getDatetime()); + } + + public function getDateTime() + { + return $this->_datetime; + } + + public function setDateTime($value) + { + $this->_datetime = $value; + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/CacheTest.php b/tests/unit/SQLMap/CacheTest.php index 4fd69916..c8a0aab7 100644 --- a/tests/unit/SQLMap/CacheTest.php +++ b/tests/unit/SQLMap/CacheTest.php @@ -1,164 +1,164 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class CacheTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
-
- $this->initSqlMap();
-
- //force autoload
- new Account;
- }
-
- function resetDatabase()
- {
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test for JIRA 29
- */
- function testJIRA28()
- {
- $account = $this->sqlmap->queryForObject("GetNoAccountWithCache",-99);
- $this->assertNull($account);
- }
-
- /**
- * Test Cache query
- */
- function testQueryWithCache()
- {
- $this->resetDatabase();
-
- $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 === $list2);
-
- $account = $list1[1];
- $account->setEmailAddress("somebody@cache.com");
-
- //this will cause the cache to flush
- $this->sqlmap->update("UpdateAccountViaInlineParameters", $account);
-
- $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 !== $list3);
-
- $this->resetDatabase();
- }
-
-
- /**
- * Test flush Cache
- */
- function testFlushDataCache()
- {
- $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
- $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 === $list2);
- $this->sqlmap->flushCaches();
-
- $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 !== $list3);
- }
-
- /**
- *
- */
- function testFlushDataCacheOnExecute()
- {
- $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 === $list2);
- $this->sqlmap->update("UpdateAccountViaInlineParameters", $list1[0]);
-
- $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 !== $list3);
- }
-
- /**
- */
- protected function getCacheModel()
- {
- $cache = new TSqlMapCacheModel();
- // $cache->setFlushInterval(5*60);
- $cache->setImplementation('LRU');
- $cache->initialize($this->sqlmap);
- return $cache;
- }
-
- /**
- * Test CacheHit
- */
- function testCacheHit()
- {
- $cache = $this->getCacheModel();
- $key = new TSqlMapCacheKey('testkey');
- $cache->set($key, 'a');
-
- $returnedObject = $cache->get($key);
-
- $this->assertEquals('a', $returnedObject);
-
- $this->assertEquals(1, $cache->getHitRatio());
- }
-
-
-
- /**
- * Test CacheMiss
- */
- function testCacheMiss()
- {
- $cache = $this->getCacheModel();
- $key = new TSqlMapCacheKey('testKey');
- $value = 'testValue';
- $cache->set($key, $value);
-
- $wrongKey = new TSqlMapCacheKey('wrongKey');
-
- $returnedObject = $cache->get($wrongKey);
- $this->assertNotEquals($value, $returnedObject);
- $this->assertNull($returnedObject) ;
- $this->assertEquals(0, $cache->getHitRatio());
- }
-
- /**
- * Test CacheHitMiss
- */
- function testCacheHitMiss()
- {
- $cache = $this->getCacheModel();
- $key = new TSqlMapCacheKey('testKey');
-
- $value = "testValue";
- $cache->set($key, $value);
-
- $returnedObject = $cache->get($key);
- $this->assertEquals($value, $returnedObject);
-
- $wrongKey = new TSqlMapCacheKey('wrongKey');
-
- $returnedObject = $cache->get($wrongKey);
- $this->assertNotEquals($value, $returnedObject);
- $this->assertNull($returnedObject) ;
- $this->assertEquals(0.5, $cache->getHitRatio());
- }
-}
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class CacheTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + + $this->initSqlMap(); + + //force autoload + new Account; + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + } + + /** + * Test for JIRA 29 + */ + function testJIRA28() + { + $account = $this->sqlmap->queryForObject("GetNoAccountWithCache",-99); + $this->assertNull($account); + } + + /** + * Test Cache query + */ + function testQueryWithCache() + { + $this->resetDatabase(); + + $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 === $list2); + + $account = $list1[1]; + $account->setEmailAddress("somebody@cache.com"); + + //this will cause the cache to flush + $this->sqlmap->update("UpdateAccountViaInlineParameters", $account); + + $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 !== $list3); + + $this->resetDatabase(); + } + + + /** + * Test flush Cache + */ + function testFlushDataCache() + { + $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 === $list2); + $this->sqlmap->flushCaches(); + + $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 !== $list3); + } + + /** + * + */ + function testFlushDataCacheOnExecute() + { + $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 === $list2); + $this->sqlmap->update("UpdateAccountViaInlineParameters", $list1[0]); + + $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 !== $list3); + } + + /** + */ + protected function getCacheModel() + { + $cache = new TSqlMapCacheModel(); + // $cache->setFlushInterval(5*60); + $cache->setImplementation('LRU'); + $cache->initialize($this->sqlmap); + return $cache; + } + + /** + * Test CacheHit + */ + function testCacheHit() + { + $cache = $this->getCacheModel(); + $key = new TSqlMapCacheKey('testkey'); + $cache->set($key, 'a'); + + $returnedObject = $cache->get($key); + + $this->assertEquals('a', $returnedObject); + + $this->assertEquals(1, $cache->getHitRatio()); + } + + + + /** + * Test CacheMiss + */ + function testCacheMiss() + { + $cache = $this->getCacheModel(); + $key = new TSqlMapCacheKey('testKey'); + $value = 'testValue'; + $cache->set($key, $value); + + $wrongKey = new TSqlMapCacheKey('wrongKey'); + + $returnedObject = $cache->get($wrongKey); + $this->assertNotEquals($value, $returnedObject); + $this->assertNull($returnedObject) ; + $this->assertEquals(0, $cache->getHitRatio()); + } + + /** + * Test CacheHitMiss + */ + function testCacheHitMiss() + { + $cache = $this->getCacheModel(); + $key = new TSqlMapCacheKey('testKey'); + + $value = "testValue"; + $cache->set($key, $value); + + $returnedObject = $cache->get($key); + $this->assertEquals($value, $returnedObject); + + $wrongKey = new TSqlMapCacheKey('wrongKey'); + + $returnedObject = $cache->get($wrongKey); + $this->assertNotEquals($value, $returnedObject); + $this->assertNull($returnedObject) ; + $this->assertEquals(0.5, $cache->getHitRatio()); + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/ConfigureTest.php b/tests/unit/SQLMap/ConfigureTest.php index ef2e5e31..84c77c0e 100644 --- a/tests/unit/SQLMap/ConfigureTest.php +++ b/tests/unit/SQLMap/ConfigureTest.php @@ -1,20 +1,20 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class ConfigureTest extends BaseTest
-{
-
- function testConfigureAbsolutePath()
- {
- $builder = new TDomSqlMapBuilder;
- $filename = realpath(dirname(__FILE__).'/resources/sqlmap.xml');
- $sqlmap = $builder->configure($filename);
- $this->assertNotNull($sqlmap);
- }
-}
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class ConfigureTest extends BaseTest +{ + + function testConfigureAbsolutePath() + { + $builder = new TDomSqlMapBuilder; + $filename = realpath(dirname(__FILE__).'/resources/sqlmap.xml'); + $sqlmap = $builder->configure($filename); + $this->assertNotNull($sqlmap); + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/ConnectionTest.php b/tests/unit/SQLMap/ConnectionTest.php index 138505fd..5ab1e7e7 100644 --- a/tests/unit/SQLMap/ConnectionTest.php +++ b/tests/unit/SQLMap/ConnectionTest.php @@ -1,26 +1,26 @@ -<?php
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class ConnectionTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlmap();
- }
-
- function testOpenConnection()
- {
- $conn = $this->sqlmap->openConnection();
- $this->assertFalse($conn->getIsClosed());
- $this->sqlmap->closeConnection();
- $this->assertTrue($conn->getIsClosed());
- $this->sqlmap->openConnection();
- $this->assertFalse($conn->getIsClosed());
- }
-}
-
+<?php +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class ConnectionTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlmap(); + } + + function testOpenConnection() + { + $conn = $this->sqlmap->openConnection(); + $this->assertFalse($conn->getIsClosed()); + $this->sqlmap->closeConnection(); + $this->assertTrue($conn->getIsClosed()); + $this->sqlmap->openConnection(); + $this->assertFalse($conn->getIsClosed()); + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/DelegateTest.php b/tests/unit/SQLMap/DelegateTest.php index e4c4d812..cd285d98 100644 --- a/tests/unit/SQLMap/DelegateTest.php +++ b/tests/unit/SQLMap/DelegateTest.php @@ -1,64 +1,64 @@ -<?php
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class DelegateTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
- }
-
- function testListDelegate()
- {
- $list = $this->sqlmap->queryWithRowDelegate(
- "GetAllAccountsViaResultMap", array($this, 'listHandler'));
-
- $this->assertEquals(5, count($list));
- $this->assertAccount1($list[0]);
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
- $this->assertEquals(3, $list[2]->getID());
- $this->assertEquals(4, $list[3]->getID());
- $this->assertEquals(5, $list[4]->getID());
- }
-
- /**
- * Test ExecuteQueryForMap : Hashtable.
- */
- function testExecuteQueryForMap()
- {
- $map = $this->sqlmap->QueryForMapWithRowDelegate(
- "GetAllAccountsViaResultClass", array($this, 'mapHandler'), null, "FirstName");
-
- $this->assertEquals(5, count($map));
- $this->assertAccount1($map["Joe"]);
-
- $this->assertEquals(1, $map["Joe"]->getID());
- $this->assertEquals(2, $map["Averel"]->getID());
- $this->assertEquals(3, $map["William"]->getID());
- $this->assertEquals(4, $map["Jack"]->getID());
- $this->assertEquals(5, $map["Gilles"]->getID());
- }
-
- public function listHandler($sender, $param)
- {
- $list = &$param->getList();
- $list[] = $param->result;
- $this->assertTrue($param->result instanceof Account);
- }
-
- public function mapHandler($sender, $param)
- {
- $map = &$param->getMap();
- $map[$param->getKey()] = $param->getValue();
- $this->assertTrue($param->getValue() instanceof Account);
- }
-}
-
-
-
+<?php +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class DelegateTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + } + + function testListDelegate() + { + $list = $this->sqlmap->queryWithRowDelegate( + "GetAllAccountsViaResultMap", array($this, 'listHandler')); + + $this->assertEquals(5, count($list)); + $this->assertAccount1($list[0]); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + $this->assertEquals(3, $list[2]->getID()); + $this->assertEquals(4, $list[3]->getID()); + $this->assertEquals(5, $list[4]->getID()); + } + + /** + * Test ExecuteQueryForMap : Hashtable. + */ + function testExecuteQueryForMap() + { + $map = $this->sqlmap->QueryForMapWithRowDelegate( + "GetAllAccountsViaResultClass", array($this, 'mapHandler'), null, "FirstName"); + + $this->assertEquals(5, count($map)); + $this->assertAccount1($map["Joe"]); + + $this->assertEquals(1, $map["Joe"]->getID()); + $this->assertEquals(2, $map["Averel"]->getID()); + $this->assertEquals(3, $map["William"]->getID()); + $this->assertEquals(4, $map["Jack"]->getID()); + $this->assertEquals(5, $map["Gilles"]->getID()); + } + + public function listHandler($sender, $param) + { + $list = &$param->getList(); + $list[] = $param->result; + $this->assertTrue($param->result instanceof Account); + } + + public function mapHandler($sender, $param) + { + $map = &$param->getMap(); + $map[$param->getKey()] = $param->getValue(); + $this->assertTrue($param->getValue() instanceof Account); + } +} + + + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/GroupByTest.php b/tests/unit/SQLMap/GroupByTest.php index a03a7305..eed714c9 100644 --- a/tests/unit/SQLMap/GroupByTest.php +++ b/tests/unit/SQLMap/GroupByTest.php @@ -1,43 +1,43 @@ -<?php
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-class AccountWithOrders extends Account
-{
- private $_orders = array();
-
- public function setOrders($orders)
- {
- $this->_orders = $orders;
- }
-
- public function getOrders()
- {
- return $this->_orders;
- }
-}
-
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class GroupByTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
- }
-
- function testAccountWithOrders()
- {
- $this->initScript('account-init.sql');
- $accounts = $this->sqlmap->queryForList("getAccountWithOrders");
- $this->assertEquals(5, count($accounts));
- foreach($accounts as $account)
- $this->assertEquals(2, count($account->getOrders()));
- }
-
-/**/
-}
-
+<?php +require_once(dirname(__FILE__).'/BaseTest.php'); + +class AccountWithOrders extends Account +{ + private $_orders = array(); + + public function setOrders($orders) + { + $this->_orders = $orders; + } + + public function getOrders() + { + return $this->_orders; + } +} + + +/** + * @package System.DataAccess.SQLMap + */ +class GroupByTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + } + + function testAccountWithOrders() + { + $this->initScript('account-init.sql'); + $accounts = $this->sqlmap->queryForList("getAccountWithOrders"); + $this->assertEquals(5, count($accounts)); + foreach($accounts as $account) + $this->assertEquals(2, count($account->getOrders())); + } + +/**/ +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/InheritanceTest.php b/tests/unit/SQLMap/InheritanceTest.php index 9ace1c29..41a81ae1 100644 --- a/tests/unit/SQLMap/InheritanceTest.php +++ b/tests/unit/SQLMap/InheritanceTest.php @@ -1,146 +1,146 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class InheritanceTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
-
- $this->initSqlMap();
- $this->initScript('documents-init.sql');
- }
-
- /// Test All document with no formula
- function testGetAllDocument()
- {
- $list = $this->sqlmap->queryForList("GetAllDocument");
-
- $this->assertEquals(6, count($list));
- $book = $list[0];
- $this->assertBook($book, 1, "The World of Null-A", 55);
-
- $book = $list[1];
- $this->assertBook($book, 3, "Lord of the Rings", 3587);
-
- $document = $list[2];
- $this->assertDocument($document, 5, "Le Monde");
-
- $document = $list[3];
- $this->assertDocument($document, 6, "Foundation");
-
- $news = $list[4];
- $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon");
-
- $document = $list[5];
- $this->assertDocument($document, 4, "Le Canard enchaine");
- }
-
- /// Test All document in a typed collection
- function testGetTypedCollection()
- {
- $list = $this->sqlmap->queryForList("GetTypedCollection");
-
- $this->assertEquals(6, $list->getCount());
-
- $book = $list[0];
- $this->assertBook($book, 1, "The World of Null-A", 55);
-
- $book = $list[1];
- $this->assertBook($book, 3, "Lord of the Rings", 3587);
-
- $document = $list[2];
- $this->assertDocument($document, 5, "Le Monde");
-
- $document = $list[3];
- $this->assertDocument($document, 6, "Foundation");
-
- $news = $list[4];
- $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon");
-
- $document = $list[5];
- $this->assertDocument($document, 4, "Le Canard enchaine");
- }
-
- /// Test All document with Custom Type Handler
- function testGetAllDocumentWithCustomTypeHandler()
- {
-
- //register the custom inheritance type handler
- $this->sqlmap->getTypeHandlerFactory()->register(
- 'CustomInheritance', new CustomInheritance);
-
- $list = $this->sqlmap->queryForList("GetAllDocumentWithCustomTypeHandler");
-
- $this->assertEquals(6, count($list));
- $book = $list[0];
- $this->assertBook($book, 1, "The World of Null-A", 55);
-
- $book = $list[1];
- $this->assertBook($book, 3, "Lord of the Rings", 3587);
-
- $news = $list[2];
- $this->assertNewspaper($news, 5, "Le Monde", "Paris");
-
- $book = $list[3];
- $this->assertBook($book, 6, "Foundation", 557);
-
- $news = $list[4];
- $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon");
-
- $news = $list[5];
- $this->assertNewspaper($news, 4, "Le Canard enchaine", "Paris");
- }
-
- function AssertDocument(Document $document, $id, $title)
- {
- $this->assertEquals($id, $document->getID());
- $this->assertEquals($title, $document->getTitle());
- }
-
- function AssertBook(Book $book, $id, $title, $pageNumber)
- {
- $this->assertEquals($id, $book->getId());
- $this->assertEquals($title, $book->getTitle());
- $this->assertEquals($pageNumber, (int)$book->getPageNumber());
- }
-
- function AssertNewspaper(Newspaper $news, $id, $title, $city)
- {
- $this->assertEquals($id, $news->getId());
- $this->assertEquals($title, $news->getTitle());
- $this->assertEquals($city, $news->getCity());
- }
-}
-
-
-class CustomInheritance implements ITypeHandlerCallback
-{
- public function getResult($type)
- {
- switch ($type)
- {
- case 'Monograph': case 'Book':
- return 'Book';
- case 'Tabloid': case 'Broadsheet': case 'Newspaper':
- return 'Newspaper';
- default:
- return 'Document';
- }
- }
-
- public function getParameter($parameter)
- {
- throw new TDataMapperException('not implemented');
- }
-
- public function createNewInstance($data=null)
- {
- throw new TDataMapperException('can not create');
- }
-}
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class InheritanceTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + + $this->initSqlMap(); + $this->initScript('documents-init.sql'); + } + + /// Test All document with no formula + function testGetAllDocument() + { + $list = $this->sqlmap->queryForList("GetAllDocument"); + + $this->assertEquals(6, count($list)); + $book = $list[0]; + $this->assertBook($book, 1, "The World of Null-A", 55); + + $book = $list[1]; + $this->assertBook($book, 3, "Lord of the Rings", 3587); + + $document = $list[2]; + $this->assertDocument($document, 5, "Le Monde"); + + $document = $list[3]; + $this->assertDocument($document, 6, "Foundation"); + + $news = $list[4]; + $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); + + $document = $list[5]; + $this->assertDocument($document, 4, "Le Canard enchaine"); + } + + /// Test All document in a typed collection + function testGetTypedCollection() + { + $list = $this->sqlmap->queryForList("GetTypedCollection"); + + $this->assertEquals(6, $list->getCount()); + + $book = $list[0]; + $this->assertBook($book, 1, "The World of Null-A", 55); + + $book = $list[1]; + $this->assertBook($book, 3, "Lord of the Rings", 3587); + + $document = $list[2]; + $this->assertDocument($document, 5, "Le Monde"); + + $document = $list[3]; + $this->assertDocument($document, 6, "Foundation"); + + $news = $list[4]; + $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); + + $document = $list[5]; + $this->assertDocument($document, 4, "Le Canard enchaine"); + } + + /// Test All document with Custom Type Handler + function testGetAllDocumentWithCustomTypeHandler() + { + + //register the custom inheritance type handler + $this->sqlmap->getTypeHandlerFactory()->register( + 'CustomInheritance', new CustomInheritance); + + $list = $this->sqlmap->queryForList("GetAllDocumentWithCustomTypeHandler"); + + $this->assertEquals(6, count($list)); + $book = $list[0]; + $this->assertBook($book, 1, "The World of Null-A", 55); + + $book = $list[1]; + $this->assertBook($book, 3, "Lord of the Rings", 3587); + + $news = $list[2]; + $this->assertNewspaper($news, 5, "Le Monde", "Paris"); + + $book = $list[3]; + $this->assertBook($book, 6, "Foundation", 557); + + $news = $list[4]; + $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); + + $news = $list[5]; + $this->assertNewspaper($news, 4, "Le Canard enchaine", "Paris"); + } + + function AssertDocument(Document $document, $id, $title) + { + $this->assertEquals($id, $document->getID()); + $this->assertEquals($title, $document->getTitle()); + } + + function AssertBook(Book $book, $id, $title, $pageNumber) + { + $this->assertEquals($id, $book->getId()); + $this->assertEquals($title, $book->getTitle()); + $this->assertEquals($pageNumber, (int)$book->getPageNumber()); + } + + function AssertNewspaper(Newspaper $news, $id, $title, $city) + { + $this->assertEquals($id, $news->getId()); + $this->assertEquals($title, $news->getTitle()); + $this->assertEquals($city, $news->getCity()); + } +} + + +class CustomInheritance implements ITypeHandlerCallback +{ + public function getResult($type) + { + switch ($type) + { + case 'Monograph': case 'Book': + return 'Book'; + case 'Tabloid': case 'Broadsheet': case 'Newspaper': + return 'Newspaper'; + default: + return 'Document'; + } + } + + public function getParameter($parameter) + { + throw new TDataMapperException('not implemented'); + } + + public function createNewInstance($data=null) + { + throw new TDataMapperException('can not create'); + } +} ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/ParameterMapTest.php b/tests/unit/SQLMap/ParameterMapTest.php index 5b3c3006..130b1505 100644 --- a/tests/unit/SQLMap/ParameterMapTest.php +++ b/tests/unit/SQLMap/ParameterMapTest.php @@ -1,249 +1,249 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class ParameterMapTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
- }
-
- function setup()
- {
- $this->initScript('account-init.sql');
-// $this->initScript('account-procedure.sql');
- $this->initScript('order-init.sql');
-// $this->initScript('line-item-init.sql');
- $this->initScript('category-init.sql');
- }
-
- /// Test null replacement in ParameterMap property
- function testNullValueReplacement()
- {
- $account = $this->newAccount6();
-
- $this->sqlmap->insert("InsertAccountViaParameterMap", $account);
- $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6);
-
- $this->assertNull($account->getEmailAddress(), 'no_email@provided.com');
-
- $this->assertAccount6($account);
- }
-
- /// Test Test Null Value Replacement Inline
- function testNullValueReplacementInline()
- {
- $account = $this->newAccount6();
-
- $this->sqlmap->insert("InsertAccountViaInlineParameters", $account);
- $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6);
- $this->assertNull($account->getEmailAddress());
-
- $this->assertAccount6($account);
- }
-
- /// Test Test Null Value Replacement Inline
- function testSpecifiedType()
- {
- $account = $this->newAccount6();
- $account->setEmailAddress(null);
- $this->sqlmap->insert("InsertAccountNullableEmail", $account);
- $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6);
- $this->assertAccount6($account);
- }
-
-
- /// Test Test Null Value Replacement Inline
- function testUnknownParameterClass()
- {
- $account = $this->newAccount6();
- $account->setEmailAddress(null);
- $this->sqlmap->insert("InsertAccountUknownParameterClass", $account);
- $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6);
- $this->assertAccount6($account);
- }
-
-
- /// Test null replacement in ParameterMap property
- /// for System.DateTime.MinValue
- function testNullValueReplacementForDateTimeMinValue()
- {
- $account = $this->newAccount6();
- $this->sqlmap->insert("InsertAccountViaParameterMap", $account);
- $order = new Order();
- $order->setId(99);
- $order->setCardExpiry("09/11");
- $order->setAccount($account);
- $order->setCardNumber("154564656");
- $order->setCardType("Visa");
- $order->setCity("Lyon");
- $order->setDate(null);
- $order->setPostalCode("69004");
- $order->setProvince("Rhone");
- $order->setStreet("rue Durand");
-
- $this->sqlmap->insert("InsertOrderViaParameterMap", $order);
-
- $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99);
-
- $this->assertEquals($order->getCity(), $orderTest->getCity());
- }
-
- /// Test null replacement in ParameterMap/Hahstable property
- /// for System.DateTime.MinValue
- function testNullValueReplacementForDateTimeWithHashtable()
- {
- $account = $this->newAccount6();
-
- $this->sqlmap->insert("InsertAccountViaParameterMap", $account);
-
- $order = new Order();
- $order->setId(99);
- $order->setCardExpiry("09/11");
- $order->setAccount($account);
- $order->setCardNumber("154564656");
- $order->setCardType("Visa");
- $order->setCity("Lyon");
- $order->setDate('0001-01-01 00:00:00'); //<-- null replacement
- $order->setPostalCode("69004");
- $order->setProvince("Rhone");
- $order->setStreet("rue Durand");
-
- $this->sqlmap->insert("InsertOrderViaParameterMap", $order);
-
- $orderTest = $this->sqlmap->queryForObject("GetOrderByHashTable", 99);
-
- $this->assertEquals($orderTest["Date"], '0001-01-01 00:00:00');
- }
-
- /// Test null replacement in ParameterMap property
- /// for Guid
- function testNullValueReplacementForGuidValue()
- {
- if($this->hasSupportFor('last_insert_id'))
- {
- $category = new Category();
- $category->setName("Totoasdasd");
- $category->setGuidString('00000000-0000-0000-0000-000000000000');
-
- $key = $this->sqlmap->insert("InsertCategoryNull", $category);
-
- $categoryRead = $this->sqlmap->queryForObject("GetCategory", $key);
-
- $this->assertEquals($category->getName(), $categoryRead->getName());
- $this->assertEquals('', $categoryRead->getGuidString());
- }
- }
-
-
-
-/// Test complex mapping Via hasTable
- /// <example>
- ///
- /// map.Add("Item", Item);
- /// map.Add("Order", Order);
- ///
- /// <statement>
- /// ... #Item.prop1#...#Order.prop2#
- /// </statement>
- ///
- /// </example>
- function testComplexMappingViaHasTable()
- {
- $a = new Account();
- $a->setFirstName("Joe");
-
- $param["Account"] = $a;
-
- $o = new Order();
- $o->setCity("Dalton");
- $param["Order"] = $o;
-
- $accountTest = $this->sqlmap->queryForObject("GetAccountComplexMapping", $param);
-
- $this->assertAccount1($accountTest);
- }
-
-/*
- /// Test ByteArrayTypeHandler via Picture Property
- function testByteArrayTypeHandler()
- {
- $account = $this->newAccount6();
-
- $this->sqlmap->insert("InsertAccountViaParameterMap", $account);
-
- $order = new Order();
- $order->setId(99);
- $order->setCardExpiry("09/11");
- $order->setAccount($account);
- $order->setCardNumber("154564656");
- $order->setCardType("Visa");
- $order->setCity("Lyon");
- $order->setDate(0);
- $order->setPostalCode("69004");
- $order->setProvince("Rhone");
- $order->setStreet("rue Durand");
-
- $this->sqlmap->insert("InsertOrderViaParameterMap", $order);
-
- $item = new LineItem();
- $item->setId(99);
- $item->setCode("test");
- $item->setPrice(-99.99);
- $item->setQuantity(99);
- $item->setOrder($order);
- $item->setPicture(null);
-
- // Check insert
- $this->sqlmap->insert("InsertLineItemWithPicture", $item);
-
- // select
- $item = null;
-
- $param["LineItem_ID"] = 99;
- $param["Order_ID"] = 99;
-
- $item = $this->sqlmap->queryForObject("GetSpecificLineItemWithPicture", $param);
-
- $this->assertNotNull($item->getId());
-// $this->assertNotNull($item->getPicture());
-// $this->assertEquals( GetSize(item.Picture), this.GetSize( this.GetPicture() ));
- }
-*/
-
- /// Test extend parameter map capacity
- /// (Support Requests 1043181)
- function testInsertOrderViaExtendParameterMap()
- {
- $this->sqlmap->getTypeHandlerFactory()->register('HundredsBool', new HundredsBool());
-
- $account = $this->newAccount6();
- $this->sqlmap->insert("InsertAccountViaParameterMap", $account);
-
- $order = new Order();
- $order->setId(99);
- $order->setCardExpiry("09/11");
- $order->setAccount($account);
- $order->setCardNumber("154564656");
- $order->setCardType("Visa");
- $order->setCity("Lyon");
- $order->setDate(null); //<-- null replacement
- $order->setPostalCode("69004");
- $order->setProvince("Rhone");
- $order->setStreet("rue Durand");
-
- $this->sqlmap->insert("InsertOrderViaExtendParameterMap", $order);
-
- $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99);
-
- $this->assertEquals($order->getCity(), $orderTest->getCity());
- }
-/**/
-}
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class ParameterMapTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + } + + function setup() + { + $this->initScript('account-init.sql'); +// $this->initScript('account-procedure.sql'); + $this->initScript('order-init.sql'); +// $this->initScript('line-item-init.sql'); + $this->initScript('category-init.sql'); + } + + /// Test null replacement in ParameterMap property + function testNullValueReplacement() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + + $this->assertNull($account->getEmailAddress(), 'no_email@provided.com'); + + $this->assertAccount6($account); + } + + /// Test Test Null Value Replacement Inline + function testNullValueReplacementInline() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaInlineParameters", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + $this->assertNull($account->getEmailAddress()); + + $this->assertAccount6($account); + } + + /// Test Test Null Value Replacement Inline + function testSpecifiedType() + { + $account = $this->newAccount6(); + $account->setEmailAddress(null); + $this->sqlmap->insert("InsertAccountNullableEmail", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + $this->assertAccount6($account); + } + + + /// Test Test Null Value Replacement Inline + function testUnknownParameterClass() + { + $account = $this->newAccount6(); + $account->setEmailAddress(null); + $this->sqlmap->insert("InsertAccountUknownParameterClass", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + $this->assertAccount6($account); + } + + + /// Test null replacement in ParameterMap property + /// for System.DateTime.MinValue + function testNullValueReplacementForDateTimeMinValue() + { + $account = $this->newAccount6(); + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate(null); + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaParameterMap", $order); + + $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99); + + $this->assertEquals($order->getCity(), $orderTest->getCity()); + } + + /// Test null replacement in ParameterMap/Hahstable property + /// for System.DateTime.MinValue + function testNullValueReplacementForDateTimeWithHashtable() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate('0001-01-01 00:00:00'); //<-- null replacement + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaParameterMap", $order); + + $orderTest = $this->sqlmap->queryForObject("GetOrderByHashTable", 99); + + $this->assertEquals($orderTest["Date"], '0001-01-01 00:00:00'); + } + + /// Test null replacement in ParameterMap property + /// for Guid + function testNullValueReplacementForGuidValue() + { + if($this->hasSupportFor('last_insert_id')) + { + $category = new Category(); + $category->setName("Totoasdasd"); + $category->setGuidString('00000000-0000-0000-0000-000000000000'); + + $key = $this->sqlmap->insert("InsertCategoryNull", $category); + + $categoryRead = $this->sqlmap->queryForObject("GetCategory", $key); + + $this->assertEquals($category->getName(), $categoryRead->getName()); + $this->assertEquals('', $categoryRead->getGuidString()); + } + } + + + +/// Test complex mapping Via hasTable + /// <example> + /// + /// map.Add("Item", Item); + /// map.Add("Order", Order); + /// + /// <statement> + /// ... #Item.prop1#...#Order.prop2# + /// </statement> + /// + /// </example> + function testComplexMappingViaHasTable() + { + $a = new Account(); + $a->setFirstName("Joe"); + + $param["Account"] = $a; + + $o = new Order(); + $o->setCity("Dalton"); + $param["Order"] = $o; + + $accountTest = $this->sqlmap->queryForObject("GetAccountComplexMapping", $param); + + $this->assertAccount1($accountTest); + } + +/* + /// Test ByteArrayTypeHandler via Picture Property + function testByteArrayTypeHandler() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate(0); + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaParameterMap", $order); + + $item = new LineItem(); + $item->setId(99); + $item->setCode("test"); + $item->setPrice(-99.99); + $item->setQuantity(99); + $item->setOrder($order); + $item->setPicture(null); + + // Check insert + $this->sqlmap->insert("InsertLineItemWithPicture", $item); + + // select + $item = null; + + $param["LineItem_ID"] = 99; + $param["Order_ID"] = 99; + + $item = $this->sqlmap->queryForObject("GetSpecificLineItemWithPicture", $param); + + $this->assertNotNull($item->getId()); +// $this->assertNotNull($item->getPicture()); +// $this->assertEquals( GetSize(item.Picture), this.GetSize( this.GetPicture() )); + } +*/ + + /// Test extend parameter map capacity + /// (Support Requests 1043181) + function testInsertOrderViaExtendParameterMap() + { + $this->sqlmap->getTypeHandlerFactory()->register('HundredsBool', new HundredsBool()); + + $account = $this->newAccount6(); + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate(null); //<-- null replacement + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaExtendParameterMap", $order); + + $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99); + + $this->assertEquals($order->getCity(), $orderTest->getCity()); + } +/**/ +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/PropertyAccessTest.php b/tests/unit/SQLMap/PropertyAccessTest.php index 04bb8c17..0e17e8d5 100644 --- a/tests/unit/SQLMap/PropertyAccessTest.php +++ b/tests/unit/SQLMap/PropertyAccessTest.php @@ -1,77 +1,77 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class PropertyAccessTest extends BaseTest
-{
- function testGetPublicProperty()
- {
- $account = new AccountBis();
-
- $account->Id = 10;
- $account->FirstName = "Luky";
- $account->LastName = "Luke";
- $account->EmailAddress = "luly.luke@somewhere.com";
-
- $two = new AccountBis();
- $two->Id = 12;
- $two->FirstName = "Mini Me!";
- $account->More = $two;
-
- $account6 = $this->NewAccount6();
- $two->More = $account6;
-
- $this->assertEquals(10, TPropertyAccess::get($account, 'Id'));
- $this->assertEquals(12, TPropertyAccess::get($account, 'More.Id'));
- $this->assertEquals(6, TPropertyAccess::get($account, 'More.More.Id'));
- }
-
- function testSetPublicProperty()
- {
- $account = new AccountBis();
-
- $account->Id = 10;
- $account->FirstName = "Luky";
- $account->LastName = "Luke";
- $account->EmailAddress = "luly.luke@somewhere.com";
-
- $two = new AccountBis();
- $two->Id = 12;
- $two->FirstName = "Mini Me!";
- TPropertyAccess::set($account, 'More', $two);
-
- $account6 = $this->NewAccount6();
- TPropertyAccess::set($account, 'More.More', $account6);
-
- TPropertyAccess::set($account, 'More.More.EmailAddress', 'hahaha');
-
- $this->assertEquals(10, TPropertyAccess::get($account, 'Id'));
- $this->assertEquals(12, TPropertyAccess::get($account, 'More.Id'));
- $this->assertEquals(6, TPropertyAccess::get($account, 'More.More.Id'));
-
- $this->assertEquals('hahaha',
- TPropertyAccess::get($account, 'More.More.EmailAddress'));
- }
-
- function testArrayAccessProperty()
- {
- $account = new AccountBis();
- $things['more'] = 1;
- $things['accounts'] = $this->NewAccount6();
- $account->More = $things;
-
- $this->assertEquals(6, TPropertyAccess::get($account, 'More.accounts.ID'));
-
- TPropertyAccess::set($account, 'More.accounts.EmailAddress', 'adssd');
- $this->assertEquals('adssd', TPropertyAccess::get($account, 'More.accounts.EmailAddress'));
-
- $this->assertEquals(1, TPropertyAccess::get($things, 'more'));
- }
-
-}
-
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class PropertyAccessTest extends BaseTest +{ + function testGetPublicProperty() + { + $account = new AccountBis(); + + $account->Id = 10; + $account->FirstName = "Luky"; + $account->LastName = "Luke"; + $account->EmailAddress = "luly.luke@somewhere.com"; + + $two = new AccountBis(); + $two->Id = 12; + $two->FirstName = "Mini Me!"; + $account->More = $two; + + $account6 = $this->NewAccount6(); + $two->More = $account6; + + $this->assertEquals(10, TPropertyAccess::get($account, 'Id')); + $this->assertEquals(12, TPropertyAccess::get($account, 'More.Id')); + $this->assertEquals(6, TPropertyAccess::get($account, 'More.More.Id')); + } + + function testSetPublicProperty() + { + $account = new AccountBis(); + + $account->Id = 10; + $account->FirstName = "Luky"; + $account->LastName = "Luke"; + $account->EmailAddress = "luly.luke@somewhere.com"; + + $two = new AccountBis(); + $two->Id = 12; + $two->FirstName = "Mini Me!"; + TPropertyAccess::set($account, 'More', $two); + + $account6 = $this->NewAccount6(); + TPropertyAccess::set($account, 'More.More', $account6); + + TPropertyAccess::set($account, 'More.More.EmailAddress', 'hahaha'); + + $this->assertEquals(10, TPropertyAccess::get($account, 'Id')); + $this->assertEquals(12, TPropertyAccess::get($account, 'More.Id')); + $this->assertEquals(6, TPropertyAccess::get($account, 'More.More.Id')); + + $this->assertEquals('hahaha', + TPropertyAccess::get($account, 'More.More.EmailAddress')); + } + + function testArrayAccessProperty() + { + $account = new AccountBis(); + $things['more'] = 1; + $things['accounts'] = $this->NewAccount6(); + $account->More = $things; + + $this->assertEquals(6, TPropertyAccess::get($account, 'More.accounts.ID')); + + TPropertyAccess::set($account, 'More.accounts.EmailAddress', 'adssd'); + $this->assertEquals('adssd', TPropertyAccess::get($account, 'More.accounts.EmailAddress')); + + $this->assertEquals(1, TPropertyAccess::get($things, 'more')); + } + +} + + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/ResultClassTest.php b/tests/unit/SQLMap/ResultClassTest.php index 93f93069..ec82b983 100644 --- a/tests/unit/SQLMap/ResultClassTest.php +++ b/tests/unit/SQLMap/ResultClassTest.php @@ -1,282 +1,282 @@ -<?php
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class ResultClassTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
- }
-
- /**
- * Test a boolean resultClass
- */
- function testBoolean()
- {
- $bit = $this->sqlmap->queryForObject("GetBoolean", 1);
-
- $this->assertEquals(true, $bit);
- }
-
- /**
- * Test a boolean implicit resultClass
- */
- function testBooleanWithoutResultClass()
- {
- $bit = (boolean)$this->sqlmap->queryForObject("GetBooleanWithoutResultClass", 1);
-
- $this->assertEquals(true, $bit);
- }
-
- /**
- * Test a byte resultClass
- */
- function testByte()
- {
- $letter = $this->sqlmap->queryForObject("GetByte", 1);
-
- $this->assertEquals(155, (int)$letter);
- }
-
- /**
- * Test a byte implicit resultClass
- */
- function testByteWithoutResultClass()
- {
- $letter = $this->sqlmap->queryForObject("GetByteWithoutResultClass", 1);
-
- $this->assertEquals(155, (int)$letter);
- }
-
- /**
- * Test a char resultClass
- */
- function testChar()
- {
- $letter = $this->sqlmap->queryForObject("GetChar", 1);
-
- $this->assertEquals('a', trim($letter));
- }
-
- /**
- * Test a char implicit resultClass
- */
- function testCharWithoutResultClass()
- {
- $letter = $this->sqlmap->queryForObject("GetCharWithoutResultClass", 1);
-
- $this->assertEquals('a', trim($letter));
- }
-
- /**
- * Test a DateTime resultClass
- */
- function testDateTime()
- {
- $orderDate = $this->sqlmap->queryForObject("GetDate", 1);
-
- $date = @mktime(8, 15, 00, 2, 15, 2003);
-
- $this->assertEquals($date, $orderDate->getTimeStamp());
- }
-
- /**
- * Test a DateTime implicit resultClass
- */
- function testDateTimeWithoutResultClass()
- {
- $date = $this->sqlmap->queryForObject("GetDateWithoutResultClass", 1);
- $orderDate = new TDateTime;
- $orderDate->setDateTime($date);
- $date = @mktime(8, 15, 00, 2, 15, 2003);
-
- $this->assertEquals($date, $orderDate->getTimeStamp());
- }
-
- /**
- * Test a decimal resultClass
- */
- function testDecimal()
- {
- $price = $this->sqlmap->queryForObject("GetDecimal", 1);
-
- $this->assertEquals(1.56, $price);
- }
-
- /**
- * Test a decimal implicit resultClass
- */
- function testDecimalWithoutResultClass()
- {
- $price = $this->sqlmap->queryForObject("GetDecimalWithoutResultClass", 1);
-
- $this->assertEquals(1.56, (float)$price);
- }
-
- /**
- * Test a double resultClass
- */
- function testDouble()
- {
- $price = $this->sqlmap->queryForObject("GetDouble", 1);
-
- $this->assertEquals(99.5, $price);
- }
-
- /**
- * Test a double implicit resultClass
- */
-
- function testDoubleWithoutResultClass()
- {
- $price = $this->sqlmap->queryForObject("GetDoubleWithoutResultClass", 1);
-
- $this->assertEquals(99.5, (float)$price);
- }
-
- /**
- * IBATISNET-25 Error applying ResultMap when using 'Guid' in resultClass
- */
-/* function testGuid()
- {
- Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4");
-
- Guid guid = (Guid) $this->sqlmap->queryForObject("GetGuid", 1);
-
- $this->assertEquals(newGuid, guid);
- }
-*/
-
- /**
- * Test a Guid implicit resultClass
- */
-/* function testGuidWithoutResultClass()
- {
- Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4");
-
- string guidString = Convert.ToString($this->sqlmap->queryForObject("GetGuidWithoutResultClass", 1));
-
- Guid guid = new Guid(guidString);
-
- $this->assertEquals(newGuid, guid);
- }
-*/
- /**
- * Test a int16 resultClass (integer in PHP)
- */
-
- function testInt16()
- {
- $integer = $this->sqlmap->queryForObject("GetInt16", 1);
-
- $this->assertEquals(32111, $integer);
- }
-
- /**
- * Test a int16 implicit resultClass (integer in PHP)
- */
-
- function testInt16WithoutResultClass()
- {
- $integer = $this->sqlmap->queryForObject("GetInt16WithoutResultClass", 1);
-
- $this->assertEquals(32111, (int)$integer);
- }
-
- /**
- * Test a int 32 resultClass (integer in PHP)
- */
-
-
- function testInt32()
- {
- $integer = $this->sqlmap->queryForObject("GetInt32", 1);
-
- $this->assertEquals(999999, $integer);
- }
-
- /**
- * Test a int 32 implicit resultClass (integer in PHP)
- */
-
-
- function testInt32WithoutResultClass()
- {
- $integer = $this->sqlmap->queryForObject("GetInt32WithoutResultClass", 1);
-
- $this->assertEquals(999999, (int)$integer);
- }
-
- /**
- * Test a int64 resultClass (float in PHP)
- */
-
- function testInt64()
- {
- $bigInt = $this->sqlmap->queryForObject("GetInt64", 1);
-
- $this->assertEquals(9223372036854775800, $bigInt);
- }
-
- /**
- * Test a int64 implicit resultClass (float in PHP)
- */
-
- function testInt64WithoutResultClass()
- {
- $bigInt = $this->sqlmap->queryForObject("GetInt64WithoutResultClass", 1);
-
- $this->assertEquals(9223372036854775800, (double)$bigInt);
- }
-
- /**
- * Test a single/float resultClass
- */
-
- function testSingle()
- {
- $price = (float)$this->sqlmap->queryForObject("GetSingle", 1);
-
- $this->assertEquals(92233.5, $price);
- }
-
- /**
- * Test a single/float implicit resultClass
- */
-
- function testSingleWithoutResultClass()
- {
- $price = $this->sqlmap->queryForObject("GetSingleWithoutResultClass", 1);
-
- $this->assertEquals(92233.5, (float)$price);
- }
-
- /**
- * Test a string resultClass
- */
-
- function testString()
- {
- $cardType = $this->sqlmap->queryForObject("GetString", 1);
-
- $this->assertEquals("VISA", $cardType);
- }
-
- /**
- * Test a string implicit resultClass
- */
-
- function testStringWithoutResultClass()
- {
- $cardType = $this->sqlmap->queryForObject("GetStringWithoutResultClass", 1);
-
- $this->assertEquals("VISA", $cardType);
- }
-/**/
-}
-
+<?php +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class ResultClassTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + } + + /** + * Test a boolean resultClass + */ + function testBoolean() + { + $bit = $this->sqlmap->queryForObject("GetBoolean", 1); + + $this->assertEquals(true, $bit); + } + + /** + * Test a boolean implicit resultClass + */ + function testBooleanWithoutResultClass() + { + $bit = (boolean)$this->sqlmap->queryForObject("GetBooleanWithoutResultClass", 1); + + $this->assertEquals(true, $bit); + } + + /** + * Test a byte resultClass + */ + function testByte() + { + $letter = $this->sqlmap->queryForObject("GetByte", 1); + + $this->assertEquals(155, (int)$letter); + } + + /** + * Test a byte implicit resultClass + */ + function testByteWithoutResultClass() + { + $letter = $this->sqlmap->queryForObject("GetByteWithoutResultClass", 1); + + $this->assertEquals(155, (int)$letter); + } + + /** + * Test a char resultClass + */ + function testChar() + { + $letter = $this->sqlmap->queryForObject("GetChar", 1); + + $this->assertEquals('a', trim($letter)); + } + + /** + * Test a char implicit resultClass + */ + function testCharWithoutResultClass() + { + $letter = $this->sqlmap->queryForObject("GetCharWithoutResultClass", 1); + + $this->assertEquals('a', trim($letter)); + } + + /** + * Test a DateTime resultClass + */ + function testDateTime() + { + $orderDate = $this->sqlmap->queryForObject("GetDate", 1); + + $date = @mktime(8, 15, 00, 2, 15, 2003); + + $this->assertEquals($date, $orderDate->getTimeStamp()); + } + + /** + * Test a DateTime implicit resultClass + */ + function testDateTimeWithoutResultClass() + { + $date = $this->sqlmap->queryForObject("GetDateWithoutResultClass", 1); + $orderDate = new TDateTime; + $orderDate->setDateTime($date); + $date = @mktime(8, 15, 00, 2, 15, 2003); + + $this->assertEquals($date, $orderDate->getTimeStamp()); + } + + /** + * Test a decimal resultClass + */ + function testDecimal() + { + $price = $this->sqlmap->queryForObject("GetDecimal", 1); + + $this->assertEquals(1.56, $price); + } + + /** + * Test a decimal implicit resultClass + */ + function testDecimalWithoutResultClass() + { + $price = $this->sqlmap->queryForObject("GetDecimalWithoutResultClass", 1); + + $this->assertEquals(1.56, (float)$price); + } + + /** + * Test a double resultClass + */ + function testDouble() + { + $price = $this->sqlmap->queryForObject("GetDouble", 1); + + $this->assertEquals(99.5, $price); + } + + /** + * Test a double implicit resultClass + */ + + function testDoubleWithoutResultClass() + { + $price = $this->sqlmap->queryForObject("GetDoubleWithoutResultClass", 1); + + $this->assertEquals(99.5, (float)$price); + } + + /** + * IBATISNET-25 Error applying ResultMap when using 'Guid' in resultClass + */ +/* function testGuid() + { + Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); + + Guid guid = (Guid) $this->sqlmap->queryForObject("GetGuid", 1); + + $this->assertEquals(newGuid, guid); + } +*/ + + /** + * Test a Guid implicit resultClass + */ +/* function testGuidWithoutResultClass() + { + Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); + + string guidString = Convert.ToString($this->sqlmap->queryForObject("GetGuidWithoutResultClass", 1)); + + Guid guid = new Guid(guidString); + + $this->assertEquals(newGuid, guid); + } +*/ + /** + * Test a int16 resultClass (integer in PHP) + */ + + function testInt16() + { + $integer = $this->sqlmap->queryForObject("GetInt16", 1); + + $this->assertEquals(32111, $integer); + } + + /** + * Test a int16 implicit resultClass (integer in PHP) + */ + + function testInt16WithoutResultClass() + { + $integer = $this->sqlmap->queryForObject("GetInt16WithoutResultClass", 1); + + $this->assertEquals(32111, (int)$integer); + } + + /** + * Test a int 32 resultClass (integer in PHP) + */ + + + function testInt32() + { + $integer = $this->sqlmap->queryForObject("GetInt32", 1); + + $this->assertEquals(999999, $integer); + } + + /** + * Test a int 32 implicit resultClass (integer in PHP) + */ + + + function testInt32WithoutResultClass() + { + $integer = $this->sqlmap->queryForObject("GetInt32WithoutResultClass", 1); + + $this->assertEquals(999999, (int)$integer); + } + + /** + * Test a int64 resultClass (float in PHP) + */ + + function testInt64() + { + $bigInt = $this->sqlmap->queryForObject("GetInt64", 1); + + $this->assertEquals(9223372036854775800, $bigInt); + } + + /** + * Test a int64 implicit resultClass (float in PHP) + */ + + function testInt64WithoutResultClass() + { + $bigInt = $this->sqlmap->queryForObject("GetInt64WithoutResultClass", 1); + + $this->assertEquals(9223372036854775800, (double)$bigInt); + } + + /** + * Test a single/float resultClass + */ + + function testSingle() + { + $price = (float)$this->sqlmap->queryForObject("GetSingle", 1); + + $this->assertEquals(92233.5, $price); + } + + /** + * Test a single/float implicit resultClass + */ + + function testSingleWithoutResultClass() + { + $price = $this->sqlmap->queryForObject("GetSingleWithoutResultClass", 1); + + $this->assertEquals(92233.5, (float)$price); + } + + /** + * Test a string resultClass + */ + + function testString() + { + $cardType = $this->sqlmap->queryForObject("GetString", 1); + + $this->assertEquals("VISA", $cardType); + } + + /** + * Test a string implicit resultClass + */ + + function testStringWithoutResultClass() + { + $cardType = $this->sqlmap->queryForObject("GetStringWithoutResultClass", 1); + + $this->assertEquals("VISA", $cardType); + } +/**/ +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/ResultMapTest.php b/tests/unit/SQLMap/ResultMapTest.php index 4909c37f..09fff11d 100644 --- a/tests/unit/SQLMap/ResultMapTest.php +++ b/tests/unit/SQLMap/ResultMapTest.php @@ -1,280 +1,280 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class ResultMapTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
- new Order;
- new LineItemCollection;
- new Account;
- }
-
- function resetDatabase()
- {
- $this->initScript('account-init.sql');
- $this->initScript('order-init.sql');
- $this->initScript('line-item-init.sql');
-// $this->initScript('enumeration-init.sql');
- }
-
- function testColumnsByName()
- {
- $order = $this->sqlmap->QueryForObject('GetOrderLiteByColumnName', 1);
- $this->assertOrder1($order);
- }
-
- function testColumnsByIndex()
- {
- $order = $this->sqlmap->QueryForObject("GetOrderLiteByColumnIndex", 1);
- $this->assertOrder1($order);
- }
-
-
- function testExtendedResultMap()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsNoLazyLoad", 1);
- $this->assertOrder1($order);
- $this->assertTrue($order->getLineItemsList() instanceof TList);
- $this->assertEquals(2, $order->getLineItemsList()->getCount());
- }
-
- function testLazyLoad()
- {
- $order = $this->sqlmap->QueryForObject("GetOrderWithLineItems", 1);
- $this->assertOrder1($order);
- $this->assertNotNull($order->getLineItemsList());
- $this->assertFalse($order->getLineItemsList() instanceof TList);
- $this->assertEquals(2, $order->getLineItemsList()->getCount());
-
- // After a call to a method from a proxy object,
- // the proxy object is replaced by the real object.
- $this->assertTrue($order->getLineItemsList() instanceof TList);
- $this->assertEquals(2, $order->getLineItemsList()->getCount());
- }
-
- function testLazyLoadWithOpenConnection()
- {
- $this->sqlmap->openConnection();
-
- $this->testLazyLoad();
- $this->sqlmap->closeConnection();
- }
-
- function testLazyWithTypedCollectionMapping()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollection", 1);
- $this->assertOrder1($order);
- $this->assertNotNull($order->getLineItems());
- $this->assertFalse($order->getLineItemsList() instanceof LineItemCollection);
-
- $this->assertEquals(2, $order->getLineItems()->getCount());
-
- // After a call to a method from a proxy object,
- // the proxy object is replaced by the real object.
- $this->assertTrue($order->getLineItems() instanceof LineItemCollection);
- foreach($order->getLineItems() as $item)
- {
- $this->assertNotNull($item);
- $this->assertTrue($item instanceof LineItem);
- }
- }
-
- function testNullValueReplacementOnString()
- {
- $account = $this->sqlmap->queryForObject("GetAccountViaColumnName", 5);
- $this->assertEquals("no_email@provided.com", $account->getEmailAddress());
- }
-
- function testTypeSpecified()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithTypes", 1);
- $this->assertOrder1($order);
- }
-
-
- function testComplexObjectMapping()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithAccount", 1);
- $this->assertOrder1($order);
- $this->assertAccount1($order->getAccount());
- }
-
- function testCollectionMappingAndExtends()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsCollection", 1);
- $this->assertOrder1($order);
-
- // Check strongly typed collection
- $this->assertNotNull($order->getLineItems());
- $this->assertEquals(2, $order->getLineItems()->getCount());
- }
-
- function testListMapping()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithLineItems", 1);
- $this->assertOrder1($order);
-
- // Check TList collection
- $this->assertNotNull($order->getLineItemsList());
- $this->assertEquals(2, $order->getLineItemsList()->getCount());
- }
-
- function testArrayMapping()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithLineItemArray", 1);
- $this->assertOrder1($order);
- $this->assertNotNull($order->getLineItemsArray());
- $this->assertTrue(is_array($order->getLineItemsArray()));
- $this->assertEquals(2, count($order->getLineItemsArray()));
- }
-
- function testTypedCollectionMapping()
- {
- $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollectionNoLazy", 1);
- $this->assertOrder1($order);
- $this->assertNotNull($order->getLineItems());
- $this->assertTrue($order->getLineItems() instanceof LineItemCollection);
- $this->assertEquals(2, $order->getLineItems()->getCount());
- foreach($order->getLineItems() as $item)
- {
- $this->assertNotNull($item);
- $this->assertTrue($item instanceof LineItem);
- }
- }
-
- function testHashArrayMapping()
- {
- $order = $this->sqlmap->queryForObject("GetOrderAsHastable", 1);
- $this->assertOrder1AsHashArray($order);
- }
-
- function testNestedObjects()
- {
- $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite", 1);
-
- $this->assertOrder1($order);
- $this->assertNotNull($order->getFavouriteLineItem());
- $this->assertEquals(2, (int)$order->getFavouriteLineItem()->getID());
- $this->assertEquals("ESM-23", $order->getFavouriteLineItem()->getCode());
-
- }
- function testNestedObjects2()
- {
- $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite2", 1);
- $this->assertOrder1($order);
-
- $this->assertNotNull($order->getFavouriteLineItem());
- $this->assertEquals(2, (int)$order->getFavouriteLineItem()->getID());
- $this->assertEquals("ESM-23", $order->getFavouriteLineItem()->getCode());
- }
-
- function testImplicitResultMaps()
- {
- $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite3", 1);
-
- // *** force date to timestamp since data type can't be
- // *** explicity known without mapping
- $order->setDate(new TDateTime($order->getDate()));
-
- $this->assertOrder1($order);
-
- $this->assertNotNull($order->getFavouriteLineItem());
- $this->assertEquals(2, $order->getFavouriteLineItem()->getID());
- $this->assertEquals("ESM-23", $order->getFavouriteLineItem()->getCode());
- }
-
- function testCompositeKeyMapping()
- {
- $this->resetDatabase();
-
- $order1 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 1);
- $order2 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 2);
-
- $this->assertNotNull($order1);
- $this->assertNotNull($order1->getFavouriteLineItem());
- $this->assertEquals(2, $order1->getFavouriteLineItem()->getID());
-
- $this->assertNotNull($order2);
- $this->assertNotNull($order2->getFavouriteLineItem());
- $this->assertEquals(1, $order2->getFavouriteLineItem()->getID());
- }
-
- function testSimpleTypeMapping()
- {
- $this->resetDatabase();
-
- $list = $this->sqlmap->QueryForList("GetAllCreditCardNumbersFromOrders", null);
-
- $this->assertEquals(5, count($list));
- $this->assertEquals("555555555555", $list[0]);
- }
-
-
- function testDecimalTypeMapping()
- {
- $this->resetDatabase();
-
- $param["LineItem_ID"] = 1;
- $param["Order_ID"] = 10;
- $price = $this->sqlmap->queryForObject("GetLineItemPrice", $param);
- $this->assertEquals(gettype($price), 'double');
- $this->assertEquals(45.43, $price);
- }
-
-//todo
-/*
- function testNullValueReplacementOnEnum()
- {
- $enum['Id'] = 99;
- $enum['Day'] = 'Days.Thu';
- $enum['Color'] = 'Colors.Blue';
- $enum['Month'] = 'Months.All';
-
- $this->sqlmap->insert("InsertEnumViaParameterMap", $enum);
-
- $enumClass = $this->sqlmap->queryForObject("GetEnumerationNullValue", 99);
-
- $this->assertEquals($enumClass['Day'], 'Days.Thu');
- $this->asserEquals($enumClass['Color'], 'Colors.Blue');
- $this->assertEquals($enumClass['Month'], 'Months.All');
- }
-
-
- function testByteArrayMapping()
- {
- }
-
- function testNullValueReplacementOnDecimal()
- {
- }
-
- function testNullValueReplacementOnDateTime()
- {
- }
-*/
-
-//future work
-
-/*
- //requires dynamic SQL
- function testDynamiqueCompositeKeyMapping()
- {
- $order1 = $this->sqlmap->queryForObject("GetOrderWithDynFavouriteLineItem", 1);
-
- $this->assertNotNull($order1);
- $this->assertNotNull($order1->getFavouriteLineItem());
- var_dump($order1);
- $this->assertEquals(2, $order1->getFavouriteLineItem()->getID());
- }
-*/
-
-}
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class ResultMapTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + new Order; + new LineItemCollection; + new Account; + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + $this->initScript('line-item-init.sql'); +// $this->initScript('enumeration-init.sql'); + } + + function testColumnsByName() + { + $order = $this->sqlmap->QueryForObject('GetOrderLiteByColumnName', 1); + $this->assertOrder1($order); + } + + function testColumnsByIndex() + { + $order = $this->sqlmap->QueryForObject("GetOrderLiteByColumnIndex", 1); + $this->assertOrder1($order); + } + + + function testExtendedResultMap() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsNoLazyLoad", 1); + $this->assertOrder1($order); + $this->assertTrue($order->getLineItemsList() instanceof TList); + $this->assertEquals(2, $order->getLineItemsList()->getCount()); + } + + function testLazyLoad() + { + $order = $this->sqlmap->QueryForObject("GetOrderWithLineItems", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItemsList()); + $this->assertFalse($order->getLineItemsList() instanceof TList); + $this->assertEquals(2, $order->getLineItemsList()->getCount()); + + // After a call to a method from a proxy object, + // the proxy object is replaced by the real object. + $this->assertTrue($order->getLineItemsList() instanceof TList); + $this->assertEquals(2, $order->getLineItemsList()->getCount()); + } + + function testLazyLoadWithOpenConnection() + { + $this->sqlmap->openConnection(); + + $this->testLazyLoad(); + $this->sqlmap->closeConnection(); + } + + function testLazyWithTypedCollectionMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollection", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItems()); + $this->assertFalse($order->getLineItemsList() instanceof LineItemCollection); + + $this->assertEquals(2, $order->getLineItems()->getCount()); + + // After a call to a method from a proxy object, + // the proxy object is replaced by the real object. + $this->assertTrue($order->getLineItems() instanceof LineItemCollection); + foreach($order->getLineItems() as $item) + { + $this->assertNotNull($item); + $this->assertTrue($item instanceof LineItem); + } + } + + function testNullValueReplacementOnString() + { + $account = $this->sqlmap->queryForObject("GetAccountViaColumnName", 5); + $this->assertEquals("no_email@provided.com", $account->getEmailAddress()); + } + + function testTypeSpecified() + { + $order = $this->sqlmap->queryForObject("GetOrderWithTypes", 1); + $this->assertOrder1($order); + } + + + function testComplexObjectMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithAccount", 1); + $this->assertOrder1($order); + $this->assertAccount1($order->getAccount()); + } + + function testCollectionMappingAndExtends() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsCollection", 1); + $this->assertOrder1($order); + + // Check strongly typed collection + $this->assertNotNull($order->getLineItems()); + $this->assertEquals(2, $order->getLineItems()->getCount()); + } + + function testListMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItems", 1); + $this->assertOrder1($order); + + // Check TList collection + $this->assertNotNull($order->getLineItemsList()); + $this->assertEquals(2, $order->getLineItemsList()->getCount()); + } + + function testArrayMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemArray", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItemsArray()); + $this->assertTrue(is_array($order->getLineItemsArray())); + $this->assertEquals(2, count($order->getLineItemsArray())); + } + + function testTypedCollectionMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollectionNoLazy", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItems()); + $this->assertTrue($order->getLineItems() instanceof LineItemCollection); + $this->assertEquals(2, $order->getLineItems()->getCount()); + foreach($order->getLineItems() as $item) + { + $this->assertNotNull($item); + $this->assertTrue($item instanceof LineItem); + } + } + + function testHashArrayMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderAsHastable", 1); + $this->assertOrder1AsHashArray($order); + } + + function testNestedObjects() + { + $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite", 1); + + $this->assertOrder1($order); + $this->assertNotNull($order->getFavouriteLineItem()); + $this->assertEquals(2, (int)$order->getFavouriteLineItem()->getID()); + $this->assertEquals("ESM-23", $order->getFavouriteLineItem()->getCode()); + + } + function testNestedObjects2() + { + $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite2", 1); + $this->assertOrder1($order); + + $this->assertNotNull($order->getFavouriteLineItem()); + $this->assertEquals(2, (int)$order->getFavouriteLineItem()->getID()); + $this->assertEquals("ESM-23", $order->getFavouriteLineItem()->getCode()); + } + + function testImplicitResultMaps() + { + $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite3", 1); + + // *** force date to timestamp since data type can't be + // *** explicity known without mapping + $order->setDate(new TDateTime($order->getDate())); + + $this->assertOrder1($order); + + $this->assertNotNull($order->getFavouriteLineItem()); + $this->assertEquals(2, $order->getFavouriteLineItem()->getID()); + $this->assertEquals("ESM-23", $order->getFavouriteLineItem()->getCode()); + } + + function testCompositeKeyMapping() + { + $this->resetDatabase(); + + $order1 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 1); + $order2 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 2); + + $this->assertNotNull($order1); + $this->assertNotNull($order1->getFavouriteLineItem()); + $this->assertEquals(2, $order1->getFavouriteLineItem()->getID()); + + $this->assertNotNull($order2); + $this->assertNotNull($order2->getFavouriteLineItem()); + $this->assertEquals(1, $order2->getFavouriteLineItem()->getID()); + } + + function testSimpleTypeMapping() + { + $this->resetDatabase(); + + $list = $this->sqlmap->QueryForList("GetAllCreditCardNumbersFromOrders", null); + + $this->assertEquals(5, count($list)); + $this->assertEquals("555555555555", $list[0]); + } + + + function testDecimalTypeMapping() + { + $this->resetDatabase(); + + $param["LineItem_ID"] = 1; + $param["Order_ID"] = 10; + $price = $this->sqlmap->queryForObject("GetLineItemPrice", $param); + $this->assertEquals(gettype($price), 'double'); + $this->assertEquals(45.43, $price); + } + +//todo +/* + function testNullValueReplacementOnEnum() + { + $enum['Id'] = 99; + $enum['Day'] = 'Days.Thu'; + $enum['Color'] = 'Colors.Blue'; + $enum['Month'] = 'Months.All'; + + $this->sqlmap->insert("InsertEnumViaParameterMap", $enum); + + $enumClass = $this->sqlmap->queryForObject("GetEnumerationNullValue", 99); + + $this->assertEquals($enumClass['Day'], 'Days.Thu'); + $this->asserEquals($enumClass['Color'], 'Colors.Blue'); + $this->assertEquals($enumClass['Month'], 'Months.All'); + } + + + function testByteArrayMapping() + { + } + + function testNullValueReplacementOnDecimal() + { + } + + function testNullValueReplacementOnDateTime() + { + } +*/ + +//future work + +/* + //requires dynamic SQL + function testDynamiqueCompositeKeyMapping() + { + $order1 = $this->sqlmap->queryForObject("GetOrderWithDynFavouriteLineItem", 1); + + $this->assertNotNull($order1); + $this->assertNotNull($order1->getFavouriteLineItem()); + var_dump($order1); + $this->assertEquals(2, $order1->getFavouriteLineItem()->getID()); + } +*/ + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/SelectKeyTest.php b/tests/unit/SQLMap/SelectKeyTest.php index 6ed48165..34ffbbb7 100644 --- a/tests/unit/SQLMap/SelectKeyTest.php +++ b/tests/unit/SQLMap/SelectKeyTest.php @@ -1,120 +1,120 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class SelectKeyTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
-
- //force autoload
- new Account;
- new Order;
- new LineItem;
- new LineItemCollection;
- new A; new B; new C; new D; new E; new F;
- }
-
- /**
- * Test Insert with post GeneratedKey
- */
- function testInsertPostKey()
- {
- $this->initScript('line-item-init.sql');
-
- $item = new LineItem();
-
- $item->setId(10);
- $item->setCode("blah");
- $item->setOrder(new Order());
- $item->getOrder()->setId(9);
- $item->setPrice(44.00);
- $item->setQuantity(1);
-
- $key = $this->sqlmap->Insert("InsertLineItemPostKey", $item);
-
- $this->assertEquals(99, $key);
- $this->assertEquals(99, $item->getId());
-
- $param["Order_ID"] = 9;
- $param["LineItem_ID"] =10;
- $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param);
-
- $this->assertNotNull($testItem);
- $this->assertEquals(10, $testItem->getId());
-
- $this->initScript('line-item-init.sql');
- }
-
- /**
- * Test Insert pre GeneratedKey
- */
- function testInsertPreKey()
- {
- $this->initScript('line-item-init.sql');
-
- $item = new LineItem();
-
- $item->setId(10);
- $item->setCode("blah");
- $item->setOrder(new Order());
- $item->getOrder()->setId(9);
- $item->setPrice(44.00);
- $item->setQuantity(1);
-
- $key = $this->sqlmap->Insert("InsertLineItemPreKey", $item);
-
- $this->assertEquals(99, $key);
- $this->assertEquals(99, $item->getId());
-
- $param["Order_ID"] = 9;
- $param["LineItem_ID"] = 99;
-
- $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param);
-
- $this->assertNotNull($testItem);
- $this->assertEquals(99, $testItem->getId());
-
- $this->initScript('line-item-init.sql');
- }
-
- /**
- * Test Test Insert No Key
- */
- function testInsertNoKey()
- {
- $this->initScript('line-item-init.sql');
-
- $item = new LineItem();
-
- $item->setId(100);
- $item->setCode("blah");
- $item->setOrder(new Order());
- $item->getOrder()->setId(9);
- $item->setPrice(44.00);
- $item->setQuantity(1);
-
-
- $key = $this->sqlmap->Insert("InsertLineItemNoKey", $item);
-
- $this->assertNull($key);
- $this->assertEquals(100, $item->getId());
-
- $param["Order_ID"] = 9;
- $param["LineItem_ID"] = 100;
-
- $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param);
-
- $this->assertNotNull($testItem);
- $this->assertEquals(100, $testItem->getId());
-
- $this->initScript('line-item-init.sql');
- }
-}
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class SelectKeyTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + + //force autoload + new Account; + new Order; + new LineItem; + new LineItemCollection; + new A; new B; new C; new D; new E; new F; + } + + /** + * Test Insert with post GeneratedKey + */ + function testInsertPostKey() + { + $this->initScript('line-item-init.sql'); + + $item = new LineItem(); + + $item->setId(10); + $item->setCode("blah"); + $item->setOrder(new Order()); + $item->getOrder()->setId(9); + $item->setPrice(44.00); + $item->setQuantity(1); + + $key = $this->sqlmap->Insert("InsertLineItemPostKey", $item); + + $this->assertEquals(99, $key); + $this->assertEquals(99, $item->getId()); + + $param["Order_ID"] = 9; + $param["LineItem_ID"] =10; + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertEquals(10, $testItem->getId()); + + $this->initScript('line-item-init.sql'); + } + + /** + * Test Insert pre GeneratedKey + */ + function testInsertPreKey() + { + $this->initScript('line-item-init.sql'); + + $item = new LineItem(); + + $item->setId(10); + $item->setCode("blah"); + $item->setOrder(new Order()); + $item->getOrder()->setId(9); + $item->setPrice(44.00); + $item->setQuantity(1); + + $key = $this->sqlmap->Insert("InsertLineItemPreKey", $item); + + $this->assertEquals(99, $key); + $this->assertEquals(99, $item->getId()); + + $param["Order_ID"] = 9; + $param["LineItem_ID"] = 99; + + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertEquals(99, $testItem->getId()); + + $this->initScript('line-item-init.sql'); + } + + /** + * Test Test Insert No Key + */ + function testInsertNoKey() + { + $this->initScript('line-item-init.sql'); + + $item = new LineItem(); + + $item->setId(100); + $item->setCode("blah"); + $item->setOrder(new Order()); + $item->getOrder()->setId(9); + $item->setPrice(44.00); + $item->setQuantity(1); + + + $key = $this->sqlmap->Insert("InsertLineItemNoKey", $item); + + $this->assertNull($key); + $this->assertEquals(100, $item->getId()); + + $param["Order_ID"] = 9; + $param["LineItem_ID"] = 100; + + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertEquals(100, $testItem->getId()); + + $this->initScript('line-item-init.sql'); + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/SqlMapCacheTest.php b/tests/unit/SQLMap/SqlMapCacheTest.php index a2593e1a..f1746115 100644 --- a/tests/unit/SQLMap/SqlMapCacheTest.php +++ b/tests/unit/SQLMap/SqlMapCacheTest.php @@ -1,77 +1,77 @@ -<?php
-
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class SqlMapCacheTest extends PHPUnit2_Framework_TestCase
-{
- function testFIFOCache()
- {
- $fifo = new TSqlMapFifoCache(2);
- $object1 = new TSqlMapper;
- $object2 = new TComponent;
- $object3 = new TMapper;
-
- $key1 = 'key1';
- $key2 = 'key2';
- $key3 = 'key3';
-
- $fifo->set($key1, $object1);
- $fifo->set($key2, $object2);
-
- $this->assertTrue($object1 === $fifo->get($key1));
- $this->assertTrue($object2 === $fifo->get($key2));
-
- //object 1 should be removed
- $fifo->set($key3, $object3);
-
- $this->assertNull($fifo->get($key1));
- $this->assertTrue($object2 === $fifo->get($key2));
- $this->assertTrue($object3 === $fifo->get($key3));
-
- //object 2 should be removed
- $fifo->set($key1, $object1);
-
- $this->assertNull($fifo->get($key2));
- $this->assertTrue($object3 === $fifo->get($key3));
- $this->assertTrue($object1 === $fifo->get($key1));
- }
-
- function testLruCache()
- {
- $lru = new TSqlMapLruCache(2);
-
- $object1 = new TSqlMapper;
- $object2 = new TComponent;
- $object3 = new TMapper;
-
- $key1 = 'key1';
- $key2 = 'key2';
- $key3 = 'key3';
-
- $lru->set($key1, $object1);
- $lru->set($key2, $object2);
-
- $this->assertTrue($object2 === $lru->get($key2));
- $this->assertTrue($object1 === $lru->get($key1));
-
- //object 2 should be removed, i.e. least recently used
- $lru->set($key3, $object3);
-
- $this->assertNull($lru->get($key2));
- $this->assertTrue($object1 === $lru->get($key1));
- $this->assertTrue($object3 === $lru->get($key3));
-
- //object 1 will be removed
- $lru->set($key2, $object2);
-
- $this->assertNull($lru->get($key1));
- $this->assertTrue($object2 === $lru->get($key2));
- $this->assertTrue($object3 === $lru->get($key3));
- }
-}
-
-
+<?php + +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class SqlMapCacheTest extends PHPUnit2_Framework_TestCase +{ + function testFIFOCache() + { + $fifo = new TSqlMapFifoCache(2); + $object1 = new TSqlMapper; + $object2 = new TComponent; + $object3 = new TMapper; + + $key1 = 'key1'; + $key2 = 'key2'; + $key3 = 'key3'; + + $fifo->set($key1, $object1); + $fifo->set($key2, $object2); + + $this->assertTrue($object1 === $fifo->get($key1)); + $this->assertTrue($object2 === $fifo->get($key2)); + + //object 1 should be removed + $fifo->set($key3, $object3); + + $this->assertNull($fifo->get($key1)); + $this->assertTrue($object2 === $fifo->get($key2)); + $this->assertTrue($object3 === $fifo->get($key3)); + + //object 2 should be removed + $fifo->set($key1, $object1); + + $this->assertNull($fifo->get($key2)); + $this->assertTrue($object3 === $fifo->get($key3)); + $this->assertTrue($object1 === $fifo->get($key1)); + } + + function testLruCache() + { + $lru = new TSqlMapLruCache(2); + + $object1 = new TSqlMapper; + $object2 = new TComponent; + $object3 = new TMapper; + + $key1 = 'key1'; + $key2 = 'key2'; + $key3 = 'key3'; + + $lru->set($key1, $object1); + $lru->set($key2, $object2); + + $this->assertTrue($object2 === $lru->get($key2)); + $this->assertTrue($object1 === $lru->get($key1)); + + //object 2 should be removed, i.e. least recently used + $lru->set($key3, $object3); + + $this->assertNull($lru->get($key2)); + $this->assertTrue($object1 === $lru->get($key1)); + $this->assertTrue($object3 === $lru->get($key3)); + + //object 1 will be removed + $lru->set($key2, $object2); + + $this->assertNull($lru->get($key1)); + $this->assertTrue($object2 === $lru->get($key2)); + $this->assertTrue($object3 === $lru->get($key3)); + } +} + + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/StatementTest.php b/tests/unit/SQLMap/StatementTest.php index b014dea4..b549835f 100644 --- a/tests/unit/SQLMap/StatementTest.php +++ b/tests/unit/SQLMap/StatementTest.php @@ -1,1134 +1,1134 @@ -<?php
-require_once(dirname(__FILE__).'/BaseTest.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class StatementTest extends BaseTest
-{
- function __construct()
- {
- parent::__construct();
- $this->initSqlMap();
-
- //force autoload
- new Account;
- new Order;
- new LineItem;
- new LineItemCollection;
- new A; new B; new C; new D; new E; new F;
- }
-
- public function setup()
- {
-
- }
-
- function resetDatabase()
- {
- $this->initScript('account-init.sql');
- $this->initScript('order-init.sql');
- $this->initScript('line-item-init.sql');
-// $this->initScript('enumeration-init.sql');
- $this->initScript('other-init.sql');
- }
-
-
- #region Object Query tests
-
- /**
- * Test Open connection with a connection string
- */
- function testOpenConnection()
- {
- $this->sqlmap->OpenConnection($this->sqlmap->getDataProvider()->getConnectionString());
- $account= $this->sqlmap->QueryForObject("SelectWithProperty");
- $this->sqlmap->CloseConnection();
- $this->assertAccount1($account);
- }
-
- /**
- * Test use a statement with property subtitution
- * (JIRA 22)
- */
- function testSelectWithProperty()
- {
- $account= $this->sqlmap->QueryForObject("SelectWithProperty");
- $this->assertAccount1($account);
- }
-
- /**
- * Test ExecuteQueryForObject Via ColumnName
- */
- function testExecuteQueryForObjectViaColumnName()
- {
- $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
- $this->assertAccount1($account);
- }
-
- /**
- * Test ExecuteQueryForObject Via ColumnIndex
- */
- function testExecuteQueryForObjectViaColumnIndex()
- {
- $account= $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 1);
- $this->assertAccount1($account);
- }
-
- /**
- * Test ExecuteQueryForObject Via ResultClass
- */
- function testExecuteQueryForObjectViaResultClass()
- {
- $account= $this->sqlmap->QueryForObject("GetAccountViaResultClass", 1);
- $this->assertAccount1($account);
- }
-
- /**
- * Test ExecuteQueryForObject With simple ResultClass : string
- */
- function testExecuteQueryForObjectWithSimpleResultClass()
- {
- $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultClass", 1);
- $this->assertEquals("Joe.Dalton@somewhere.com", $email);
- }
-
- /**
- * Test ExecuteQueryForObject With simple ResultMap : string
- */
- function testExecuteQueryForObjectWithSimpleResultMap()
- {
- $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultMap", 1);
- $this->assertEquals("Joe.Dalton@somewhere.com", $email);
- }
-
- /**
- * Test Primitive ReturnValue : TDateTime
- */
- function testPrimitiveReturnValue()
- {
- $CardExpiry = $this->sqlmap->QueryForObject("GetOrderCardExpiryViaResultClass", 1);
- $date = @mktime(8, 15, 00, 2, 15, 2003);
- $this->assertEquals($date, $CardExpiry->getTimeStamp());
- }
-
- /**
- * Test ExecuteQueryForObject with result object : Account
- */
- function testExecuteQueryForObjectWithResultObject()
- {
- $account= new Account();
- $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1, $account);
- $this->assertAccount1($account);
- $this->assertTrue($account == $testAccount);
- }
-
- /**
- * Test ExecuteQueryForObject as array
- */
- function testExecuteQueryForObjectAsHashArray()
- {
- $account = $this->sqlmap->QueryForObject("GetAccountAsHashtable", 1);
- $this->assertAccount1AsHashArray($account);
- }
-
- /**
- * Test ExecuteQueryForObject as Hashtable ResultClass
- */
- function testExecuteQueryForObjectAsHashtableResultClass()
- {
- $account = $this->sqlmap->QueryForObject("GetAccountAsHashtableResultClass", 1);
- $this->assertAccount1AsHashArray($account);
- }
-
- /**
- * Test ExecuteQueryForObject via Hashtable
- */
- function testExecuteQueryForObjectViaHashtable()
- {
- $param["LineItem_ID"] = 2;
- $param["Order_ID"] = 9;
-
- $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param);
-
- $this->assertNotNull($testItem);
- $this->assertEquals("TSM-12", $testItem->getCode());
- }
- /**/
-
- //TODO: Test Query Dynamic Sql Element
- function testQueryDynamicSqlElement()
- {
- //$list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID");
-
- //$this->assertEquals("Joe.Dalton@somewhere.com", $list[0]);
-
- //list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName");
-
- //$this->assertEquals("Averel.Dalton@somewhere.com", $list[0]);
-
- }
-
- // TODO: Test Execute QueryForList With ResultMap With Dynamic Element
- function testExecuteQueryForListWithResultMapWithDynamicElement()
- {
- //$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE");
-
- //$this->assertAccount1$list[0]);
- //$this->assertEquals(3, $list->getCount());
- //$this->assertEquals(1, $list[0]->getID());
- //$this->assertEquals(2, $list[1]->getID());
- //$this->assertEquals(4, $list[2]->getID());
-
- //list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "=");
-
- //$this->assertEquals(0, $list->getCount());
- }
-
-
-
- /**
- * Test Get Account Via Inline Parameters
- */
- function testExecuteQueryForObjectViaInlineParameters()
- {
- $account= new Account();
- $account->setID(1);
-
- $testAccount = $this->sqlmap->QueryForObject("GetAccountViaInlineParameters", $account);
-
- $this->assertAccount1($testAccount);
- }
- /**/
-
- // TODO: Test ExecuteQuery For Object With Enum property
-
- function testExecuteQueryForObjectWithEnum()
- {
- //$enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 1);
-
- //$this->assertEquals(enumClass.Day, Days.Sat);
- //$this->assertEquals(enumClass.Color, Colors.Red);
- //$this->assertEquals(enumClass.Month, Months.August);
-
- //enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 3) as Enumeration;
-
- //$this->assertEquals(enumClass.Day, Days.Mon);
- //$this->assertEquals(enumClass.Color, Colors.Blue);
- //$this->assertEquals(enumClass.Month, Months.September);*/
- }
-
- #endregion
-
- #region List Query tests
-
- /**
- * Test QueryForList with Hashtable ResultMap
- */
- function testQueryForListWithHashtableResultMap()
- {
- $this->initScript('account-init.sql');
- $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashMapViaResultMap");
-
- $this->assertAccount1AsHashArray($list[0]);
- $this->assertEquals(5, count($list));
-
- $this->assertEquals(1, (int)$list[0]["Id"]);
- $this->assertEquals(2, (int)$list[1]["Id"]);
- $this->assertEquals(3, (int)$list[2]["Id"]);
- $this->assertEquals(4, (int)$list[3]["Id"]);
- $this->assertEquals(5, (int)$list[4]["Id"]);
- }
-
- /**
- * Test QueryForList with Hashtable ResultClass
- */
- function testQueryForListWithHashtableResultClass()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashtableViaResultClass");
-
- $this->assertAccount1AsHashArray($list[0]);
- $this->assertEquals(5, count($list));
-
- $this->assertEquals(1, (int)$list[0]["Id"]);
- $this->assertEquals(2, (int)$list[1]["Id"]);
- $this->assertEquals(3, (int)$list[2]["Id"]);
- $this->assertEquals(4, (int)$list[3]["Id"]);
- $this->assertEquals(5, (int)$list[4]["Id"]);
- }
-
- /**
- * Test QueryForList with IList ResultClass
- */
- function testQueryForListWithIListResultClass()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccountsAsArrayListViaResultClass");
-
- $listAccount = $list[0];
-
- $this->assertEquals(1,(int)$listAccount[0]);
- $this->assertEquals("Joe",$listAccount[1]);
- $this->assertEquals("Dalton",$listAccount[2]);
- $this->assertEquals("Joe.Dalton@somewhere.com",$listAccount[3]);
-
- $this->assertEquals(5, count($list));
-
- $listAccount = $list[0];
- $this->assertEquals(1, (int)$listAccount[0]);
- $listAccount = $list[1];
- $this->assertEquals(2, (int)$listAccount[0]);
- $listAccount = $list[2];
- $this->assertEquals(3, (int)$listAccount[0]);
- $listAccount = $list[3];
- $this->assertEquals(4, (int)$listAccount[0]);
- $listAccount = $list[4];
- $this->assertEquals(5, (int)$listAccount[0]);
- }
-
- /**
- * Test QueryForList With ResultMap, result collection as ArrayList
- */
- function testQueryForListWithResultMap()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap");
-
- $this->assertAccount1($list[0]);
- $this->assertEquals(5, count($list));
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
- $this->assertEquals(3, $list[2]->getID());
- $this->assertEquals(4, $list[3]->getID());
- $this->assertEquals(5, $list[4]->getID());
- }
-
- /**
- * Test ExecuteQueryForPaginatedList
- */
- function testExecuteQueryForPaginatedList()
- {
- // Get List of all 5
- $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 2);
-
- // Test initial state (page 0)
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertAccount1($list[0]);
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
-
- // Test illegal previous page (no effect, state should be same)
- $list->PreviousPage();
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertAccount1($list[0]);
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
-
- // Test next (page 1)
- $list->NextPage();
- $this->assertTrue($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(3, $list[0]->getID());
- $this->assertEquals(4, $list[1]->getID());
-
- // Test next (page 2 -last)
- $list->NextPage();
- $this->assertTrue($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(1, $list->getCount());
- $this->assertEquals(5, $list[0]->getID());
-
- // Test previous (page 1)
- $list->PreviousPage();
- $this->assertTrue($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(3, $list[0]->getID());
- $this->assertEquals(4, $list[1]->getID());
-
- // Test previous (page 0 -first)
- $list->PreviousPage();
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertAccount1($list[0]);
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
-
- // Test goto (page 0)
- $list->GotoPage(0);
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
-
- // Test goto (page 1)
- $list->GotoPage(1);
- $this->assertTrue($list->getIsPreviousPageAvailable());
- $this->assertTrue($list->getIsNextPageAvailable());
- $this->assertEquals(2, $list->getCount());
- $this->assertEquals(3, $list[0]->getID());
- $this->assertEquals(4, $list[1]->getID());
-
- // Test goto (page 2)
- $list->GotoPage(2);
- $this->assertTrue($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(1, $list->getCount());
- $this->assertEquals(5, $list[0]->getID());
-
- // Test illegal goto (page 0)
- $list->GotoPage(3);
- $this->assertTrue($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(0, $list->getCount());
-
- $list = $this->sqlmap->QueryForPagedList("GetNoAccountsViaResultMap", null, 2);
-
- // Test empty list
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(0, $list->getCount());
-
- // Test next
- $list->NextPage();
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(0, $list->getCount());
-
- // Test previous
- $list->PreviousPage();
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(0, $list->getCount());
-
- // Test previous
- $list->GotoPage(0);
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(0, $list->getCount());
- $list = $this->sqlmap->QueryForPagedList("GetFewAccountsViaResultMap", null, 2);
-
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(1, $list->getCount());
-
- // Test next
- $list->NextPage();
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(1, $list->getCount());
- // Test previous
- $list->PreviousPage();
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(1, $list->getCount());
-
- // Test previous
- $list->GotoPage(0);
- $this->assertFalse($list->getIsPreviousPageAvailable());
- $this->assertFalse($list->getIsNextPageAvailable());
- $this->assertEquals(1, $list->getCount());
-
-
- $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 5);
-
- $this->assertEquals(5, $list->getCount());
-
- $list->NextPage();
- $this->assertEquals(5, $list->getCount());
-
- $b = $list->getIsPreviousPageAvailable();
- $list->PreviousPage();
- $this->assertEquals(5, $list->getCount());
- }
-
- /**
- * Test QueryForList with ResultObject :
- * AccountCollection strongly typed collection
- */
- function testQueryForListWithResultObject()
- {
- $accounts = new AccountCollection();
-
- $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, $accounts);
- $this->assertAccount1($accounts[0]);
- $this->assertEquals(5, $accounts->getCount());
- $this->assertEquals(1, $accounts[0]->getID());
- $this->assertEquals(2, $accounts[1]->getID());
- $this->assertEquals(3, $accounts[2]->getID());
- $this->assertEquals(4, $accounts[3]->getID());
- $this->assertEquals(5, $accounts[4]->GetId());
- }
-
- /**
- * Test QueryForList with ListClass : LineItemCollection
- */
- function testQueryForListWithListClass()
- {
- $linesItem = $this->sqlmap->QueryForList("GetLineItemsForOrderWithListClass", 10);
-
- $this->assertNotNull($linesItem);
- $this->assertEquals(2, $linesItem->getCount());
- $this->assertEquals("ESM-34", $linesItem[0]->getCode());
- $this->assertEquals("QSM-98", $linesItem[1]->getCode());
- }
-
- /**
- * Test QueryForList with no result.
- */
- function testQueryForListWithNoResult()
- {
- $list = $this->sqlmap->QueryForList("GetNoAccountsViaResultMap");
-
- $this->assertEquals(0, count($list));
- }
-
- /**
- * Test QueryForList with ResultClass : Account.
- */
- function testQueryForListResultClass()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultClass");
-
- $this->assertAccount1($list[0]);
- $this->assertEquals(5, count($list));
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
- $this->assertEquals(3, $list[2]->getID());
- $this->assertEquals(4, $list[3]->getID());
- $this->assertEquals(5, $list[4]->getID());
- }
-
- /**
- * Test QueryForList with simple resultClass : string
- */
- function testQueryForListWithSimpleResultClass()
- {
- $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultClass");
-
- $this->assertEquals("Joe.Dalton@somewhere.com", $list[0]);
- $this->assertEquals("Averel.Dalton@somewhere.com", $list[1]);
- $this->assertEquals('', $list[2]);
- $this->assertEquals("Jack.Dalton@somewhere.com", $list[3]);
- $this->assertEquals('', $list[4]);
- }
-
- /**
- * Test QueryForList with simple ResultMap : string
- */
- function testQueryForListWithSimpleResultMap()
- {
- $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultMap");
-
- $this->assertEquals("Joe.Dalton@somewhere.com", $list[0]);
- $this->assertEquals("Averel.Dalton@somewhere.com", $list[1]);
- $this->assertEquals('', $list[2]);
- $this->assertEquals("Jack.Dalton@somewhere.com", $list[3]);
- $this->assertEquals('', $list[4]);
- }
-
- /**
- * Test QueryForListWithSkipAndMax
- */
- function testQueryForListWithSkipAndMax()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, null, 2, 2);
-
- $this->assertEquals(2, count($list));
- $this->assertEquals(3, $list[0]->getID());
- $this->assertEquals(4, $list[1]->getID());
- }
-
-
- /**
- * Test row delegate
- */
- function testQueryWithRowDelegate()
- {
- //$handler = new SqlMapper.RowDelegate(this.RowHandler);
-
- //$list = $this->sqlmap->QueryWithRowDelegate("GetAllAccountsViaResultMap", null, handler);
-
- //$this->assertEquals(5, _index);
- //$this->assertEquals(5, $list->getCount());
- //$this->assertAccount1$list[0]);
- //$this->assertEquals(1, $list[0]->getID());
- //$this->assertEquals(2, $list[1]->getID());
- //$this->assertEquals(3, $list[2]->getID());
- //$this->assertEquals(4, $list[3]->getID());
- //$this->assertEquals(5, $list[4]->getID());
- }
-
- #endregion
-
- #region Map Tests
-
- /**
- * Test ExecuteQueryForMap : Hashtable.
- */
- function testExecuteQueryForMap()
- {
- $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName");
-
- $this->assertEquals(5, count($map));
- $this->assertAccount1($map["Joe"]);
-
- $this->assertEquals(1, $map["Joe"]->getID());
- $this->assertEquals(2, $map["Averel"]->getID());
- $this->assertEquals(3, $map["William"]->getID());
- $this->assertEquals(4, $map["Jack"]->getID());
- $this->assertEquals(5, $map["Gilles"]->getID());
- }
-
- /**
- * Test ExecuteQueryForMap : Hashtable.
- *
- * If the keyProperty is an integer, you must acces the map
- * by map[integer] and not by map["integer"]
- */
- function testExecuteQueryForMap2()
- {
- $map = $this->sqlmap->QueryForMap("GetAllOrderWithLineItems", null, "PostalCode");
-
- $this->assertEquals(11, count($map));
- $order = $map["T4H 9G4"];
-
- $this->assertEquals(2, $order->getLineItemsList()->getCount());
- }
-
- /**
- * Test ExecuteQueryForMap with value property :
- * "FirstName" as key, "EmailAddress" as value
- */
- function testExecuteQueryForMapWithValueProperty()
- {
- $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null,
- "FirstName", "EmailAddress");
-
- $this->assertEquals(5, count($map));
-
- $this->assertEquals("Joe.Dalton@somewhere.com", $map["Joe"]);
- $this->assertEquals("Averel.Dalton@somewhere.com", $map["Averel"]);
- $this->assertNull($map["William"]);
- $this->assertEquals("Jack.Dalton@somewhere.com", $map["Jack"]);
- $this->assertNull($map["Gilles"]);
- }
-
- /**
- * Test ExecuteQueryForWithJoined
- */
- function testExecuteQueryForWithJoined()
- {
- $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",10);
-
- $this->assertNotNull($order->getAccount());
-
- $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",11);
-
- $this->assertNull($order->getAccount());
- }
-
- /**
- * Test ExecuteQueryFor With Complex Joined
- *
- * A->B->C
- * ->E
- * ->F
- */
- function testExecuteQueryForWithComplexJoined()
- {
- $a = $this->sqlmap->QueryForObject("SelectComplexJoined",null);
- $this->assertNotNull($a);
- $this->assertNotNull($a->getB());
- $this->assertNotNull($a->getB()->getC());
- $this->assertNull($a->getB()->getD());
- $this->assertNotNull($a->getE());
- $this->assertNull($a->getF());
- }
- #endregion
-
- #region Extends statement
-
- /**
- * Test base Extends statement
- */
- function testExtendsGetAllAccounts()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccounts");
-
- $this->assertAccount1($list[0]);
- $this->assertEquals(5, count($list));
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
- $this->assertEquals(3, $list[2]->getID());
- $this->assertEquals(4, $list[3]->getID());
- $this->assertEquals(5, $list[4]->getID());
- }
-
- /**
- * Test Extends statement GetAllAccountsOrderByName extends GetAllAccounts
- */
- function testExtendsGetAllAccountsOrderByName()
- {
- $list = $this->sqlmap->QueryForList("GetAllAccountsOrderByName");
-
- $this->assertAccount1($list[3]);
- $this->assertEquals(5, count($list));
-
- $this->assertEquals(2, $list[0]->getID());
- $this->assertEquals(5, $list[1]->getID());
- $this->assertEquals(4, $list[2]->getID());
- $this->assertEquals(1, $list[3]->getID());
- $this->assertEquals(3, $list[4]->getID());
- }
-
- /**
- * Test Extends statement GetOneAccount extends GetAllAccounts
- */
- function testExtendsGetOneAccount()
- {
- $account= $this->sqlmap->QueryForObject("GetOneAccount", 1);
- $this->assertAccount1($account);
- }
-
- /**
- * Test Extends statement GetSomeAccount extends GetAllAccounts
- */
- function testExtendsGetSomeAccount()
- {
- $param["lowID"] = 2;
- $param["hightID"] = 4;
-
- $list = $this->sqlmap->QueryForList("GetSomeAccount", $param);
-
- $this->assertEquals(3, count($list));
-
- $this->assertEquals(2, $list[0]->getID());
- $this->assertEquals(3, $list[1]->getID());
- $this->assertEquals(4, $list[2]->getID());
- }
-
- #endregion
-
- #region Update tests
-
-
- /**
- * Test Insert account via public fields
- */
- function testInsertAccountViaPublicFields()
- {
- $this->initScript('account-init.sql');
-
- $account = new AccountBis();
-
- $account->Id = 10;
- $account->FirstName = "Luky";
- $account->LastName = "Luke";
- $account->EmailAddress = "luly.luke@somewhere.com";
-
- $this->sqlmap->Insert("InsertAccountViaPublicFields", $account);
-
- $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 10);
-
- $this->assertNotNull($testAccount);
-
- $this->assertEquals(10, $testAccount->getID());
-
- $this->initScript('account-init.sql');
- }
-
- /**
- *
- */
- function testInsertOrderViaProperties()
- {
- $this->initScript('account-init.sql');
- $this->initScript('order-init.sql');
- $account= $this->NewAccount6();
-
- $this->sqlmap->Insert("InsertAccountViaParameterMap", $account);
-
- $order = new Order();
- $order->setId(99);
- $order->setCardExpiry("09/11");
- $order->setAccount($account);
- $order->setCardNumber("154564656");
- $order->setCardType("Visa");
- $order->setCity("Lyon");
- $order->setDate('2005-05-20');
- $order->setPostalCode("69004");
- $order->setProvince("Rhone");
- $order->setStreet("rue Durand");
-
- $this->sqlmap->Insert("InsertOrderViaPublicFields", $order);
-
- $this->initScript('account-init.sql');
- $this->initScript('order-init.sql');
- }
-
-
- /**
- * Test Insert account via inline parameters
- */
- function testInsertAccountViaInlineParameters()
- {
- $this->initScript('account-init.sql');
- $account= new Account();
-
- $account->setId(10);
- $account->setFirstName("Luky");
- $account->setLastName("Luke");
- $account->setEmailAddress("luly.luke@somewhere.com");
-
- $this->sqlmap->Insert("InsertAccountViaInlineParameters", $account);
-
- $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 10);
-
- $this->assertNotNull($testAccount);
- $this->assertEquals(10, $testAccount->getId());
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Insert account via parameterMap
- */
- function testInsertAccountViaParameterMap()
- {
- $this->initScript('account-init.sql');
- $account= $this->NewAccount6();
- $this->sqlmap->Insert("InsertAccountViaParameterMap", $account);
-
- $account = $this->sqlmap->QueryForObject("GetAccountNullableEmail", 6);
- $this->AssertAccount6($account);
-
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Update via parameterMap
- */
- function testUpdateViaParameterMap()
- {
- $this->initScript('account-init.sql');
- $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
-
- $account->setEmailAddress("new@somewhere.com");
- $this->sqlmap->Update("UpdateAccountViaParameterMap", $account);
-
- $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
-
- $this->assertEquals("new@somewhere.com", $account->getEmailAddress());
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Update via parameterMap V2
- */
- function testUpdateViaParameterMap2()
- {
- $this->initScript('account-init.sql');
- $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
-
- $account->setEmailAddress("new@somewhere.com");
- $this->sqlmap->Update("UpdateAccountViaParameterMap2", $account);
-
- $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
-
- $this->assertEquals("new@somewhere.com", $account->getEmailAddress());
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Update with inline parameters
- */
- function testUpdateWithInlineParameters()
- {
- $this->initScript('account-init.sql');
- $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
-
- $account->setEmailAddress("new@somewhere.com");
- $this->sqlmap->Update("UpdateAccountViaInlineParameters", $account);
-
- $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1);
-
- $this->assertEquals("new@somewhere.com", $account->getEmailAddress());
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Execute Update With Parameter Class
- */
- function testExecuteUpdateWithParameterClass()
- {
- $this->initScript('account-init.sql');
- $account= $this->NewAccount6();
-
- $this->sqlmap->Insert("InsertAccountViaParameterMap", $account);
-
- $noRowsDeleted = $this->sqlmap->Update("DeleteAccount", null);
-
- $this->sqlmap->Update("DeleteAccount", $account);
-
- $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6);
-
- $this->assertNull($account);
- $this->assertEquals(0, $noRowsDeleted);
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Execute Delete
- */
- function testExecuteDelete()
- {
- $this->initScript('account-init.sql');
- $account= $this->NewAccount6();
-
- $this->sqlmap->Insert("InsertAccountViaParameterMap", $account);
-
- $account = null;
- $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6);
-
- $this->assertTrue($account->getId() == 6);
-
- $rowNumber = $this->sqlmap->Delete("DeleteAccount", $account);
- $this->assertTrue($rowNumber == 1);
-
- $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6);
-
- $this->assertNull($account);
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test Execute Delete
- */
- function testDeleteWithComments()
- {
- $this->initScript('line-item-init.sql');
- $rowNumber = $this->sqlmap->Delete("DeleteWithComments");
-
- $this->assertEquals($rowNumber, 2);
- $this->initScript('line-item-init.sql');
- }
-
-
-
- #endregion
-
- #region Row delegate
-
- private $_index = 0;
-
- function RowHandler($sender, $paramterObject, $list)
- {
- //_index++;
- //$this->assertEquals(_index, (($account) obj).Id);
- //$list->Add(obj);
- }
-
- #endregion
-
- #region JIRA Tests
-
- /**
- * Test JIRA 30 (repeating property)
- */
- function testJIRA30()
- {
- $account= new Account();
- $account->setId(1);
- $account->setFirstName("Joe");
- $account->setLastName("Dalton");
- $account->setEmailAddress("Joe.Dalton@somewhere.com");
-
- $result = $this->sqlmap->QueryForObject("GetAccountWithRepeatingProperty", $account);
-
- $this->assertAccount1($result);
- }
-
- /**
- * Test Bit column
- */
- function testJIRA42()
- {
- $other = new Other();
-
- $other->setInt(100);
- $other->setBool(true);
- $other->setLong(789456321);
-
- $this->sqlmap->Insert("InsertBool", $other);
- }
-
- /**
- * Test for access a result map in a different namespace
- */
- function testJIRA45()
- {
- $account= $this->sqlmap->QueryForObject("GetAccountJIRA45", 1);
- $this->assertAccount1($account);
- }
-
- /**
- * Test : Whitespace is not maintained properly when CDATA tags are used
- */
- function testJIRA110()
- {
- $account= $this->sqlmap->QueryForObject("Get1Account");
- $this->assertAccount1($account);
- }
-
- /**
- * Test : Whitespace is not maintained properly when CDATA tags are used
- */
- function testJIRA110Bis()
- {
- $list = $this->sqlmap->QueryForList("GetAccounts");
-
- $this->assertAccount1($list[0]);
- $this->assertEquals(5, count($list));
- }
-
- /**
- * Test for cache stats only being calculated on CachingStatments
- */
- function testJIRA113()
- {
- // $this->sqlmap->FlushCaches();
-
- // taken from TestFlushDataCache()
- // first query is not cached, second query is: 50% cache hit
- /*$list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap");
- $firstId = HashCodeProvider.GetIdentityHashCode(list);
- list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap");
- int secondId = HashCodeProvider.GetIdentityHashCode(list);
- $this->assertEquals(firstId, secondId);
-
- string cacheStats = $this->sqlmap->GetDataCacheStats();
-
- $this->assertNotNull(cacheStats);*/
- }
-
- #endregion
-
- #region CustomTypeHandler tests
-
- /**
- * Test CustomTypeHandler
- */
- function testExecuteQueryWithCustomTypeHandler()
- {
- $this->sqlmap->getTypeHandlerFactory()->register('HundredsBool', new HundredsBool());
- $this->sqlmap->getTypeHandlerFactory()->register('OuiNonBool', new OuiNonBool());
-
- $list = $this->sqlmap->QueryForList("GetAllAccountsViaCustomTypeHandler");
-
- $this->assertAccount1($list[0]);
- $this->assertEquals(5, count($list));
- $this->assertEquals(1, $list[0]->getID());
- $this->assertEquals(2, $list[1]->getID());
- $this->assertEquals(3, $list[2]->getID());
- $this->assertEquals(4, $list[3]->getID());
- $this->assertEquals(5, $list[4]->getID());
-
- $this->assertFalse($list[0]->getCartOptions());
- $this->assertFalse($list[1]->getCartOptions());
- $this->assertTrue($list[2]->getCartOptions());
- $this->assertTrue($list[3]->getCartOptions());
- $this->assertTrue($list[4]->getCartOptions());
-
- $this->assertTrue($list[0]->getBannerOptions());
- $this->assertTrue($list[1]->getBannerOptions());
- $this->assertFalse($list[2]->getBannerOptions());
- $this->assertFalse($list[3]->getBannerOptions());
- $this->assertTrue($list[4]->getBannerOptions());
- }
-
- /**
- * Test CustomTypeHandler Oui/Non
- */
- function testCustomTypeHandler()
- {
- $this->initScript('other-init.sql');
- $this->initScript('account-init.sql');
-
- $this->sqlmap->getTypeHandlerFactory()->register('OuiNonBool', new OuiNonBool());
-
- $other = new Other();
- $other->setInt(99);
- $other->setLong(1966);
- $other->setBool(true);
- $other->setBool2(false);
- $this->sqlmap->Insert("InsertCustomTypeHandler", $other);
-
- $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99);
- $this->assertNotNull( $anOther );
- $this->assertEquals(99, (int)$anOther->getInt());
- $this->assertEquals(1966, (int)$anOther->getLong());
- $this->assertEquals(true, (boolean)$anOther->getBool());
- $this->assertEquals(false, (boolean)$anOther->getBool2());
-
- }
-
- /**
- * Test CustomTypeHandler Oui/Non
- */
- function testInsertInlineCustomTypeHandlerV1()
- {
- $this->initScript('other-init.sql');
- $this->initScript('account-init.sql');
-
- $other = new Other();
- $other->setInt(99);
- $other->setLong(1966);
- $other->setBool(true);
- $other->setBool2(false);
-
- $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV1", $other);
-
- $anOther = $this->sqlmap->QueryForObject("SelectByIntV1", 99);
-
- $this->assertNotNull( $anOther );
- $this->assertEquals(99, (int)$anOther->getInt());
- $this->assertEquals(1966, (int)$anOther->getLong());
- $this->assertEquals(true, (boolean)$anOther->getBool());
- $this->assertEquals(false, (boolean)$anOther->getBool2());
-
- }
-
- /**
- * Test CustomTypeHandler Oui/Non
- */
- function testInsertInlineCustomTypeHandlerV2()
- {
- $this->initScript('other-init.sql');
- $this->initScript('account-init.sql');
-
- $other = new Other();
- $other->setInt(99);
- $other->setLong(1966);
- $other->setBool(true);
- $other->setBool2(false);
-
- $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV2", $other);
-
- $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99);
-
- $this->assertNotNull( $anOther );
- $this->assertEquals(99, (int)$anOther->getInt());
- $this->assertEquals(1966, (int)$anOther->getLong());
- $this->assertEquals(true, (boolean)$anOther->getBool());
- $this->assertEquals(false, (boolean)$anOther->getBool2());
- }
- #endregion
- /**/
-}
-
+<?php +require_once(dirname(__FILE__).'/BaseTest.php'); + +/** + * @package System.DataAccess.SQLMap + */ +class StatementTest extends BaseTest +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + + //force autoload + new Account; + new Order; + new LineItem; + new LineItemCollection; + new A; new B; new C; new D; new E; new F; + } + + public function setup() + { + + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + $this->initScript('line-item-init.sql'); +// $this->initScript('enumeration-init.sql'); + $this->initScript('other-init.sql'); + } + + + #region Object Query tests + + /** + * Test Open connection with a connection string + */ + function testOpenConnection() + { + $this->sqlmap->OpenConnection($this->sqlmap->getDataProvider()->getConnectionString()); + $account= $this->sqlmap->QueryForObject("SelectWithProperty"); + $this->sqlmap->CloseConnection(); + $this->assertAccount1($account); + } + + /** + * Test use a statement with property subtitution + * (JIRA 22) + */ + function testSelectWithProperty() + { + $account= $this->sqlmap->QueryForObject("SelectWithProperty"); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject Via ColumnName + */ + function testExecuteQueryForObjectViaColumnName() + { + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject Via ColumnIndex + */ + function testExecuteQueryForObjectViaColumnIndex() + { + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 1); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject Via ResultClass + */ + function testExecuteQueryForObjectViaResultClass() + { + $account= $this->sqlmap->QueryForObject("GetAccountViaResultClass", 1); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject With simple ResultClass : string + */ + function testExecuteQueryForObjectWithSimpleResultClass() + { + $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultClass", 1); + $this->assertEquals("Joe.Dalton@somewhere.com", $email); + } + + /** + * Test ExecuteQueryForObject With simple ResultMap : string + */ + function testExecuteQueryForObjectWithSimpleResultMap() + { + $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultMap", 1); + $this->assertEquals("Joe.Dalton@somewhere.com", $email); + } + + /** + * Test Primitive ReturnValue : TDateTime + */ + function testPrimitiveReturnValue() + { + $CardExpiry = $this->sqlmap->QueryForObject("GetOrderCardExpiryViaResultClass", 1); + $date = @mktime(8, 15, 00, 2, 15, 2003); + $this->assertEquals($date, $CardExpiry->getTimeStamp()); + } + + /** + * Test ExecuteQueryForObject with result object : Account + */ + function testExecuteQueryForObjectWithResultObject() + { + $account= new Account(); + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1, $account); + $this->assertAccount1($account); + $this->assertTrue($account == $testAccount); + } + + /** + * Test ExecuteQueryForObject as array + */ + function testExecuteQueryForObjectAsHashArray() + { + $account = $this->sqlmap->QueryForObject("GetAccountAsHashtable", 1); + $this->assertAccount1AsHashArray($account); + } + + /** + * Test ExecuteQueryForObject as Hashtable ResultClass + */ + function testExecuteQueryForObjectAsHashtableResultClass() + { + $account = $this->sqlmap->QueryForObject("GetAccountAsHashtableResultClass", 1); + $this->assertAccount1AsHashArray($account); + } + + /** + * Test ExecuteQueryForObject via Hashtable + */ + function testExecuteQueryForObjectViaHashtable() + { + $param["LineItem_ID"] = 2; + $param["Order_ID"] = 9; + + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertEquals("TSM-12", $testItem->getCode()); + } + /**/ + + //TODO: Test Query Dynamic Sql Element + function testQueryDynamicSqlElement() + { + //$list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID"); + + //$this->assertEquals("Joe.Dalton@somewhere.com", $list[0]); + + //list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName"); + + //$this->assertEquals("Averel.Dalton@somewhere.com", $list[0]); + + } + + // TODO: Test Execute QueryForList With ResultMap With Dynamic Element + function testExecuteQueryForListWithResultMapWithDynamicElement() + { + //$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE"); + + //$this->assertAccount1$list[0]); + //$this->assertEquals(3, $list->getCount()); + //$this->assertEquals(1, $list[0]->getID()); + //$this->assertEquals(2, $list[1]->getID()); + //$this->assertEquals(4, $list[2]->getID()); + + //list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "="); + + //$this->assertEquals(0, $list->getCount()); + } + + + + /** + * Test Get Account Via Inline Parameters + */ + function testExecuteQueryForObjectViaInlineParameters() + { + $account= new Account(); + $account->setID(1); + + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaInlineParameters", $account); + + $this->assertAccount1($testAccount); + } + /**/ + + // TODO: Test ExecuteQuery For Object With Enum property + + function testExecuteQueryForObjectWithEnum() + { + //$enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 1); + + //$this->assertEquals(enumClass.Day, Days.Sat); + //$this->assertEquals(enumClass.Color, Colors.Red); + //$this->assertEquals(enumClass.Month, Months.August); + + //enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 3) as Enumeration; + + //$this->assertEquals(enumClass.Day, Days.Mon); + //$this->assertEquals(enumClass.Color, Colors.Blue); + //$this->assertEquals(enumClass.Month, Months.September);*/ + } + + #endregion + + #region List Query tests + + /** + * Test QueryForList with Hashtable ResultMap + */ + function testQueryForListWithHashtableResultMap() + { + $this->initScript('account-init.sql'); + $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashMapViaResultMap"); + + $this->assertAccount1AsHashArray($list[0]); + $this->assertEquals(5, count($list)); + + $this->assertEquals(1, (int)$list[0]["Id"]); + $this->assertEquals(2, (int)$list[1]["Id"]); + $this->assertEquals(3, (int)$list[2]["Id"]); + $this->assertEquals(4, (int)$list[3]["Id"]); + $this->assertEquals(5, (int)$list[4]["Id"]); + } + + /** + * Test QueryForList with Hashtable ResultClass + */ + function testQueryForListWithHashtableResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashtableViaResultClass"); + + $this->assertAccount1AsHashArray($list[0]); + $this->assertEquals(5, count($list)); + + $this->assertEquals(1, (int)$list[0]["Id"]); + $this->assertEquals(2, (int)$list[1]["Id"]); + $this->assertEquals(3, (int)$list[2]["Id"]); + $this->assertEquals(4, (int)$list[3]["Id"]); + $this->assertEquals(5, (int)$list[4]["Id"]); + } + + /** + * Test QueryForList with IList ResultClass + */ + function testQueryForListWithIListResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsAsArrayListViaResultClass"); + + $listAccount = $list[0]; + + $this->assertEquals(1,(int)$listAccount[0]); + $this->assertEquals("Joe",$listAccount[1]); + $this->assertEquals("Dalton",$listAccount[2]); + $this->assertEquals("Joe.Dalton@somewhere.com",$listAccount[3]); + + $this->assertEquals(5, count($list)); + + $listAccount = $list[0]; + $this->assertEquals(1, (int)$listAccount[0]); + $listAccount = $list[1]; + $this->assertEquals(2, (int)$listAccount[0]); + $listAccount = $list[2]; + $this->assertEquals(3, (int)$listAccount[0]); + $listAccount = $list[3]; + $this->assertEquals(4, (int)$listAccount[0]); + $listAccount = $list[4]; + $this->assertEquals(5, (int)$listAccount[0]); + } + + /** + * Test QueryForList With ResultMap, result collection as ArrayList + */ + function testQueryForListWithResultMap() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap"); + + $this->assertAccount1($list[0]); + $this->assertEquals(5, count($list)); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + $this->assertEquals(3, $list[2]->getID()); + $this->assertEquals(4, $list[3]->getID()); + $this->assertEquals(5, $list[4]->getID()); + } + + /** + * Test ExecuteQueryForPaginatedList + */ + function testExecuteQueryForPaginatedList() + { + // Get List of all 5 + $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 2); + + // Test initial state (page 0) + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertAccount1($list[0]); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + + // Test illegal previous page (no effect, state should be same) + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertAccount1($list[0]); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + + // Test next (page 1) + $list->NextPage(); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(3, $list[0]->getID()); + $this->assertEquals(4, $list[1]->getID()); + + // Test next (page 2 -last) + $list->NextPage(); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(1, $list->getCount()); + $this->assertEquals(5, $list[0]->getID()); + + // Test previous (page 1) + $list->PreviousPage(); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(3, $list[0]->getID()); + $this->assertEquals(4, $list[1]->getID()); + + // Test previous (page 0 -first) + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertAccount1($list[0]); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + + // Test goto (page 0) + $list->GotoPage(0); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + + // Test goto (page 1) + $list->GotoPage(1); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertEquals(2, $list->getCount()); + $this->assertEquals(3, $list[0]->getID()); + $this->assertEquals(4, $list[1]->getID()); + + // Test goto (page 2) + $list->GotoPage(2); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(1, $list->getCount()); + $this->assertEquals(5, $list[0]->getID()); + + // Test illegal goto (page 0) + $list->GotoPage(3); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(0, $list->getCount()); + + $list = $this->sqlmap->QueryForPagedList("GetNoAccountsViaResultMap", null, 2); + + // Test empty list + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(0, $list->getCount()); + + // Test next + $list->NextPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(0, $list->getCount()); + + // Test previous + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(0, $list->getCount()); + + // Test previous + $list->GotoPage(0); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(0, $list->getCount()); + $list = $this->sqlmap->QueryForPagedList("GetFewAccountsViaResultMap", null, 2); + + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(1, $list->getCount()); + + // Test next + $list->NextPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(1, $list->getCount()); + // Test previous + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(1, $list->getCount()); + + // Test previous + $list->GotoPage(0); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertEquals(1, $list->getCount()); + + + $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 5); + + $this->assertEquals(5, $list->getCount()); + + $list->NextPage(); + $this->assertEquals(5, $list->getCount()); + + $b = $list->getIsPreviousPageAvailable(); + $list->PreviousPage(); + $this->assertEquals(5, $list->getCount()); + } + + /** + * Test QueryForList with ResultObject : + * AccountCollection strongly typed collection + */ + function testQueryForListWithResultObject() + { + $accounts = new AccountCollection(); + + $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, $accounts); + $this->assertAccount1($accounts[0]); + $this->assertEquals(5, $accounts->getCount()); + $this->assertEquals(1, $accounts[0]->getID()); + $this->assertEquals(2, $accounts[1]->getID()); + $this->assertEquals(3, $accounts[2]->getID()); + $this->assertEquals(4, $accounts[3]->getID()); + $this->assertEquals(5, $accounts[4]->GetId()); + } + + /** + * Test QueryForList with ListClass : LineItemCollection + */ + function testQueryForListWithListClass() + { + $linesItem = $this->sqlmap->QueryForList("GetLineItemsForOrderWithListClass", 10); + + $this->assertNotNull($linesItem); + $this->assertEquals(2, $linesItem->getCount()); + $this->assertEquals("ESM-34", $linesItem[0]->getCode()); + $this->assertEquals("QSM-98", $linesItem[1]->getCode()); + } + + /** + * Test QueryForList with no result. + */ + function testQueryForListWithNoResult() + { + $list = $this->sqlmap->QueryForList("GetNoAccountsViaResultMap"); + + $this->assertEquals(0, count($list)); + } + + /** + * Test QueryForList with ResultClass : Account. + */ + function testQueryForListResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultClass"); + + $this->assertAccount1($list[0]); + $this->assertEquals(5, count($list)); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + $this->assertEquals(3, $list[2]->getID()); + $this->assertEquals(4, $list[3]->getID()); + $this->assertEquals(5, $list[4]->getID()); + } + + /** + * Test QueryForList with simple resultClass : string + */ + function testQueryForListWithSimpleResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultClass"); + + $this->assertEquals("Joe.Dalton@somewhere.com", $list[0]); + $this->assertEquals("Averel.Dalton@somewhere.com", $list[1]); + $this->assertEquals('', $list[2]); + $this->assertEquals("Jack.Dalton@somewhere.com", $list[3]); + $this->assertEquals('', $list[4]); + } + + /** + * Test QueryForList with simple ResultMap : string + */ + function testQueryForListWithSimpleResultMap() + { + $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultMap"); + + $this->assertEquals("Joe.Dalton@somewhere.com", $list[0]); + $this->assertEquals("Averel.Dalton@somewhere.com", $list[1]); + $this->assertEquals('', $list[2]); + $this->assertEquals("Jack.Dalton@somewhere.com", $list[3]); + $this->assertEquals('', $list[4]); + } + + /** + * Test QueryForListWithSkipAndMax + */ + function testQueryForListWithSkipAndMax() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, null, 2, 2); + + $this->assertEquals(2, count($list)); + $this->assertEquals(3, $list[0]->getID()); + $this->assertEquals(4, $list[1]->getID()); + } + + + /** + * Test row delegate + */ + function testQueryWithRowDelegate() + { + //$handler = new SqlMapper.RowDelegate(this.RowHandler); + + //$list = $this->sqlmap->QueryWithRowDelegate("GetAllAccountsViaResultMap", null, handler); + + //$this->assertEquals(5, _index); + //$this->assertEquals(5, $list->getCount()); + //$this->assertAccount1$list[0]); + //$this->assertEquals(1, $list[0]->getID()); + //$this->assertEquals(2, $list[1]->getID()); + //$this->assertEquals(3, $list[2]->getID()); + //$this->assertEquals(4, $list[3]->getID()); + //$this->assertEquals(5, $list[4]->getID()); + } + + #endregion + + #region Map Tests + + /** + * Test ExecuteQueryForMap : Hashtable. + */ + function testExecuteQueryForMap() + { + $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName"); + + $this->assertEquals(5, count($map)); + $this->assertAccount1($map["Joe"]); + + $this->assertEquals(1, $map["Joe"]->getID()); + $this->assertEquals(2, $map["Averel"]->getID()); + $this->assertEquals(3, $map["William"]->getID()); + $this->assertEquals(4, $map["Jack"]->getID()); + $this->assertEquals(5, $map["Gilles"]->getID()); + } + + /** + * Test ExecuteQueryForMap : Hashtable. + * + * If the keyProperty is an integer, you must acces the map + * by map[integer] and not by map["integer"] + */ + function testExecuteQueryForMap2() + { + $map = $this->sqlmap->QueryForMap("GetAllOrderWithLineItems", null, "PostalCode"); + + $this->assertEquals(11, count($map)); + $order = $map["T4H 9G4"]; + + $this->assertEquals(2, $order->getLineItemsList()->getCount()); + } + + /** + * Test ExecuteQueryForMap with value property : + * "FirstName" as key, "EmailAddress" as value + */ + function testExecuteQueryForMapWithValueProperty() + { + $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, + "FirstName", "EmailAddress"); + + $this->assertEquals(5, count($map)); + + $this->assertEquals("Joe.Dalton@somewhere.com", $map["Joe"]); + $this->assertEquals("Averel.Dalton@somewhere.com", $map["Averel"]); + $this->assertNull($map["William"]); + $this->assertEquals("Jack.Dalton@somewhere.com", $map["Jack"]); + $this->assertNull($map["Gilles"]); + } + + /** + * Test ExecuteQueryForWithJoined + */ + function testExecuteQueryForWithJoined() + { + $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",10); + + $this->assertNotNull($order->getAccount()); + + $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",11); + + $this->assertNull($order->getAccount()); + } + + /** + * Test ExecuteQueryFor With Complex Joined + * + * A->B->C + * ->E + * ->F + */ + function testExecuteQueryForWithComplexJoined() + { + $a = $this->sqlmap->QueryForObject("SelectComplexJoined",null); + $this->assertNotNull($a); + $this->assertNotNull($a->getB()); + $this->assertNotNull($a->getB()->getC()); + $this->assertNull($a->getB()->getD()); + $this->assertNotNull($a->getE()); + $this->assertNull($a->getF()); + } + #endregion + + #region Extends statement + + /** + * Test base Extends statement + */ + function testExtendsGetAllAccounts() + { + $list = $this->sqlmap->QueryForList("GetAllAccounts"); + + $this->assertAccount1($list[0]); + $this->assertEquals(5, count($list)); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + $this->assertEquals(3, $list[2]->getID()); + $this->assertEquals(4, $list[3]->getID()); + $this->assertEquals(5, $list[4]->getID()); + } + + /** + * Test Extends statement GetAllAccountsOrderByName extends GetAllAccounts + */ + function testExtendsGetAllAccountsOrderByName() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsOrderByName"); + + $this->assertAccount1($list[3]); + $this->assertEquals(5, count($list)); + + $this->assertEquals(2, $list[0]->getID()); + $this->assertEquals(5, $list[1]->getID()); + $this->assertEquals(4, $list[2]->getID()); + $this->assertEquals(1, $list[3]->getID()); + $this->assertEquals(3, $list[4]->getID()); + } + + /** + * Test Extends statement GetOneAccount extends GetAllAccounts + */ + function testExtendsGetOneAccount() + { + $account= $this->sqlmap->QueryForObject("GetOneAccount", 1); + $this->assertAccount1($account); + } + + /** + * Test Extends statement GetSomeAccount extends GetAllAccounts + */ + function testExtendsGetSomeAccount() + { + $param["lowID"] = 2; + $param["hightID"] = 4; + + $list = $this->sqlmap->QueryForList("GetSomeAccount", $param); + + $this->assertEquals(3, count($list)); + + $this->assertEquals(2, $list[0]->getID()); + $this->assertEquals(3, $list[1]->getID()); + $this->assertEquals(4, $list[2]->getID()); + } + + #endregion + + #region Update tests + + + /** + * Test Insert account via public fields + */ + function testInsertAccountViaPublicFields() + { + $this->initScript('account-init.sql'); + + $account = new AccountBis(); + + $account->Id = 10; + $account->FirstName = "Luky"; + $account->LastName = "Luke"; + $account->EmailAddress = "luly.luke@somewhere.com"; + + $this->sqlmap->Insert("InsertAccountViaPublicFields", $account); + + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 10); + + $this->assertNotNull($testAccount); + + $this->assertEquals(10, $testAccount->getID()); + + $this->initScript('account-init.sql'); + } + + /** + * + */ + function testInsertOrderViaProperties() + { + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + $account= $this->NewAccount6(); + + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate('2005-05-20'); + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->Insert("InsertOrderViaPublicFields", $order); + + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + } + + + /** + * Test Insert account via inline parameters + */ + function testInsertAccountViaInlineParameters() + { + $this->initScript('account-init.sql'); + $account= new Account(); + + $account->setId(10); + $account->setFirstName("Luky"); + $account->setLastName("Luke"); + $account->setEmailAddress("luly.luke@somewhere.com"); + + $this->sqlmap->Insert("InsertAccountViaInlineParameters", $account); + + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 10); + + $this->assertNotNull($testAccount); + $this->assertEquals(10, $testAccount->getId()); + $this->initScript('account-init.sql'); + } + + /** + * Test Insert account via parameterMap + */ + function testInsertAccountViaParameterMap() + { + $this->initScript('account-init.sql'); + $account= $this->NewAccount6(); + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountNullableEmail", 6); + $this->AssertAccount6($account); + + $this->initScript('account-init.sql'); + } + + /** + * Test Update via parameterMap + */ + function testUpdateViaParameterMap() + { + $this->initScript('account-init.sql'); + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $account->setEmailAddress("new@somewhere.com"); + $this->sqlmap->Update("UpdateAccountViaParameterMap", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $this->assertEquals("new@somewhere.com", $account->getEmailAddress()); + $this->initScript('account-init.sql'); + } + + /** + * Test Update via parameterMap V2 + */ + function testUpdateViaParameterMap2() + { + $this->initScript('account-init.sql'); + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $account->setEmailAddress("new@somewhere.com"); + $this->sqlmap->Update("UpdateAccountViaParameterMap2", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $this->assertEquals("new@somewhere.com", $account->getEmailAddress()); + $this->initScript('account-init.sql'); + } + + /** + * Test Update with inline parameters + */ + function testUpdateWithInlineParameters() + { + $this->initScript('account-init.sql'); + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $account->setEmailAddress("new@somewhere.com"); + $this->sqlmap->Update("UpdateAccountViaInlineParameters", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $this->assertEquals("new@somewhere.com", $account->getEmailAddress()); + $this->initScript('account-init.sql'); + } + + /** + * Test Execute Update With Parameter Class + */ + function testExecuteUpdateWithParameterClass() + { + $this->initScript('account-init.sql'); + $account= $this->NewAccount6(); + + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $noRowsDeleted = $this->sqlmap->Update("DeleteAccount", null); + + $this->sqlmap->Update("DeleteAccount", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); + + $this->assertNull($account); + $this->assertEquals(0, $noRowsDeleted); + $this->initScript('account-init.sql'); + } + + /** + * Test Execute Delete + */ + function testExecuteDelete() + { + $this->initScript('account-init.sql'); + $account= $this->NewAccount6(); + + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $account = null; + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); + + $this->assertTrue($account->getId() == 6); + + $rowNumber = $this->sqlmap->Delete("DeleteAccount", $account); + $this->assertTrue($rowNumber == 1); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); + + $this->assertNull($account); + $this->initScript('account-init.sql'); + } + + /** + * Test Execute Delete + */ + function testDeleteWithComments() + { + $this->initScript('line-item-init.sql'); + $rowNumber = $this->sqlmap->Delete("DeleteWithComments"); + + $this->assertEquals($rowNumber, 2); + $this->initScript('line-item-init.sql'); + } + + + + #endregion + + #region Row delegate + + private $_index = 0; + + function RowHandler($sender, $paramterObject, $list) + { + //_index++; + //$this->assertEquals(_index, (($account) obj).Id); + //$list->Add(obj); + } + + #endregion + + #region JIRA Tests + + /** + * Test JIRA 30 (repeating property) + */ + function testJIRA30() + { + $account= new Account(); + $account->setId(1); + $account->setFirstName("Joe"); + $account->setLastName("Dalton"); + $account->setEmailAddress("Joe.Dalton@somewhere.com"); + + $result = $this->sqlmap->QueryForObject("GetAccountWithRepeatingProperty", $account); + + $this->assertAccount1($result); + } + + /** + * Test Bit column + */ + function testJIRA42() + { + $other = new Other(); + + $other->setInt(100); + $other->setBool(true); + $other->setLong(789456321); + + $this->sqlmap->Insert("InsertBool", $other); + } + + /** + * Test for access a result map in a different namespace + */ + function testJIRA45() + { + $account= $this->sqlmap->QueryForObject("GetAccountJIRA45", 1); + $this->assertAccount1($account); + } + + /** + * Test : Whitespace is not maintained properly when CDATA tags are used + */ + function testJIRA110() + { + $account= $this->sqlmap->QueryForObject("Get1Account"); + $this->assertAccount1($account); + } + + /** + * Test : Whitespace is not maintained properly when CDATA tags are used + */ + function testJIRA110Bis() + { + $list = $this->sqlmap->QueryForList("GetAccounts"); + + $this->assertAccount1($list[0]); + $this->assertEquals(5, count($list)); + } + + /** + * Test for cache stats only being calculated on CachingStatments + */ + function testJIRA113() + { + // $this->sqlmap->FlushCaches(); + + // taken from TestFlushDataCache() + // first query is not cached, second query is: 50% cache hit + /*$list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); + $firstId = HashCodeProvider.GetIdentityHashCode(list); + list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); + int secondId = HashCodeProvider.GetIdentityHashCode(list); + $this->assertEquals(firstId, secondId); + + string cacheStats = $this->sqlmap->GetDataCacheStats(); + + $this->assertNotNull(cacheStats);*/ + } + + #endregion + + #region CustomTypeHandler tests + + /** + * Test CustomTypeHandler + */ + function testExecuteQueryWithCustomTypeHandler() + { + $this->sqlmap->getTypeHandlerFactory()->register('HundredsBool', new HundredsBool()); + $this->sqlmap->getTypeHandlerFactory()->register('OuiNonBool', new OuiNonBool()); + + $list = $this->sqlmap->QueryForList("GetAllAccountsViaCustomTypeHandler"); + + $this->assertAccount1($list[0]); + $this->assertEquals(5, count($list)); + $this->assertEquals(1, $list[0]->getID()); + $this->assertEquals(2, $list[1]->getID()); + $this->assertEquals(3, $list[2]->getID()); + $this->assertEquals(4, $list[3]->getID()); + $this->assertEquals(5, $list[4]->getID()); + + $this->assertFalse($list[0]->getCartOptions()); + $this->assertFalse($list[1]->getCartOptions()); + $this->assertTrue($list[2]->getCartOptions()); + $this->assertTrue($list[3]->getCartOptions()); + $this->assertTrue($list[4]->getCartOptions()); + + $this->assertTrue($list[0]->getBannerOptions()); + $this->assertTrue($list[1]->getBannerOptions()); + $this->assertFalse($list[2]->getBannerOptions()); + $this->assertFalse($list[3]->getBannerOptions()); + $this->assertTrue($list[4]->getBannerOptions()); + } + + /** + * Test CustomTypeHandler Oui/Non + */ + function testCustomTypeHandler() + { + $this->initScript('other-init.sql'); + $this->initScript('account-init.sql'); + + $this->sqlmap->getTypeHandlerFactory()->register('OuiNonBool', new OuiNonBool()); + + $other = new Other(); + $other->setInt(99); + $other->setLong(1966); + $other->setBool(true); + $other->setBool2(false); + $this->sqlmap->Insert("InsertCustomTypeHandler", $other); + + $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); + $this->assertNotNull( $anOther ); + $this->assertEquals(99, (int)$anOther->getInt()); + $this->assertEquals(1966, (int)$anOther->getLong()); + $this->assertEquals(true, (boolean)$anOther->getBool()); + $this->assertEquals(false, (boolean)$anOther->getBool2()); + + } + + /** + * Test CustomTypeHandler Oui/Non + */ + function testInsertInlineCustomTypeHandlerV1() + { + $this->initScript('other-init.sql'); + $this->initScript('account-init.sql'); + + $other = new Other(); + $other->setInt(99); + $other->setLong(1966); + $other->setBool(true); + $other->setBool2(false); + + $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV1", $other); + + $anOther = $this->sqlmap->QueryForObject("SelectByIntV1", 99); + + $this->assertNotNull( $anOther ); + $this->assertEquals(99, (int)$anOther->getInt()); + $this->assertEquals(1966, (int)$anOther->getLong()); + $this->assertEquals(true, (boolean)$anOther->getBool()); + $this->assertEquals(false, (boolean)$anOther->getBool2()); + + } + + /** + * Test CustomTypeHandler Oui/Non + */ + function testInsertInlineCustomTypeHandlerV2() + { + $this->initScript('other-init.sql'); + $this->initScript('account-init.sql'); + + $other = new Other(); + $other->setInt(99); + $other->setLong(1966); + $other->setBool(true); + $other->setBool2(false); + + $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV2", $other); + + $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); + + $this->assertNotNull( $anOther ); + $this->assertEquals(99, (int)$anOther->getInt()); + $this->assertEquals(1966, (int)$anOther->getLong()); + $this->assertEquals(true, (boolean)$anOther->getBool()); + $this->assertEquals(false, (boolean)$anOther->getBool2()); + } + #endregion + /**/ +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/TAdodbConnectionTestCase.php b/tests/unit/SQLMap/TAdodbConnectionTestCase.php index 1ba0ec04..7d566386 100644 --- a/tests/unit/SQLMap/TAdodbConnectionTestCase.php +++ b/tests/unit/SQLMap/TAdodbConnectionTestCase.php @@ -1,64 +1,64 @@ -<?php
-
-require_once dirname(__FILE__).'/../phpunit2.php';
-
-require_once(dirname(__FILE__).'/common.php');
-
-/**
- * @package System.DataAccess
- */
-class TAdodbConnectionTestCase extends PHPUnit2_Framework_TestCase
-{
- protected $db_file;
-
- function setup()
- {
- $file = dirname(__FILE__).'/resources/data.db';
- $this->db_file = dirname(__FILE__).'/resources/test.db';
- copy($file,$this->db_file);
- $provider = new TAdodb();
- }
-
- function getDsn()
- {
- return 'sqlite://'.urlencode(realpath($this->db_file));
- }
-
- function testProviderCreation()
- {
- $provider = new TAdodb();
- $connection = $provider->getConnection();
- $this->assertTrue($connection instanceof TAdodbConnection);
- try
- {
- $connection->open();
- $this->fail();
- }
- catch (TDbConnectionException $e)
- {
- $this->pass();
- }
- }
-
-
-
- function testAdodbSqliteConnection()
- {
- $connection = new TAdodbConnection($this->getDsn());
- $this->assertTrue($connection->open());
-
- $statement = "insert into person(per_id, per_first_name,
- per_last_name, per_birth_date, per_weight_kg, per_height_m)
- values(?, ?, ?, ?, ?, ?)";
- $sql = $connection->prepare($statement);
- $connection->execute($sql,
- array(2,'mini','me','2000-01-01', 50.5, 145.5));
-
- $statement = "select * from person";
- $results = $connection->execute($statement);
- $this->assertEquals($results->RecordCount(), 2);
-
- }
-}
-
+<?php + +require_once dirname(__FILE__).'/../phpunit2.php'; + +require_once(dirname(__FILE__).'/common.php'); + +/** + * @package System.DataAccess + */ +class TAdodbConnectionTestCase extends PHPUnit2_Framework_TestCase +{ + protected $db_file; + + function setup() + { + $file = dirname(__FILE__).'/resources/data.db'; + $this->db_file = dirname(__FILE__).'/resources/test.db'; + copy($file,$this->db_file); + $provider = new TAdodb(); + } + + function getDsn() + { + return 'sqlite://'.urlencode(realpath($this->db_file)); + } + + function testProviderCreation() + { + $provider = new TAdodb(); + $connection = $provider->getConnection(); + $this->assertTrue($connection instanceof TAdodbConnection); + try + { + $connection->open(); + $this->fail(); + } + catch (TDbConnectionException $e) + { + $this->pass(); + } + } + + + + function testAdodbSqliteConnection() + { + $connection = new TAdodbConnection($this->getDsn()); + $this->assertTrue($connection->open()); + + $statement = "insert into person(per_id, per_first_name, + per_last_name, per_birth_date, per_weight_kg, per_height_m) + values(?, ?, ?, ?, ?, ?)"; + $sql = $connection->prepare($statement); + $connection->execute($sql, + array(2,'mini','me','2000-01-01', 50.5, 145.5)); + + $statement = "select * from person"; + $results = $connection->execute($statement); + $this->assertEquals($results->RecordCount(), 2); + + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/common.php b/tests/unit/SQLMap/common.php index 97f83267..f13fe829 100644 --- a/tests/unit/SQLMap/common.php +++ b/tests/unit/SQLMap/common.php @@ -1,152 +1,152 @@ -<?php
-
-
-if(!defined('SQLMAP_DIR'))
- define('SQLMAP_DIR', Prado::getFrameworkPath().'/DataAccess/SQLMap/');
-
-require_once(SQLMAP_DIR.'/TMapper.php');
-
-if(!defined('SQLMAP_TESTS'))
- define('SQLMAP_TESTS', realpath(dirname(__FILE__)));
-
-if(!class_exists('Account', false))
-{
- include(SQLMAP_TESTS.'/domain/A.php');
- include(SQLMAP_TESTS.'/domain/Account.php');
- include(SQLMAP_TESTS.'/domain/AccountBis.php');
- include(SQLMAP_TESTS.'/domain/AccountCollection.php');
- include(SQLMAP_TESTS.'/domain/B.php');
- include(SQLMAP_TESTS.'/domain/Document.php');
- include(SQLMAP_TESTS.'/domain/Book.php');
- include(SQLMAP_TESTS.'/domain/C.php');
- include(SQLMAP_TESTS.'/domain/Category.php');
- include(SQLMAP_TESTS.'/domain/Complex.php');
- include(SQLMAP_TESTS.'/domain/D.php');
- include(SQLMAP_TESTS.'/domain/DocumentCollection.php');
- include(SQLMAP_TESTS.'/domain/E.php');
- include(SQLMAP_TESTS.'/domain/F.php');
- include(SQLMAP_TESTS.'/domain/LineItem.php');
- include(SQLMAP_TESTS.'/domain/LineItemCollection.php');
- include(SQLMAP_TESTS.'/domain/Newspaper.php');
- include(SQLMAP_TESTS.'/domain/Order.php');
- include(SQLMAP_TESTS.'/domain/Other.php');
- include(SQLMAP_TESTS.'/domain/Sample.php');
- include(SQLMAP_TESTS.'/domain/Search.php');
- include(SQLMAP_TESTS.'/domain/User.php');
-}
-
-error_reporting(E_ALL);
-restore_error_handler();
-
-class DefaultScriptRunner
-{
- function runScript($connection, $script)
- {
- $sql = file_get_contents($script);
- $lines = explode(';', $sql);
- foreach($lines as $line)
- {
- $line = trim($line);
- if(strlen($line) > 0)
- $connection->execute($line);
- }
- }
-}
-
-class CopyFileScriptRunner
-{
- protected $baseFile;
- protected $targetFile;
-
- public function __construct($base, $target)
- {
- $this->baseFile = $base;
- $this->targetFile = $target;
- }
-
- function runScript($connection, $script)
- {
- copy($this->baseFile, $this->targetFile);
- }
-}
-
-class SQLiteBaseTestConfig extends BaseTestConfig
-{
- protected $baseFile;
- protected $targetFile;
-
- public function __construct()
- {
- $this->_sqlmap = SQLMAP_TESTS.'/sqlite.xml';
- $this->targetFile = realpath(SQLMAP_TESTS.'/sqlite/tests.db');
- $this->baseFile = realpath(SQLMAP_TESTS.'/sqlite/backup.db');
- $file = urlencode($this->targetFile);
- $this->_connectionString = "sqlite://{$file}/";
- $this->_scriptDir = SQLMAP_TESTS.'/scripts/sqlite/';
- }
-
- public function getScriptRunner()
- {
- return new CopyFileScriptRunner($this->baseFile, $this->targetFile);
- }
-}
-
-class MySQLBaseTestConfig extends BaseTestConfig
-{
- public function __construct()
- {
- $this->_sqlmap = SQLMAP_TESTS.'/mysql.xml';
- $this->_connectionString = 'mysql://root:weizhuo01@localhost/IBatisNet';
- $this->_scriptDir = SQLMAP_TESTS.'/scripts/mysql/';
- $this->_features = array('insert_id');
- }
-}
-
-class MSSQLBaseTestConfig extends BaseTestConfig
-{
- public function __construct()
- {
- $this->_sqlmap = SQLMAP_TESTS.'/mssql.xml';
- $this->_connectionString = 'odbc_mssql://sqlmap_tests';
- $this->_scriptDir = SQLMAP_TESTS.'/scripts/mssql/';
- $this->_features = array('insert_id');
- }
-}
-
-class BaseTestConfig
-{
- protected $_scriptDir;
- protected $_connectionString;
- protected $_sqlmap;
- protected $_features = array();
-
- public function getScriptDir() { return $this->_scriptDir; }
- public function getConnectionString() { return $this->_connectionString; }
- public function getSqlMapConfigFile(){ return $this->_sqlmap; }
-
- public function hasFeature($feature)
- {
- return in_array($feature, $this->_features);
- }
-
- public function getScriptRunner()
- {
- return new DefaultScriptRunner();
- }
-
-
- public static function createConfigInstance()
- {
- //change this to connection to a different database
-
- //return new MySQLBaseTestConfig();
-
- return new SQLiteBaseTestConfig();
-
- //return new MSSQLBaseTestConfig();
- }
-
-}
-
-
+<?php + + +if(!defined('SQLMAP_DIR')) + define('SQLMAP_DIR', Prado::getFrameworkPath().'/DataAccess/SQLMap/'); + +require_once(SQLMAP_DIR.'/TMapper.php'); + +if(!defined('SQLMAP_TESTS')) + define('SQLMAP_TESTS', realpath(dirname(__FILE__))); + +if(!class_exists('Account', false)) +{ + include(SQLMAP_TESTS.'/domain/A.php'); + include(SQLMAP_TESTS.'/domain/Account.php'); + include(SQLMAP_TESTS.'/domain/AccountBis.php'); + include(SQLMAP_TESTS.'/domain/AccountCollection.php'); + include(SQLMAP_TESTS.'/domain/B.php'); + include(SQLMAP_TESTS.'/domain/Document.php'); + include(SQLMAP_TESTS.'/domain/Book.php'); + include(SQLMAP_TESTS.'/domain/C.php'); + include(SQLMAP_TESTS.'/domain/Category.php'); + include(SQLMAP_TESTS.'/domain/Complex.php'); + include(SQLMAP_TESTS.'/domain/D.php'); + include(SQLMAP_TESTS.'/domain/DocumentCollection.php'); + include(SQLMAP_TESTS.'/domain/E.php'); + include(SQLMAP_TESTS.'/domain/F.php'); + include(SQLMAP_TESTS.'/domain/LineItem.php'); + include(SQLMAP_TESTS.'/domain/LineItemCollection.php'); + include(SQLMAP_TESTS.'/domain/Newspaper.php'); + include(SQLMAP_TESTS.'/domain/Order.php'); + include(SQLMAP_TESTS.'/domain/Other.php'); + include(SQLMAP_TESTS.'/domain/Sample.php'); + include(SQLMAP_TESTS.'/domain/Search.php'); + include(SQLMAP_TESTS.'/domain/User.php'); +} + +error_reporting(E_ALL); +restore_error_handler(); + +class DefaultScriptRunner +{ + function runScript($connection, $script) + { + $sql = file_get_contents($script); + $lines = explode(';', $sql); + foreach($lines as $line) + { + $line = trim($line); + if(strlen($line) > 0) + $connection->execute($line); + } + } +} + +class CopyFileScriptRunner +{ + protected $baseFile; + protected $targetFile; + + public function __construct($base, $target) + { + $this->baseFile = $base; + $this->targetFile = $target; + } + + function runScript($connection, $script) + { + copy($this->baseFile, $this->targetFile); + } +} + +class SQLiteBaseTestConfig extends BaseTestConfig +{ + protected $baseFile; + protected $targetFile; + + public function __construct() + { + $this->_sqlmap = SQLMAP_TESTS.'/sqlite.xml'; + $this->targetFile = realpath(SQLMAP_TESTS.'/sqlite/tests.db'); + $this->baseFile = realpath(SQLMAP_TESTS.'/sqlite/backup.db'); + $file = urlencode($this->targetFile); + $this->_connectionString = "sqlite://{$file}/"; + $this->_scriptDir = SQLMAP_TESTS.'/scripts/sqlite/'; + } + + public function getScriptRunner() + { + return new CopyFileScriptRunner($this->baseFile, $this->targetFile); + } +} + +class MySQLBaseTestConfig extends BaseTestConfig +{ + public function __construct() + { + $this->_sqlmap = SQLMAP_TESTS.'/mysql.xml'; + $this->_connectionString = 'mysql://root:weizhuo01@localhost/IBatisNet'; + $this->_scriptDir = SQLMAP_TESTS.'/scripts/mysql/'; + $this->_features = array('insert_id'); + } +} + +class MSSQLBaseTestConfig extends BaseTestConfig +{ + public function __construct() + { + $this->_sqlmap = SQLMAP_TESTS.'/mssql.xml'; + $this->_connectionString = 'odbc_mssql://sqlmap_tests'; + $this->_scriptDir = SQLMAP_TESTS.'/scripts/mssql/'; + $this->_features = array('insert_id'); + } +} + +class BaseTestConfig +{ + protected $_scriptDir; + protected $_connectionString; + protected $_sqlmap; + protected $_features = array(); + + public function getScriptDir() { return $this->_scriptDir; } + public function getConnectionString() { return $this->_connectionString; } + public function getSqlMapConfigFile(){ return $this->_sqlmap; } + + public function hasFeature($feature) + { + return in_array($feature, $this->_features); + } + + public function getScriptRunner() + { + return new DefaultScriptRunner(); + } + + + public static function createConfigInstance() + { + //change this to connection to a different database + + //return new MySQLBaseTestConfig(); + + return new SQLiteBaseTestConfig(); + + //return new MSSQLBaseTestConfig(); + } + +} + + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/A.php b/tests/unit/SQLMap/domain/A.php index 6830ea4d..af1f925d 100644 --- a/tests/unit/SQLMap/domain/A.php +++ b/tests/unit/SQLMap/domain/A.php @@ -1,27 +1,27 @@ -<?php
-
-class A
-{
- private $_ID='';
- private $_Libelle='';
- private $_B='';
- private $_E='';
- private $_F='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getLibelle(){ return $this->_Libelle; }
- public function setLibelle($value){ $this->_Libelle = $value; }
-
- public function getB(){ return $this->_B; }
- public function setB($value){ $this->_B = $value; }
-
- public function getE(){ return $this->_E; }
- public function setE($value){ $this->_E = $value; }
-
- public function getF(){ return $this->_F; }
- public function setF($value){ $this->_F = $value; }
-}
-
+<?php + +class A +{ + private $_ID=''; + private $_Libelle=''; + private $_B=''; + private $_E=''; + private $_F=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + + public function getB(){ return $this->_B; } + public function setB($value){ $this->_B = $value; } + + public function getE(){ return $this->_E; } + public function setE($value){ $this->_E = $value; } + + public function getF(){ return $this->_F; } + public function setF($value){ $this->_F = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Account.php b/tests/unit/SQLMap/domain/Account.php index f01726ba..9502eb85 100644 --- a/tests/unit/SQLMap/domain/Account.php +++ b/tests/unit/SQLMap/domain/Account.php @@ -1,36 +1,36 @@ -<?php
-
-class Account
-{
- private $_ID=0;
- private $_FirstName='';
- private $_LastName='';
- private $_EmailAddress=null;
- private $_IDS='';
- private $_BannerOptions=0;
- private $_CartOptions=0;
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = intval($value); }
-
- public function getFirstName(){ return $this->_FirstName; }
- public function setFirstName($value){ $this->_FirstName = $value; }
-
- public function getLastName(){ return $this->_LastName; }
- public function setLastName($value){ $this->_LastName = $value; }
-
- public function getEmailAddress(){ return $this->_EmailAddress; }
- public function setEmailAddress($value){ $this->_EmailAddress = $value; }
-
- public function getIDS(){ return $this->_IDS; }
- public function setIDS($value){ $this->_IDS = $value; }
-
- public function getBannerOptions(){ return $this->_BannerOptions; }
- public function setBannerOptions($value){ $this->_BannerOptions = $value; }
-
- public function getCartOptions(){ return $this->_CartOptions; }
- public function setCartOptions($value){ $this->_CartOptions = $value; }
-
-}
-
+<?php + +class Account +{ + private $_ID=0; + private $_FirstName=''; + private $_LastName=''; + private $_EmailAddress=null; + private $_IDS=''; + private $_BannerOptions=0; + private $_CartOptions=0; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = intval($value); } + + public function getFirstName(){ return $this->_FirstName; } + public function setFirstName($value){ $this->_FirstName = $value; } + + public function getLastName(){ return $this->_LastName; } + public function setLastName($value){ $this->_LastName = $value; } + + public function getEmailAddress(){ return $this->_EmailAddress; } + public function setEmailAddress($value){ $this->_EmailAddress = $value; } + + public function getIDS(){ return $this->_IDS; } + public function setIDS($value){ $this->_IDS = $value; } + + public function getBannerOptions(){ return $this->_BannerOptions; } + public function setBannerOptions($value){ $this->_BannerOptions = $value; } + + public function getCartOptions(){ return $this->_CartOptions; } + public function setCartOptions($value){ $this->_CartOptions = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/AccountBis.php b/tests/unit/SQLMap/domain/AccountBis.php index 8c96d8e4..d454f2a8 100644 --- a/tests/unit/SQLMap/domain/AccountBis.php +++ b/tests/unit/SQLMap/domain/AccountBis.php @@ -1,13 +1,13 @@ -<?php
-
-class AccountBis
-{
- public $Id;
- public $FirstName;
- public $LastName;
- public $EmailAddress;
- public $More;
-}
-
-
+<?php + +class AccountBis +{ + public $Id; + public $FirstName; + public $LastName; + public $EmailAddress; + public $More; +} + + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/AccountCollection.php b/tests/unit/SQLMap/domain/AccountCollection.php index 9fc8edb7..b14ece5e 100644 --- a/tests/unit/SQLMap/domain/AccountCollection.php +++ b/tests/unit/SQLMap/domain/AccountCollection.php @@ -1,17 +1,17 @@ -<?php
-
-class AccountCollection extends TList
-{
- public function addRange($accounts)
- {
- foreach($accounts as $account)
- $this->add($account);
- }
-
- public function copyTo(TList $array)
- {
- $array->copyFrom($this);
- }
-}
-
+<?php + +class AccountCollection extends TList +{ + public function addRange($accounts) + { + foreach($accounts as $account) + $this->add($account); + } + + public function copyTo(TList $array) + { + $array->copyFrom($this); + } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/B.php b/tests/unit/SQLMap/domain/B.php index a05e21d4..788b804e 100644 --- a/tests/unit/SQLMap/domain/B.php +++ b/tests/unit/SQLMap/domain/B.php @@ -1,23 +1,23 @@ -<?php
-
-class B
-{
- private $_C='';
- private $_D='';
- private $_ID='';
- private $_Libelle='';
-
- public function getC(){ return $this->_C; }
- public function setC($value){ $this->_C = $value; }
-
- public function getD(){ return $this->_D; }
- public function setD($value){ $this->_D = $value; }
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getLibelle(){ return $this->_Libelle; }
- public function setLibelle($value){ $this->_Libelle = $value; }
-}
-
+<?php + +class B +{ + private $_C=''; + private $_D=''; + private $_ID=''; + private $_Libelle=''; + + public function getC(){ return $this->_C; } + public function setC($value){ $this->_C = $value; } + + public function getD(){ return $this->_D; } + public function setD($value){ $this->_D = $value; } + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Book.php b/tests/unit/SQLMap/domain/Book.php index cc12c30e..80877112 100644 --- a/tests/unit/SQLMap/domain/Book.php +++ b/tests/unit/SQLMap/domain/Book.php @@ -1,11 +1,11 @@ -<?php
-
-class Book extends Document
-{
- private $_PageNumber='';
-
- public function getPageNumber(){ return $this->_PageNumber; }
- public function setPageNumber($value){ $this->_PageNumber = $value; }
-}
-
+<?php + +class Book extends Document +{ + private $_PageNumber=''; + + public function getPageNumber(){ return $this->_PageNumber; } + public function setPageNumber($value){ $this->_PageNumber = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/C.php b/tests/unit/SQLMap/domain/C.php index 09fb456a..47118d44 100644 --- a/tests/unit/SQLMap/domain/C.php +++ b/tests/unit/SQLMap/domain/C.php @@ -1,15 +1,15 @@ -<?php
-
-class C
-{
- private $_ID='';
- private $_Libelle='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getLibelle(){ return $this->_Libelle; }
- public function setLibelle($value){ $this->_Libelle = $value; }
-}
-
+<?php + +class C +{ + private $_ID=''; + private $_Libelle=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Category.php b/tests/unit/SQLMap/domain/Category.php index 83fecc7e..db76edb4 100644 --- a/tests/unit/SQLMap/domain/Category.php +++ b/tests/unit/SQLMap/domain/Category.php @@ -1,19 +1,19 @@ -<?php
-
-class Category
-{
- private $_ID=-1;
- private $_Name='';
- private $_Guid='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getName(){ return $this->_Name; }
- public function setName($value){ $this->_Name = $value; }
-
- public function getGuidString(){ return $this->_Guid; }
- public function setGuidString($value){ $this->_Guid = $value; }
-}
-
+<?php + +class Category +{ + private $_ID=-1; + private $_Name=''; + private $_Guid=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getName(){ return $this->_Name; } + public function setName($value){ $this->_Name = $value; } + + public function getGuidString(){ return $this->_Guid; } + public function setGuidString($value){ $this->_Guid = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Complex.php b/tests/unit/SQLMap/domain/Complex.php index 92b500f4..99cb04b8 100644 --- a/tests/unit/SQLMap/domain/Complex.php +++ b/tests/unit/SQLMap/domain/Complex.php @@ -1,11 +1,11 @@ -<?php
-
-class Complex
-{
- private $_map;
-
- public function getMap(){ return $this->_map; }
- public function setMap(TMap $map){ $this->_map = $map; }
-}
-
+<?php + +class Complex +{ + private $_map; + + public function getMap(){ return $this->_map; } + public function setMap(TMap $map){ $this->_map = $map; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/D.php b/tests/unit/SQLMap/domain/D.php index 5d1baabd..2cbd2883 100644 --- a/tests/unit/SQLMap/domain/D.php +++ b/tests/unit/SQLMap/domain/D.php @@ -1,16 +1,16 @@ -<?php
-
-class D
-{
- private $_ID='';
- private $_Libelle='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getLibelle(){ return $this->_Libelle; }
- public function setLibelle($value){ $this->_Libelle = $value; }
-
-}
-
+<?php + +class D +{ + private $_ID=''; + private $_Libelle=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Document.php b/tests/unit/SQLMap/domain/Document.php index 63bcfd33..682f8eb3 100644 --- a/tests/unit/SQLMap/domain/Document.php +++ b/tests/unit/SQLMap/domain/Document.php @@ -1,16 +1,16 @@ -<?php
-
-class Document
-{
- private $_ID='';
- private $_Title='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getTitle(){ return $this->_Title; }
- public function setTitle($value){ $this->_Title = $value; }
-
-}
-
+<?php + +class Document +{ + private $_ID=''; + private $_Title=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getTitle(){ return $this->_Title; } + public function setTitle($value){ $this->_Title = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/DocumentCollection.php b/tests/unit/SQLMap/domain/DocumentCollection.php index c15b6f7d..c130db56 100644 --- a/tests/unit/SQLMap/domain/DocumentCollection.php +++ b/tests/unit/SQLMap/domain/DocumentCollection.php @@ -1,8 +1,8 @@ -<?php
-
-class DocumentCollection extends TList
-{
-
-}
-
+<?php + +class DocumentCollection extends TList +{ + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/E.php b/tests/unit/SQLMap/domain/E.php index 2c80bb46..8473c156 100644 --- a/tests/unit/SQLMap/domain/E.php +++ b/tests/unit/SQLMap/domain/E.php @@ -1,16 +1,16 @@ -<?php
-
-class E
-{
- private $_ID='';
- private $_Libelle='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getLibelle(){ return $this->_Libelle; }
- public function setLibelle($value){ $this->_Libelle = $value; }
-
-}
-
+<?php + +class E +{ + private $_ID=''; + private $_Libelle=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/F.php b/tests/unit/SQLMap/domain/F.php index b1090cc6..2bbbb2fb 100644 --- a/tests/unit/SQLMap/domain/F.php +++ b/tests/unit/SQLMap/domain/F.php @@ -1,16 +1,16 @@ -<?php
-
-class F
-{
- private $_ID='';
- private $_Libelle='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getLibelle(){ return $this->_Libelle; }
- public function setLibelle($value){ $this->_Libelle = $value; }
-
-}
-
+<?php + +class F +{ + private $_ID=''; + private $_Libelle=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/LineItem.php b/tests/unit/SQLMap/domain/LineItem.php index d851da6c..f6908bbd 100644 --- a/tests/unit/SQLMap/domain/LineItem.php +++ b/tests/unit/SQLMap/domain/LineItem.php @@ -1,32 +1,32 @@ -<?php
-
-class LineItem
-{
- private $_ID=-1;
- private $_Order='';
- private $_Code='';
- private $_Quantity=-1;
- private $_Price=0.0;
- private $_PictureData='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getOrder(){ return $this->_Order; }
- public function setOrder($value){ $this->_Order = $value; }
-
- public function getCode(){ return $this->_Code; }
- public function setCode($value){ $this->_Code = $value; }
-
- public function getQuantity(){ return $this->_Quantity; }
- public function setQuantity($value){ $this->_Quantity = $value; }
-
- public function getPrice(){ return $this->_Price; }
- public function setPrice($value){ $this->_Price = $value; }
-
- public function getPictureData(){ return $this->_PictureData; }
- public function setPictureData($value){ $this->_PictureData = $value; }
-
-}
-
+<?php + +class LineItem +{ + private $_ID=-1; + private $_Order=''; + private $_Code=''; + private $_Quantity=-1; + private $_Price=0.0; + private $_PictureData=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getOrder(){ return $this->_Order; } + public function setOrder($value){ $this->_Order = $value; } + + public function getCode(){ return $this->_Code; } + public function setCode($value){ $this->_Code = $value; } + + public function getQuantity(){ return $this->_Quantity; } + public function setQuantity($value){ $this->_Quantity = $value; } + + public function getPrice(){ return $this->_Price; } + public function setPrice($value){ $this->_Price = $value; } + + public function getPictureData(){ return $this->_PictureData; } + public function setPictureData($value){ $this->_PictureData = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/LineItemCollection.php b/tests/unit/SQLMap/domain/LineItemCollection.php index f177487c..8bc95622 100644 --- a/tests/unit/SQLMap/domain/LineItemCollection.php +++ b/tests/unit/SQLMap/domain/LineItemCollection.php @@ -1,8 +1,8 @@ -<?php
-
-class LineItemCollection extends TList
-{
-
-}
-
+<?php + +class LineItemCollection extends TList +{ + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Newspaper.php b/tests/unit/SQLMap/domain/Newspaper.php index 4eb56aa2..08716c6d 100644 --- a/tests/unit/SQLMap/domain/Newspaper.php +++ b/tests/unit/SQLMap/domain/Newspaper.php @@ -1,12 +1,12 @@ -<?php
-
-class Newspaper extends Document
-{
- private $_City='';
-
- public function getCity(){ return $this->_City; }
- public function setCity($value){ $this->_City = $value; }
-
-}
-
+<?php + +class Newspaper extends Document +{ + private $_City=''; + + public function getCity(){ return $this->_City; } + public function setCity($value){ $this->_City = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Order.php b/tests/unit/SQLMap/domain/Order.php index 65d18b13..312626fe 100644 --- a/tests/unit/SQLMap/domain/Order.php +++ b/tests/unit/SQLMap/domain/Order.php @@ -1,71 +1,71 @@ -<?php
-
-class Order
-{
- private $_ID=-1;
- private $_Account='';
- private $_Date='';
- private $_CardType='';
- private $_CardExpiry='';
- private $_CardNumber='';
- private $_Street='';
- private $_City='';
- private $_Province='';
- private $_PostalCode='';
- private $_LineItemsList='';
- private $_LineItems=null;
- private $_LineItemsArray=array();
- private $_FavouriteLineItem=null;
-
- public function __construct()
- {
- $this->_LineItemsList = new TList;
- $this->_LineItems = new TList;
- $this->_FavouriteLineItem = new LineItem;
- }
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getAccount(){ return $this->_Account; }
- public function setAccount($value){ $this->_Account = $value; }
-
- public function getDate(){ return $this->_Date; }
- public function setDate($value){ $this->_Date = $value; }
-
- public function getCardType(){ return $this->_CardType; }
- public function setCardType($value){ $this->_CardType = $value; }
-
- public function getCardExpiry(){ return $this->_CardExpiry; }
- public function setCardExpiry($value){ $this->_CardExpiry = $value; }
-
- public function getCardNumber(){ return $this->_CardNumber; }
- public function setCardNumber($value){ $this->_CardNumber = $value; }
-
- public function getStreet(){ return $this->_Street; }
- public function setStreet($value){ $this->_Street = $value; }
-
- public function getCity(){ return $this->_City; }
- public function setCity($value){ $this->_City = $value; }
-
- public function getProvince(){ return $this->_Province; }
- public function setProvince($value){ $this->_Province = $value; }
-
- public function getPostalCode(){ return $this->_PostalCode; }
- public function setPostalCode($value){ $this->_PostalCode = $value; }
-
- public function getLineItemsList(){ return $this->_LineItemsList; }
- public function setLineItemsList($value){ $this->_LineItemsList = $value; }
-
- public function getLineItems(){ return $this->_LineItems; }
- public function setLineItems($value){ $this->_LineItems = $value; }
-
- public function getLineItemsArray(){ return $this->_LineItemsArray; }
- public function setLineItemsArray($value){ $this->_LineItemsArray = $value; }
-
- public function getFavouriteLineItem(){ return $this->_FavouriteLineItem; }
- public function setFavouriteLineItem($value){ $this->_FavouriteLineItem = $value; }
-
-}
-
+<?php + +class Order +{ + private $_ID=-1; + private $_Account=''; + private $_Date=''; + private $_CardType=''; + private $_CardExpiry=''; + private $_CardNumber=''; + private $_Street=''; + private $_City=''; + private $_Province=''; + private $_PostalCode=''; + private $_LineItemsList=''; + private $_LineItems=null; + private $_LineItemsArray=array(); + private $_FavouriteLineItem=null; + + public function __construct() + { + $this->_LineItemsList = new TList; + $this->_LineItems = new TList; + $this->_FavouriteLineItem = new LineItem; + } + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getAccount(){ return $this->_Account; } + public function setAccount($value){ $this->_Account = $value; } + + public function getDate(){ return $this->_Date; } + public function setDate($value){ $this->_Date = $value; } + + public function getCardType(){ return $this->_CardType; } + public function setCardType($value){ $this->_CardType = $value; } + + public function getCardExpiry(){ return $this->_CardExpiry; } + public function setCardExpiry($value){ $this->_CardExpiry = $value; } + + public function getCardNumber(){ return $this->_CardNumber; } + public function setCardNumber($value){ $this->_CardNumber = $value; } + + public function getStreet(){ return $this->_Street; } + public function setStreet($value){ $this->_Street = $value; } + + public function getCity(){ return $this->_City; } + public function setCity($value){ $this->_City = $value; } + + public function getProvince(){ return $this->_Province; } + public function setProvince($value){ $this->_Province = $value; } + + public function getPostalCode(){ return $this->_PostalCode; } + public function setPostalCode($value){ $this->_PostalCode = $value; } + + public function getLineItemsList(){ return $this->_LineItemsList; } + public function setLineItemsList($value){ $this->_LineItemsList = $value; } + + public function getLineItems(){ return $this->_LineItems; } + public function setLineItems($value){ $this->_LineItems = $value; } + + public function getLineItemsArray(){ return $this->_LineItemsArray; } + public function setLineItemsArray($value){ $this->_LineItemsArray = $value; } + + public function getFavouriteLineItem(){ return $this->_FavouriteLineItem; } + public function setFavouriteLineItem($value){ $this->_FavouriteLineItem = $value; } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Other.php b/tests/unit/SQLMap/domain/Other.php index 32d85e90..9e78ab97 100644 --- a/tests/unit/SQLMap/domain/Other.php +++ b/tests/unit/SQLMap/domain/Other.php @@ -1,23 +1,23 @@ -<?php
-
-class Other
-{
- private $_Int=-1;
- private $_Long=-1;
- private $_Bool=false;
- private $_Bool2=false;
-
- public function getBool2(){ return $this->_Bool2; }
- public function setBool2($value){ $this->_Bool2 = $value; }
-
- public function getBool(){ return $this->_Bool; }
- public function setBool($value){ $this->_Bool = $value; }
-
- public function getInt(){ return $this->_Int; }
- public function setInt($value){ $this->_Int = $value; }
-
- public function getLong(){ return $this->_Long; }
- public function setLong($value){ $this->_Long = $value; }
-}
-
+<?php + +class Other +{ + private $_Int=-1; + private $_Long=-1; + private $_Bool=false; + private $_Bool2=false; + + public function getBool2(){ return $this->_Bool2; } + public function setBool2($value){ $this->_Bool2 = $value; } + + public function getBool(){ return $this->_Bool; } + public function setBool($value){ $this->_Bool = $value; } + + public function getInt(){ return $this->_Int; } + public function setInt($value){ $this->_Int = $value; } + + public function getLong(){ return $this->_Long; } + public function setLong($value){ $this->_Long = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Sample.php b/tests/unit/SQLMap/domain/Sample.php index c9a34601..e03be2df 100644 --- a/tests/unit/SQLMap/domain/Sample.php +++ b/tests/unit/SQLMap/domain/Sample.php @@ -1,55 +1,55 @@ -<?php
-
-class Sample
-{
- private $_FirstID='';
- private $_SecondID='';
- private $_ThirdID='';
- private $_FourthID='';
- private $_FifthID='';
- private $_SequenceID='';
- private $_DistributedID='';
- private $_SampleChar='';
- private $_SampleDecimal='';
- private $_SampleMoney='';
- private $_SampleDate='';
- private $_SequenceDate='';
-
- public function getFirstID(){ return $this->_FirstID; }
- public function setFirstID($value){ $this->_FirstID = $value; }
-
- public function getSecondID(){ return $this->_SecondID; }
- public function setSecondID($value){ $this->_SecondID = $value; }
-
- public function getThirdID(){ return $this->_ThirdID; }
- public function setThirdID($value){ $this->_ThirdID = $value; }
-
- public function getFourthID(){ return $this->_FourthID; }
- public function setFourthID($value){ $this->_FourthID = $value; }
-
- public function getFifthID(){ return $this->_FifthID; }
- public function setFifthID($value){ $this->_FifthID = $value; }
-
- public function getSequenceID(){ return $this->_SequenceID; }
- public function setSequenceID($value){ $this->_SequenceID = $value; }
-
- public function getDistributedID(){ return $this->_DistributedID; }
- public function setDistributedID($value){ $this->_DistributedID = $value; }
-
- public function getSampleChar(){ return $this->_SampleChar; }
- public function setSampleChar($value){ $this->_SampleChar = $value; }
-
- public function getSampleDecimal(){ return $this->_SampleDecimal; }
- public function setSampleDecimal($value){ $this->_SampleDecimal = $value; }
-
- public function getSampleMoney(){ return $this->_SampleMoney; }
- public function setSampleMoney($value){ $this->_SampleMoney = $value; }
-
- public function getSampleDate(){ return $this->_SampleDate; }
- public function setSampleDate($value){ $this->_SampleDate = $value; }
-
- public function getSequenceDate(){ return $this->_SequenceDate; }
- public function setSequenceDate($value){ $this->_SequenceDate = $value; }
-}
-
+<?php + +class Sample +{ + private $_FirstID=''; + private $_SecondID=''; + private $_ThirdID=''; + private $_FourthID=''; + private $_FifthID=''; + private $_SequenceID=''; + private $_DistributedID=''; + private $_SampleChar=''; + private $_SampleDecimal=''; + private $_SampleMoney=''; + private $_SampleDate=''; + private $_SequenceDate=''; + + public function getFirstID(){ return $this->_FirstID; } + public function setFirstID($value){ $this->_FirstID = $value; } + + public function getSecondID(){ return $this->_SecondID; } + public function setSecondID($value){ $this->_SecondID = $value; } + + public function getThirdID(){ return $this->_ThirdID; } + public function setThirdID($value){ $this->_ThirdID = $value; } + + public function getFourthID(){ return $this->_FourthID; } + public function setFourthID($value){ $this->_FourthID = $value; } + + public function getFifthID(){ return $this->_FifthID; } + public function setFifthID($value){ $this->_FifthID = $value; } + + public function getSequenceID(){ return $this->_SequenceID; } + public function setSequenceID($value){ $this->_SequenceID = $value; } + + public function getDistributedID(){ return $this->_DistributedID; } + public function setDistributedID($value){ $this->_DistributedID = $value; } + + public function getSampleChar(){ return $this->_SampleChar; } + public function setSampleChar($value){ $this->_SampleChar = $value; } + + public function getSampleDecimal(){ return $this->_SampleDecimal; } + public function setSampleDecimal($value){ $this->_SampleDecimal = $value; } + + public function getSampleMoney(){ return $this->_SampleMoney; } + public function setSampleMoney($value){ $this->_SampleMoney = $value; } + + public function getSampleDate(){ return $this->_SampleDate; } + public function setSampleDate($value){ $this->_SampleDate = $value; } + + public function getSequenceDate(){ return $this->_SequenceDate; } + public function setSequenceDate($value){ $this->_SequenceDate = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/Search.php b/tests/unit/SQLMap/domain/Search.php index a09ca6e6..c01891a9 100644 --- a/tests/unit/SQLMap/domain/Search.php +++ b/tests/unit/SQLMap/domain/Search.php @@ -1,23 +1,23 @@ -<?php
-
-class Search
-{
- private $_NumberSearch='';
- private $_StartDate='';
- private $_Operande='';
- private $_StartDateAnd='';
-
- public function getNumberSearch(){ return $this->_NumberSearch; }
- public function setNumberSearch($value){ $this->_NumberSearch = $value; }
-
- public function getStartDate(){ return $this->_StartDate; }
- public function setStartDate($value){ $this->_StartDate = $value; }
-
- public function getOperande(){ return $this->_Operande; }
- public function setOperande($value){ $this->_Operande = $value; }
-
- public function getStartDateAnd(){ return $this->_StartDateAnd; }
- public function setStartDateAnd($value){ $this->_StartDateAnd = $value; }
-}
-
+<?php + +class Search +{ + private $_NumberSearch=''; + private $_StartDate=''; + private $_Operande=''; + private $_StartDateAnd=''; + + public function getNumberSearch(){ return $this->_NumberSearch; } + public function setNumberSearch($value){ $this->_NumberSearch = $value; } + + public function getStartDate(){ return $this->_StartDate; } + public function setStartDate($value){ $this->_StartDate = $value; } + + public function getOperande(){ return $this->_Operande; } + public function setOperande($value){ $this->_Operande = $value; } + + public function getStartDateAnd(){ return $this->_StartDateAnd; } + public function setStartDateAnd($value){ $this->_StartDateAnd = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/SQLMap/domain/User.php b/tests/unit/SQLMap/domain/User.php index 0c3a547f..b21712a3 100644 --- a/tests/unit/SQLMap/domain/User.php +++ b/tests/unit/SQLMap/domain/User.php @@ -1,27 +1,27 @@ -<?php
-
-class User
-{
- private $_ID='';
- private $_UserName='';
- private $_Password='';
- private $_EmailAddress='';
- private $_LastLogon='';
-
- public function getID(){ return $this->_ID; }
- public function setID($value){ $this->_ID = $value; }
-
- public function getUserName(){ return $this->_UserName; }
- public function setUserName($value){ $this->_UserName = $value; }
-
- public function getPassword(){ return $this->_Password; }
- public function setPassword($value){ $this->_Password = $value; }
-
- public function getEmailAddress(){ return $this->_EmailAddress; }
- public function setEmailAddress($value){ $this->_EmailAddress = $value; }
-
- public function getLastLogon(){ return $this->_LastLogon; }
- public function setLastLogon($value){ $this->_LastLogon = $value; }
-}
-
+<?php + +class User +{ + private $_ID=''; + private $_UserName=''; + private $_Password=''; + private $_EmailAddress=''; + private $_LastLogon=''; + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getUserName(){ return $this->_UserName; } + public function setUserName($value){ $this->_UserName = $value; } + + public function getPassword(){ return $this->_Password; } + public function setPassword($value){ $this->_Password = $value; } + + public function getEmailAddress(){ return $this->_EmailAddress; } + public function setEmailAddress($value){ $this->_EmailAddress = $value; } + + public function getLastLogon(){ return $this->_LastLogon; } + public function setLastLogon($value){ $this->_LastLogon = $value; } +} + ?>
\ No newline at end of file diff --git a/tests/unit/Util/TDateTimeStampTest.php b/tests/unit/Util/TDateTimeStampTest.php index 8c6baf03..e9a0a22f 100644 --- a/tests/unit/Util/TDateTimeStampTest.php +++ b/tests/unit/Util/TDateTimeStampTest.php @@ -1,149 +1,149 @@ -<?php
-
-require_once dirname(__FILE__).'/../phpunit.php';
-
-Prado::using('System.Util.TDateTimeStamp');
-
-class TDateTimeStampTest extends PHPUnit_Framework_TestCase {
-
- public function testGetTimeStampAndFormat() {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0);
- $this->assertEquals($s->formatDate('Y-m-d'), date('Y-m-d'));
-
- $t = $s->getTimeStamp(0,0,0,6,1,2102);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-06-01');
-
- $t = $s->getTimeStamp(0,0,0,2,1,2102);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-02-01');
- }
-
- public function testGregorianToJulianConversion() {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0,10,11,1492);
-
- //http://www.holidayorigins.com/html/columbus_day.html - Friday check
- $this->assertEquals($s->formatDate('D Y-m-d',$t), 'Fri 1492-10-11');
-
- $t = $s->getTimeStamp(0,0,0,2,29,1500);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1500-02-29');
-
- $t = $s->getTimeStamp(0,0,0,2,29,1700);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1700-03-01');
-
- }
-
- public function testGregorianCorrection() {
- $s = new TDateTimeStamp;
- $diff = $s->getTimeStamp(0,0,0,10,15,1582) - $s->getTimeStamp(0,0,0,10,4,1582);
-
- //This test case fails on my windows machine!
- //$this->assertEquals($diff, 3600*24,
- // "Error in gregorian correction = ".($diff/3600/24)." days");
-
- $this->assertEquals($s->getDayOfWeek(1582,10,15), 5.0);
- $this->assertEquals($s->getDayOfWeek(1582,10,4), 4.0);
- }
-
- public function testOverFlow() {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0,3,33,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-04-02', 'Error in day overflow 1');
-
- $t = $s->getTimeStamp(0,0,0,4,33,1971);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1971-05-03', 'Error in day overflow 2');
- $t = $s->getTimeStamp(0,0,0,1,60,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-03-01', 'Error in day overflow 3 '.$s->getDate('Y-m-d',$t));
- $t = $s->getTimeStamp(0,0,0,12,32,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-01', 'Error in day overflow 4 '.$s->getDate('Y-m-d',$t));
- $t = $s->getTimeStamp(0,0,0,12,63,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-02-01', 'Error in day overflow 5 '.$s->getDate('Y-m-d',$t));
- $t = $s->getTimeStamp(0,0,0,13,3,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-03', 'Error in mth overflow 1');
- }
-
- public function test2DigitTo4DigitYearConversion() {
- $s = new TDateTimeStamp;
- $this->assertEquals($s->get4DigitYear(00), 2000, "Err 2-digit 2000");
- $this->assertEquals($s->get4DigitYear(10), 2010, "Err 2-digit 2010");
- $this->assertEquals($s->get4DigitYear(20), 2020, "Err 2-digit 2020");
- $this->assertEquals($s->get4DigitYear(30), 2030, "Err 2-digit 2030");
- $this->assertEquals($s->get4DigitYear(40), 2040, "Err 2-digit 2040");
- $this->assertEquals($s->get4DigitYear(50), 1950, "Err 2-digit 1950");
- $this->assertEquals($s->get4DigitYear(90), 1990, "Err 2-digit 1990");
- }
-
- public function testStringFormating() {
- $s = new TDateTimeStamp;
- $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003';
- $s1 = date($fmt,0);
- $s2 = $s->formatDate($fmt,0);
- $this->assertEquals($s1, $s2);//, " date() 0 failed \n $s1 \n $s2");
-
- for ($i=10; --$i > 0; ) {
- $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000);
- $s1 = date($fmt,$ts);
- $s2 = $s->formatDate($fmt,$ts);
- //print "$s1 <br>$s2 <p>";
- $this->assertEquals($s1,$s2);
-
- $a1 = getdate($ts);
- $a2 = $s->getDate($ts,false);
- $this->assertEquals($a1,$a2);
- }
- }
-
- public function testRandomDatesBetween100And4000() {
- $this->assertIsValidDate(100,1);
- //echo "Testing year ";
- for ($i=10; --$i >= 0;) {
- $y1 = 100+rand(0,1970-100);
- //echo $y1." ";
- $m = rand(1,12);
- $this->assertIsValidDate($y1,$m);
-
- $y1 = 3000-rand(0,3000-1970);
- //echo $y1." ";
- $this->assertIsValidDate($y1,$m);
- }
- }
-
- public function assertIsValidDate($y1,$m,$d=13) {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0,$m,$d,$y1);
- $rez = $s->formatDate('Y-n-j H:i:s',$t);
-
- $this->assertEquals("$y1-$m-$d 00:00:00", $rez);
- }
-
- function testRandomDates() {
- $start = 1960+rand(0,10);
- $yrs = 12;
- $i = 365.25*86400*($start-1970);
- $offset = 36000+rand(10000,60000);
- $max = 365*$yrs*86400;
- $lastyear = 0;
- $s = new TDateTimeStamp;
-
- // we generate a timestamp, convert it to a date, and convert it back to a timestamp
- // and check if the roundtrip broke the original timestamp value.
- //print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: ";
- $fails = 0;
- for ($max += $i; $i < $max; $i += $offset) {
- $ret = $s->formatDate('m,d,Y,H,i,s',$i);
- $arr = explode(',',$ret);
- if ($lastyear != $arr[2])
- $lastyear = $arr[2];
-
- $newi = $s->getTimestamp($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);
- if ($i != $newi) {
- $fails++;
- //$j = mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);
- //print "Error at $i, $j, getTimestamp() returned $newi ($ret)\n";
- }
- }
- $this->assertEquals($fails, 0);
- }
-}
-
-?>
+<?php + +require_once dirname(__FILE__).'/../phpunit.php'; + +Prado::using('System.Util.TDateTimeStamp'); + +class TDateTimeStampTest extends PHPUnit_Framework_TestCase { + + public function testGetTimeStampAndFormat() { + $s = new TDateTimeStamp; + $t = $s->getTimeStamp(0,0,0); + $this->assertEquals($s->formatDate('Y-m-d'), date('Y-m-d')); + + $t = $s->getTimeStamp(0,0,0,6,1,2102); + $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-06-01'); + + $t = $s->getTimeStamp(0,0,0,2,1,2102); + $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-02-01'); + } + + public function testGregorianToJulianConversion() { + $s = new TDateTimeStamp; + $t = $s->getTimeStamp(0,0,0,10,11,1492); + + //http://www.holidayorigins.com/html/columbus_day.html - Friday check + $this->assertEquals($s->formatDate('D Y-m-d',$t), 'Fri 1492-10-11'); + + $t = $s->getTimeStamp(0,0,0,2,29,1500); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1500-02-29'); + + $t = $s->getTimeStamp(0,0,0,2,29,1700); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1700-03-01'); + + } + + public function testGregorianCorrection() { + $s = new TDateTimeStamp; + $diff = $s->getTimeStamp(0,0,0,10,15,1582) - $s->getTimeStamp(0,0,0,10,4,1582); + + //This test case fails on my windows machine! + //$this->assertEquals($diff, 3600*24, + // "Error in gregorian correction = ".($diff/3600/24)." days"); + + $this->assertEquals($s->getDayOfWeek(1582,10,15), 5.0); + $this->assertEquals($s->getDayOfWeek(1582,10,4), 4.0); + } + + public function testOverFlow() { + $s = new TDateTimeStamp; + $t = $s->getTimeStamp(0,0,0,3,33,1965); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-04-02', 'Error in day overflow 1'); + + $t = $s->getTimeStamp(0,0,0,4,33,1971); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1971-05-03', 'Error in day overflow 2'); + $t = $s->getTimeStamp(0,0,0,1,60,1965); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-03-01', 'Error in day overflow 3 '.$s->getDate('Y-m-d',$t)); + $t = $s->getTimeStamp(0,0,0,12,32,1965); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-01', 'Error in day overflow 4 '.$s->getDate('Y-m-d',$t)); + $t = $s->getTimeStamp(0,0,0,12,63,1965); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-02-01', 'Error in day overflow 5 '.$s->getDate('Y-m-d',$t)); + $t = $s->getTimeStamp(0,0,0,13,3,1965); + $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-03', 'Error in mth overflow 1'); + } + + public function test2DigitTo4DigitYearConversion() { + $s = new TDateTimeStamp; + $this->assertEquals($s->get4DigitYear(00), 2000, "Err 2-digit 2000"); + $this->assertEquals($s->get4DigitYear(10), 2010, "Err 2-digit 2010"); + $this->assertEquals($s->get4DigitYear(20), 2020, "Err 2-digit 2020"); + $this->assertEquals($s->get4DigitYear(30), 2030, "Err 2-digit 2030"); + $this->assertEquals($s->get4DigitYear(40), 2040, "Err 2-digit 2040"); + $this->assertEquals($s->get4DigitYear(50), 1950, "Err 2-digit 1950"); + $this->assertEquals($s->get4DigitYear(90), 1990, "Err 2-digit 1990"); + } + + public function testStringFormating() { + $s = new TDateTimeStamp; + $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003'; + $s1 = date($fmt,0); + $s2 = $s->formatDate($fmt,0); + $this->assertEquals($s1, $s2);//, " date() 0 failed \n $s1 \n $s2"); + + for ($i=10; --$i > 0; ) { + $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000); + $s1 = date($fmt,$ts); + $s2 = $s->formatDate($fmt,$ts); + //print "$s1 <br>$s2 <p>"; + $this->assertEquals($s1,$s2); + + $a1 = getdate($ts); + $a2 = $s->getDate($ts,false); + $this->assertEquals($a1,$a2); + } + } + + public function testRandomDatesBetween100And4000() { + $this->assertIsValidDate(100,1); + //echo "Testing year "; + for ($i=10; --$i >= 0;) { + $y1 = 100+rand(0,1970-100); + //echo $y1." "; + $m = rand(1,12); + $this->assertIsValidDate($y1,$m); + + $y1 = 3000-rand(0,3000-1970); + //echo $y1." "; + $this->assertIsValidDate($y1,$m); + } + } + + public function assertIsValidDate($y1,$m,$d=13) { + $s = new TDateTimeStamp; + $t = $s->getTimeStamp(0,0,0,$m,$d,$y1); + $rez = $s->formatDate('Y-n-j H:i:s',$t); + + $this->assertEquals("$y1-$m-$d 00:00:00", $rez); + } + + function testRandomDates() { + $start = 1960+rand(0,10); + $yrs = 12; + $i = 365.25*86400*($start-1970); + $offset = 36000+rand(10000,60000); + $max = 365*$yrs*86400; + $lastyear = 0; + $s = new TDateTimeStamp; + + // we generate a timestamp, convert it to a date, and convert it back to a timestamp + // and check if the roundtrip broke the original timestamp value. + //print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; + $fails = 0; + for ($max += $i; $i < $max; $i += $offset) { + $ret = $s->formatDate('m,d,Y,H,i,s',$i); + $arr = explode(',',$ret); + if ($lastyear != $arr[2]) + $lastyear = $arr[2]; + + $newi = $s->getTimestamp($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); + if ($i != $newi) { + $fails++; + //$j = mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); + //print "Error at $i, $j, getTimestamp() returned $newi ($ret)\n"; + } + } + $this->assertEquals($fails, 0); + } +} + +?> |