summaryrefslogtreecommitdiff
path: root/tests/unit/Data/SqlMap/DynamicParameterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/Data/SqlMap/DynamicParameterTest.php')
-rw-r--r--tests/unit/Data/SqlMap/DynamicParameterTest.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/unit/Data/SqlMap/DynamicParameterTest.php b/tests/unit/Data/SqlMap/DynamicParameterTest.php
new file mode 100644
index 00000000..ec37f4e0
--- /dev/null
+++ b/tests/unit/Data/SqlMap/DynamicParameterTest.php
@@ -0,0 +1,90 @@
+<?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($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);
+ }
+
+}
+
+?> \ No newline at end of file