From 2b4d9549685e58482346c30955f89e438a5d8a33 Mon Sep 17 00:00:00 2001 From: Tomasz Narloch Date: Thu, 2 Feb 2017 21:55:37 +0100 Subject: [PATCH] Add missing tests for quoteName --- .../driver/mysql/JDatabaseDriverMysqlTest.php | 37 +++++++++++++++++++ .../mysqli/JDatabaseDriverMysqliTest.php | 37 +++++++++++++++++++ .../pdomysql/JDatabaseDriverPdomysqlTest.php | 37 +++++++++++++++++++ .../JDatabaseDriverPostgresqlTest.php | 4 ++ .../sqlsrv/JDatabaseDriverSqlsrvTest.php | 37 +++++++++++++++++++ 5 files changed, 152 insertions(+) diff --git a/tests/unit/suites/database/driver/mysql/JDatabaseDriverMysqlTest.php b/tests/unit/suites/database/driver/mysql/JDatabaseDriverMysqlTest.php index 6c8a4710765f8..0a20a28fede89 100644 --- a/tests/unit/suites/database/driver/mysql/JDatabaseDriverMysqlTest.php +++ b/tests/unit/suites/database/driver/mysql/JDatabaseDriverMysqlTest.php @@ -31,6 +31,22 @@ public function dataTestEscape() ); } + /** + * Data for the testQuoteName test. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function dataTestQuoteName() + { + return array( + array('protected`title', null, '`protected``title`'), + array('protected"title', null, '`protected"title`'), + array('protected]title', null, '`protected]title`'), + ); + } + /** * Data for the testTransactionRollback test. * @@ -126,6 +142,27 @@ public function testEscape($text, $extra, $expected) $this->assertSame($expected, self::$driver->escape($text, $extra), 'The string was not escaped properly'); } + /** + * Test the quoteName method. + * + * @param string $text The column name or alias to be quote. + * @param string $asPart String used for AS query part. + * @param string $expected The expected result. + * + * @return void + * + * @dataProvider dataTestQuoteName + * @since __DEPLOY_VERSION__ + */ + public function testQuoteName($text, $asPart, $expected) + { + $this->assertThat( + self::$driver->quoteName($text, $asPart), + $this->equalTo($expected), + 'The name was not quoted properly' + ); + } + /** * Test getAffectedRows method. * diff --git a/tests/unit/suites/database/driver/mysqli/JDatabaseDriverMysqliTest.php b/tests/unit/suites/database/driver/mysqli/JDatabaseDriverMysqliTest.php index 805a956da6a3e..1b7f86a5013b5 100644 --- a/tests/unit/suites/database/driver/mysqli/JDatabaseDriverMysqliTest.php +++ b/tests/unit/suites/database/driver/mysqli/JDatabaseDriverMysqliTest.php @@ -31,6 +31,22 @@ public function dataTestEscape() ); } + /** + * Data for the testQuoteName test. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function dataTestQuoteName() + { + return array( + array('protected`title', null, '`protected``title`'), + array('protected"title', null, '`protected"title`'), + array('protected]title', null, '`protected]title`'), + ); + } + /** * Data for the testTransactionRollback test. * @@ -126,6 +142,27 @@ public function testEscape($text, $extra, $expected) $this->assertThat(self::$driver->escape($text, $extra), $this->equalTo($expected), 'The string was not escaped properly'); } + /** + * Test the quoteName method. + * + * @param string $text The column name or alias to be quote. + * @param string $asPart String used for AS query part. + * @param string $expected The expected result. + * + * @return void + * + * @dataProvider dataTestQuoteName + * @since __DEPLOY_VERSION__ + */ + public function testQuoteName($text, $asPart, $expected) + { + $this->assertThat( + self::$driver->quoteName($text, $asPart), + $this->equalTo($expected), + 'The name was not quoted properly' + ); + } + /** * Test getAffectedRows method. * diff --git a/tests/unit/suites/database/driver/pdomysql/JDatabaseDriverPdomysqlTest.php b/tests/unit/suites/database/driver/pdomysql/JDatabaseDriverPdomysqlTest.php index b29ec0c70ce50..b1ed7bab2b9b0 100644 --- a/tests/unit/suites/database/driver/pdomysql/JDatabaseDriverPdomysqlTest.php +++ b/tests/unit/suites/database/driver/pdomysql/JDatabaseDriverPdomysqlTest.php @@ -31,6 +31,22 @@ public function dataTestEscape() ); } + /** + * Data for the testQuoteName test. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function dataTestQuoteName() + { + return array( + array('protected`title', null, '`protected``title`'), + array('protected"title', null, '`protected"title`'), + array('protected]title', null, '`protected]title`'), + ); + } + /** * Data for the testTransactionRollback test. * @@ -115,6 +131,27 @@ public function testEscape($text, $extra, $expected) ); } + /** + * Test the quoteName method. + * + * @param string $text The column name or alias to be quote. + * @param string $asPart String used for AS query part. + * @param string $expected The expected result. + * + * @return void + * + * @dataProvider dataTestQuoteName + * @since __DEPLOY_VERSION__ + */ + public function testQuoteName($text, $asPart, $expected) + { + $this->assertThat( + self::$driver->quoteName($text, $asPart), + $this->equalTo($expected), + 'The name was not quoted properly' + ); + } + /** * Test getAffectedRows method. * diff --git a/tests/unit/suites/database/driver/postgresql/JDatabaseDriverPostgresqlTest.php b/tests/unit/suites/database/driver/postgresql/JDatabaseDriverPostgresqlTest.php index cee9f0ee3e3f0..81e54da4be74a 100644 --- a/tests/unit/suites/database/driver/postgresql/JDatabaseDriverPostgresqlTest.php +++ b/tests/unit/suites/database/driver/postgresql/JDatabaseDriverPostgresqlTest.php @@ -111,6 +111,10 @@ public function dataTestReplacePrefix() public function dataTestQuoteName() { return array( + /* test escape double quote */ + array('protected`title', null, '"protected`title"'), + array('protected"title', null, '"protected""title"'), + array('protected]title', null, '"protected]title"'), /* no dot inside var */ array('jos_dbtest', null, '"jos_dbtest"'), /* a dot inside var */ diff --git a/tests/unit/suites/database/driver/sqlsrv/JDatabaseDriverSqlsrvTest.php b/tests/unit/suites/database/driver/sqlsrv/JDatabaseDriverSqlsrvTest.php index cec51d10f03ab..e5cd846b1e491 100644 --- a/tests/unit/suites/database/driver/sqlsrv/JDatabaseDriverSqlsrvTest.php +++ b/tests/unit/suites/database/driver/sqlsrv/JDatabaseDriverSqlsrvTest.php @@ -30,6 +30,22 @@ public function dataTestEscape() ); } + /** + * Data for the testQuoteName test. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function dataTestQuoteName() + { + return array( + array('protected`title', null, '[protected`title]'), + array('protected"title', null, '[protected"title]'), + array('protected]title', null, '[protected]]title]'), + ); + } + /** * Tests the dropTable method. * @@ -67,6 +83,27 @@ public function testEscape($text, $extra, $expected) ); } + /** + * Test the quoteName method. + * + * @param string $text The column name or alias to be quote. + * @param string $asPart String used for AS query part. + * @param string $expected The expected result. + * + * @return void + * + * @dataProvider dataTestQuoteName + * @since __DEPLOY_VERSION__ + */ + public function testQuoteName($text, $asPart, $expected) + { + $this->assertThat( + self::$driver->quoteName($text, $asPart), + $this->equalTo($expected), + 'The name was not quoted properly' + ); + } + /** * Tests the getAffectedRows method *