diff options
Diffstat (limited to 'tests/unit/Data/SqlMap/DynamicParameterTest.php')
-rw-r--r-- | tests/unit/Data/SqlMap/DynamicParameterTest.php | 216 |
1 files changed, 108 insertions, 108 deletions
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 |