Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Runkit testing for DBIMysqli #610

Merged
merged 1 commit into from

2 participants

adamgsoc2013 Michal Čihař
adamgsoc2013

No description provided.

Michal Čihař nijel merged commit a142cb5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 18, 2013
  1. adamgsoc2013
This page is out of date. Refresh to see the latest.
Showing with 193 additions and 15 deletions.
  1. +36 −0 test/classes/dbi/DBIMysql_test.php
  2. +157 −15 test/classes/dbi/DBIMysqli_test.php
36 test/classes/dbi/DBIMysql_test.php
View
@@ -95,7 +95,43 @@ public function testMysqlDBI()
runkit_function_redefine('mysql_field_flags','','return "mysql_field_flags";');
runkit_function_redefine('mysql_field_name','','return "mysql_field_name";');
runkit_function_redefine('mysql_field_len','','return "mysql_field_len";');
+ runkit_function_redefine('mysql_num_fields','','return "mysql_num_fields";');
+ runkit_function_redefine('mysql_affected_rows','','return "mysql_affected_rows";');
+ //test for fieldFlags
+ $result = array("table1", "table2");
+ $ret = $this->object->numFields($result);
+ $this->assertEquals(
+ 'mysql_num_fields',
+ $ret
+ );
+
+ //test for fetchRow
+ $result = array("table1", "table2");
+ $ret = $this->object->fetchRow($result);
+ $this->assertEquals(
+ 'mysql_fetch_array',
+ $ret
+ );
+
+ //test for fetchRow
+ $result = array("table1", "table2");
+ $ret = $this->object->fetchAssoc($result);
+ $this->assertEquals(
+ 'mysql_fetch_array',
+ $ret
+ );
+
+ //test for affectedRows
+ $link = "PMA_link";
+ $get_from_cache = false;
+ $ret = $this->object->affectedRows($link, $get_from_cache);
+ $this->assertEquals(
+ "mysql_affected_rows",
+ $ret
+ );
+
+ //test for connect
$user = 'PMA_user';
$password = 'PMA_password';
$is_controluser = false;
172 test/classes/dbi/DBIMysqli_test.php
View
@@ -16,6 +16,7 @@
require_once 'libraries/Index.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/dbi/DBIMysqli.class.php';
+require_once 'libraries/Theme.class.php';
/**
* Tests for PMA_DBI_Mysqli class
@@ -37,8 +38,25 @@ class PMA_DBI_Mysqli_Test extends PHPUnit_Framework_TestCase
* @return void
*/
protected function setUp()
- {
+ {
+ $GLOBALS['cfg']['Server']['ssl'] = true;
+ $GLOBALS['cfg']['PersistentConnections'] = false;
+ $GLOBALS['cfg']['Server']['compress'] = true;
+ $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
+ $GLOBALS['cfg']['ActionLinksMode'] = "both";
+ $GLOBALS['pmaThemeImage'] = 'image';
+
+ //$_SESSION
+ $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
+ $_SESSION['PMA_Theme'] = new PMA_Theme();
$this->object = new PMA_DBI_Mysqli();
+
+ //Mock DBI, just for postConnect usage
+ $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $GLOBALS['dbi'] = $dbi;
}
/**
@@ -52,37 +70,161 @@ protected function tearDown()
{
unset($this->object);
}
-
+
/**
- * Test for selectDb
+ * Test for mysqli related functions, using runkit_function_redefine
*
* @return void
*
* @group medium
*/
- public function testSelectDb()
+ public function testMysqliDBI()
{
- //$link is empty
- $GLOBALS['userlink'] = null;
+ if (! PMA_HAS_RUNKIT) {
+ $this->markTestSkipped("Cannot redefine function");
+ }
+
+ //FOR UT, we just test the right mysql client API is called
+ runkit_function_redefine('mysqli_real_connect','','return "mysqli_real_connect";');
+ runkit_function_redefine('mysqli_init','','return "mysqli_init";');
+ runkit_function_redefine('mysqli_options','','return "mysqli_options";');
+ runkit_function_redefine('mysqli_query','','return "mysqli_query";');
+ runkit_function_redefine('mysqli_multi_query','','return "mysqli_multi_query";');
+ runkit_function_redefine('mysqli_fetch_array','','return "mysqli_fetch_array";');
+ runkit_function_redefine('mysqli_data_seek','','return "mysqli_data_seek";');
+ runkit_function_redefine('mysqli_more_results','','return "mysqli_more_results";');
+ runkit_function_redefine('mysqli_next_result','','return "mysqli_next_result";');
+ runkit_function_redefine('mysqli_get_host_info','','return "mysqli_get_host_info";');
+ runkit_function_redefine('mysqli_get_proto_info','','return "mysqli_get_proto_info";');
+ runkit_function_redefine('mysqli_get_client_info','','return "mysqli_get_client_info";');
+
+ $user = 'PMA_user';
+ $password = 'PMA_password';
+ $is_controluser = false;
+ $server = array(
+ 'port' => 8080,
+ 'socket' => 123,
+ 'host' => 'locahost',
+ );
+ $auxiliary_connection = true;
+
+ //test for connect
+ $ret = $this->object->connect(
+ $user, $password, $is_controluser,
+ $server, $auxiliary_connection
+ );
$this->assertEquals(
- false,
- $this->object->selectDb("PMA")
- );
- }
+ 'mysqli_init',
+ $ret
+ );
+
+ //test for realQuery
+ $query = 'select * from DBI';
+ $link = $ret;
+ $options = 0;
+ $ret = $this->object->realQuery($query, $link, $options);
+ $this->assertEquals(
+ 'mysqli_query',
+ $ret
+ );
+
+ //test for realMultiQuery
+ $result = $ret;
+ $ret = $this->object->realMultiQuery($link, $query);
+ $this->assertEquals(
+ 'mysqli_multi_query',
+ $ret
+ );
+
+ //test for fetchArray
+ $result = $ret;
+ $ret = $this->object->fetchArray($result);
+ $this->assertEquals(
+ 'mysqli_fetch_array',
+ $ret
+ );
+
+ //test for fetchAssoc
+ $result = $ret;
+ $ret = $this->object->fetchAssoc($result);
+ $this->assertEquals(
+ 'mysqli_fetch_array',
+ $ret
+ );
+ //test for fetchRow
+ $result = $ret;
+ $ret = $this->object->fetchRow($result);
+ $this->assertEquals(
+ 'mysqli_fetch_array',
+ $ret
+ );
+
+ //test for dataSeek
+ $result = $ret;
+ $offset = 10;
+ $ret = $this->object->dataSeek($result, $offset);
+ $this->assertEquals(
+ 'mysqli_data_seek',
+ $ret
+ );
+
+ //test for moreResults
+ $link = $ret;
+ $ret = $this->object->moreResults($link);
+ $this->assertEquals(
+ 'mysqli_more_results',
+ $ret
+ );
+
+ //test for nextResult
+ $link = $ret;
+ $ret = $this->object->nextResult($link);
+ $this->assertEquals(
+ 'mysqli_next_result',
+ $ret
+ );
+
+ //test for getHostInfo
+ $link = $ret;
+ $ret = $this->object->getHostInfo($link);
+ $this->assertEquals(
+ 'mysqli_get_host_info',
+ $ret
+ );
+
+ //test for getProtoInfo
+ $link = $ret;
+ $ret = $this->object->getProtoInfo($link);
+ $this->assertEquals(
+ 'mysqli_get_proto_info',
+ $ret
+ );
+
+ //test for getClientInfo
+ $link = $ret;
+ $ret = $this->object->getClientInfo();
+ $this->assertEquals(
+ 'mysqli_get_client_info',
+ $ret
+ );
+ }
+
/**
- * Test for getClientInfo
+ * Test for selectDb
*
* @return void
*
* @group medium
*/
- public function testGetClientInfo()
+ public function testSelectDb()
{
+ //$link is empty
+ $GLOBALS['userlink'] = null;
$this->assertEquals(
- mysql_get_client_info(),
- $this->object->getClientInfo()
- );
+ false,
+ $this->object->selectDb("PMA")
+ );
}
/**
Something went wrong with that request. Please try again.