add test case for SQL parser/validator #481

Merged
merged 6 commits into from Jul 9, 2013

Projects

None yet

2 participants

@adamgsoc2013
Contributor

No description provided.

@nijel nijel commented on an outdated diff Jul 8, 2013
test/libraries/PMA_SQL_parser_test.php
@@ -52,7 +53,17 @@ public function testParser($sql, $expected, $error = '')
$this->assertEquals('', PMA_SQP_getErrorString());
$this->assertEquals($expected, $parsed_sql);
}
-
+
+ public function testPMA_SQP_isKeyWord()
+ {
+ PMA_SQP_resetError();
+ $this->assertEquals(true, PMA_SQP_isKeyWord("ACCESSIBLE"));
+ $this->assertEquals(true, PMA_SQP_isKeyWord("accessible"));
+ $this->assertEquals(true, PMA_SQP_isKeyWord("ASC"));
+ $this->assertEquals(false, PMA_SQP_isKeyWord("hello"));
@nijel
nijel Jul 8, 2013 Member

For readibility, I'd rather use assertTrue/assertFalse here.

@nijel nijel commented on an outdated diff Jul 8, 2013
test/libraries/PMA_SQL_validator_test.php
@@ -0,0 +1,60 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Tests for correctness of SQL validator
+ *
+ * @package PhpMyAdmin-test
+ */
+
+/*
+ * Include to test.
+ */
+define('PMA_MYSQL_STR_VERSION', "PMA_MYSQL_STR_VERSION");
@nijel
nijel Jul 8, 2013 Member

This really does not look like MySQL version string...

@nijel nijel commented on an outdated diff Jul 8, 2013
test/libraries/PMA_SQL_validator_test.php
+ $GLOBALS['cfg']['SQLValidator']['username'] = "PMA_username";
+ $GLOBALS['cfg']['SQLValidator']['password'] = "PMA_password";
+ }
+
+ public function testPMA_validateSQL()
+ {
+ $sql = "select * from PMA_test";
+ $this->assertEquals(
+ '',
+ PMA_validateSQL($sql)
+ );
+
+ $GLOBALS['cfg']['SQLValidator']['use'] = true;
+ $GLOBALS['sqlvalidator_error'] = true;
+ $this->assertContains(
+ 'The SQL validator could not be initialized.',
@nijel
nijel Jul 8, 2013 Member

Does it really makes sense to test that validator is not working?

@adamgsoc2013
Contributor

Hi Marc, I have fixed the issues you mentioned. the test of PMA_SQL_validator still needs more works. the remaining case is "the sql validatior is loaded correctly", I will follow up, thanks

@adamgsoc2013
Contributor

I will pull another request when I fix the problem about SOAP for PMA_SQL_validator "SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://sqlvalidator.mim"

@adamgsoc2013 adamgsoc2013 commented on an outdated diff Jul 8, 2013
test/libraries/PMA_SQL_validator_test.php
+ 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)
+ );
+
+ //the sql validatior is loaded correctly
+ //TODO: follow need SOAP
+ $GLOBALS['sqlvalidator_soap'] = 'PHP';
@adamgsoc2013
adamgsoc2013 Jul 8, 2013 Contributor

follow here, I will cover the SOAP start service. but still some problem to fix
https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/sqlvalidator.class.php#L371

@adamgsoc2013
Contributor

Hi Michal, I mock a Class SOAP_Client. and fake a simple logic about validate SQL.
https://github.com/phpmyadmin/phpmyadmin/pull/481/files#L1R97

I think the Unit test for PMA_SQL_validator is not doing the validation actual, but validate that call the SOAP_Client correctly.

so the case are cover the purpose. thanks

@adamgsoc2013
Contributor

the validate work is in SOAP_Client web service. it should be a black box for our class. thanks

@adamgsoc2013 adamgsoc2013 commented on the diff Jul 9, 2013
test/libraries/PMA_SQL_validator_test.php
+ */
+ 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)
@adamgsoc2013
adamgsoc2013 Jul 9, 2013 Contributor

validate the result is same as the Web service (Mock) result. https://github.com/phpmyadmin/phpmyadmin/pull/481/files#L1R118

@nijel nijel merged commit 476cd59 into phpmyadmin:master Jul 9, 2013

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment