diff --git a/test/libraries/PMA_SQL_parser_test.php b/test/libraries/PMA_SQL_parser_test.php index f8a78ceb4a..65e834156c 100644 --- a/test/libraries/PMA_SQL_parser_test.php +++ b/test/libraries/PMA_SQL_parser_test.php @@ -10,6 +10,7 @@ * Include to test. */ require_once 'libraries/sqlparser.lib.php'; +require_once 'libraries/sqlparser.data.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Message.class.php'; require_once 'libraries/Util.class.php'; @@ -52,7 +53,17 @@ class PMA_SQLParser_Test extends PHPUnit_Framework_TestCase $this->assertEquals('', PMA_SQP_getErrorString()); $this->assertEquals($expected, $parsed_sql); } - + + public function testPMA_SQP_isKeyWord() + { + PMA_SQP_resetError(); + $this->assertTrue(PMA_SQP_isKeyWord("ACCESSIBLE")); + $this->assertTrue(PMA_SQP_isKeyWord("accessible")); + $this->assertTrue(PMA_SQP_isKeyWord("ASC")); + $this->assertFalse(PMA_SQP_isKeyWord("hello")); + } + + /** * Data provider for parser testing * diff --git a/test/libraries/PMA_SQL_validator_test.php b/test/libraries/PMA_SQL_validator_test.php new file mode 100644 index 0000000000..b41f012274 --- /dev/null +++ b/test/libraries/PMA_SQL_validator_test.php @@ -0,0 +1,141 @@ +assertEquals( + '', + PMA_validateSQL($sql) + ); + + //$cfg['SQLValidator']['use'] = true + $GLOBALS['cfg']['SQLValidator']['use'] = true; + + //the sql validatior is not loaded + $GLOBALS['sqlvalidator_error'] = true; + $this->assertContains( + 'The SQL validator could not be initialized.', + PMA_validateSQL($sql) + ); + } + + /** + * Tests for PMA_validateSQL SOAP + * + * @return void + */ + public function testPMA_validateSQL_SOAP() + { + $sql_pass = "select * from PMA_test"; + $sql_fail = "select * PMA_test"; + + //the sql validatior is loaded correctly + //follow need SOAP + $GLOBALS['cfg']['SQLValidator']['use'] = true; + $GLOBALS['sqlvalidator_soap'] = 'PEAR'; + $GLOBALS['sqlvalidator_error'] = false; + + //validate that the result is the same as SOAP_Client return + //SOAP_Client is mocked with simple logic + $this->assertTrue( + PMA_validateSQL($sql_pass) + ); + $this->assertFalse( + PMA_validateSQL($sql_fail) + ); + } +} + +//Mock the SOAP_Client +class SOAP_Client +{ + public function call($name, $arguments) + { + return $this->{$name}($arguments); + } + public function openSession($args) + { + $session = new Session; + $session->target = "http://sqlvalidator.mimer.com/v1/services"; + $session->username = $args["a_userName"]; + $session->password = $args["a_password"]; + $session->calling_program = $args["a_callingProgram"]; + $session->sessionId = "sessionId"; + $session->sessionKey = "sessionKey"; + return $session; + } + public function validateSQL($args) + { + $session = new Session; + $sql = $args["a_SQL"]; + //simple logic of sql validate + $pos = strstr($sql, "from"); + if (!$pos) { + $session->data = false; + } else { + $session->data = true; + } + return $session; + } +} + +//Mock return Session class +class Session +{ + var $target = null; + var $username = null; + var $password = null; + var $calling_program = null; + var $sessionId = null; + var $sessionKey = null; + var $data = null; +} + +?>