From 466c414ebc9dde38e80f20fd96fd891431404fca Mon Sep 17 00:00:00 2001 From: "godzilla80@gmx.net" <> Date: Sun, 22 Mar 2009 08:02:35 +0000 Subject: Fixed Issue #88 - SQLMap $Param$ re-evaluation bug --- tests/unit/Data/SqlMap/AllTests.php | 28 +++++++ tests/unit/Data/SqlMap/DynamicParameterTest.php | 90 ++++++++++++++++++++++ tests/unit/Data/SqlMap/DynamicParameterTestMap.xml | 33 ++++++++ tests/unit/Data/SqlMap/fixtures/mysql5_reset.sql | 22 ++++++ tests/unit/Data/SqlMap/fixtures/mysql5_setup.sql | 22 ++++++ 5 files changed, 195 insertions(+) create mode 100644 tests/unit/Data/SqlMap/AllTests.php create mode 100644 tests/unit/Data/SqlMap/DynamicParameterTest.php create mode 100644 tests/unit/Data/SqlMap/DynamicParameterTestMap.xml create mode 100644 tests/unit/Data/SqlMap/fixtures/mysql5_reset.sql create mode 100644 tests/unit/Data/SqlMap/fixtures/mysql5_setup.sql (limited to 'tests/unit/Data') diff --git a/tests/unit/Data/SqlMap/AllTests.php b/tests/unit/Data/SqlMap/AllTests.php new file mode 100644 index 00000000..187be17f --- /dev/null +++ b/tests/unit/Data/SqlMap/AllTests.php @@ -0,0 +1,28 @@ +addTestSuite('DynamicParameterTest'); + + return $suite; + } +} + +if(PHPUnit_MAIN_METHOD == 'Data_SqlMap_AllTests::main') { + Data_SqlMap_AllTests::main(); +} +?> \ No newline at end of file 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 @@ +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 diff --git a/tests/unit/Data/SqlMap/DynamicParameterTestMap.xml b/tests/unit/Data/SqlMap/DynamicParameterTestMap.xml new file mode 100644 index 00000000..65a91154 --- /dev/null +++ b/tests/unit/Data/SqlMap/DynamicParameterTestMap.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/unit/Data/SqlMap/fixtures/mysql5_reset.sql b/tests/unit/Data/SqlMap/fixtures/mysql5_reset.sql new file mode 100644 index 00000000..7544ce6b --- /dev/null +++ b/tests/unit/Data/SqlMap/fixtures/mysql5_reset.sql @@ -0,0 +1,22 @@ +TRUNCATE TABLE `prado_system_data_sqlmap`.`dynamicparametertest1`; +TRUNCATE TABLE `prado_system_data_sqlmap`.`dynamicparametertest2`; + +INSERT INTO `prado_system_data_sqlmap`.`dynamicparametertest1` ( + `testname` , + `teststring` , + `testinteger` +) +VALUES +('staticsql', 'staticsql1', '1'), +('dynamictable', 'dynamictableparametertest1', '1') +; + +INSERT INTO `prado_system_data_sqlmap`.`dynamicparametertest2` ( + `testname` , + `teststring` , + `testinteger` +) +VALUES +('staticsql', 'staticsql2', '2'), +('dynamictable', 'dynamictableparametertest2', '2') +; diff --git a/tests/unit/Data/SqlMap/fixtures/mysql5_setup.sql b/tests/unit/Data/SqlMap/fixtures/mysql5_setup.sql new file mode 100644 index 00000000..753b48ac --- /dev/null +++ b/tests/unit/Data/SqlMap/fixtures/mysql5_setup.sql @@ -0,0 +1,22 @@ +CREATE DATABASE `prado_system_data_sqlmap` + DEFAULT CHARACTER SET utf8 + COLLATE utf8_general_ci; + +GRANT ALL ON `prado_system_data_sqlmap`.* + TO 'prado_unitest'@'localhost' + IDENTIFIED BY 'prado_system_data_sqlmap_unitest'; + +DROP TABLE IF EXISTS `dynamicparametertest1`; +CREATE TABLE `dynamicparametertest1` ( + `testname` varchar(50) NOT NULL, + `teststring` varchar(50) NOT NULL, + `testinteger` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +DROP TABLE IF EXISTS `dynamicparametertest2`; +CREATE TABLE `dynamicparametertest2` ( + `testname` varchar(50) NOT NULL, + `teststring` varchar(50) NOT NULL, + `testinteger` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + -- cgit v1.2.3