From 607a0393d8952ef50c2694594a56ee933cbbf3b2 Mon Sep 17 00:00:00 2001 From: xmujay Date: Thu, 5 Sep 2013 20:32:07 +0800 Subject: [PATCH] UTs for PMA_server_privileges --- test/libraries/PMA_server_privileges_test.php | 162 +++++++++++++++++- 1 file changed, 161 insertions(+), 1 deletion(-) diff --git a/test/libraries/PMA_server_privileges_test.php b/test/libraries/PMA_server_privileges_test.php index 0e27d21de4..911594618f 100644 --- a/test/libraries/PMA_server_privileges_test.php +++ b/test/libraries/PMA_server_privileges_test.php @@ -22,7 +22,7 @@ require_once 'libraries/Message.class.php'; require_once 'libraries/Response.class.php'; require_once 'libraries/relation.lib.php'; require_once 'libraries/server_privileges.lib.php'; - +define("PMA_USR_BROWSER_AGENT", 1); /** * PMA_ServerPrivileges_Test class * @@ -57,12 +57,22 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb'; $GLOBALS['cfg']['Server']['usergroups'] = 'usergroups'; $GLOBALS['cfg']['Server']['users'] = 'users'; + $GLOBALS['cfg']['ActionLinksMode'] = "both"; + $GLOBALS['cfg']['DefaultTabDatabase'] = 'db_structure.php'; + $GLOBALS['cfg']['QueryWindowHeight'] = 100; + $GLOBALS['cfg']['QueryWindowWidth'] = 100; + $GLOBALS['cfg']['PmaAbsoluteUri'] = "PmaAbsoluteUri"; + $GLOBALS['cfg']['DefaultTabTable'] = "db_structure.php"; + $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = "db_structure.php"; + $GLOBALS['cfg']['Confirm'] = "Confirm"; $GLOBALS['table'] = "table"; $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF'); $GLOBALS['pmaThemeImage'] = 'image'; $GLOBALS['server'] = 1; $GLOBALS['username'] = "pma_username"; + $GLOBALS['collation_connection'] = "collation_connection"; + $GLOBALS['text_dir'] = "text_dir"; //$_POST $_POST['pred_password'] = 'none'; @@ -70,6 +80,12 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme'); $_SESSION['PMA_Theme'] = new PMA_Theme(); + $pmaconfig = $this->getMockBuilder('PMA_Config') + ->disableOriginalConstructor() + ->getMock(); + + $GLOBALS['PMA_Config'] = $pmaconfig; + //Mock DBI $dbi = $this->getMockBuilder('PMA_DatabaseInterface') ->disableOriginalConstructor() @@ -294,6 +310,38 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase } + /** + * Test for PMA_getHtmlForUserGroupDialog + * + * @return void + */ + public function testPMAGetHtmlForUserGroupDialog() + { + $username = "pma_username"; + $is_menuswork = true; + $_REQUEST['edit_user_group_dialog'] = "edit_user_group_dialog"; + $GLOBALS['is_ajax_request'] = false; + + //PMA_getHtmlForUserGroupDialog + $html = PMA_getHtmlForUserGroupDialog($username, $is_menuswork); + $this->assertContains( + '
$username); + $html_output = PMA_URL_getHiddenInputs($params); + $this->assertContains( + $html_output, + $html + ); + //__('User group') + $this->assertContains( + __('User group'), + $html + ); + } + /** * Test for PMA_getHtmlToChooseUserGroup * @@ -323,6 +371,118 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ); } + /** + * Test for PMA_getHtmlForDisplayResourceLimits + * + * @return void + */ + public function testPMAGetHtmlForDisplayResourceLimits() + { + $row = array( + 'max_questions' => 'max_questions', + 'max_updates' => 'max_updates', + 'max_connections' => 'max_connections', + 'max_user_connections' => 'max_user_connections', + ); + + //PMA_getHtmlForDisplayResourceLimits + $html = PMA_getHtmlForDisplayResourceLimits($row); + $this->assertContains( + '' . __('Resource limits') . '', + $html + ); + $this->assertContains( + __('Note: Setting these options to 0 (zero) removes the limit.'), + $html + ); + $this->assertContains( + 'MAX QUERIES PER HOUR', + $html + ); + $this->assertContains( + $row['max_connections'], + $html + ); + $this->assertContains( + $row['max_updates'], + $html + ); + $this->assertContains( + $row['max_connections'], + $html + ); + $this->assertContains( + $row['max_user_connections'], + $html + ); + $this->assertContains( + __('Limits the number of simultaneous connections the user may have.'), + $html + ); + $this->assertContains( + __('Limits the number of simultaneous connections the user may have.'), + $html + ); + } + + /** + * Test for PMA_getSqlQueryForDisplayPrivTable + * + * @return void + */ + public function testPMAGetSqlQueryForDisplayPrivTable() + { + $username = "pma_username"; + $db = '*'; + $table = "pma_table"; + $hostname = "pma_hostname"; + + //$db == '*' + $ret = PMA_getSqlQueryForDisplayPrivTable( + $db, $table, $username, $hostname + ); + $sql = "SELECT * FROM `mysql`.`user`" + ." WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'" + ." AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "';"; + $this->assertEquals( + $sql, + $ret + ); + + //$table == '*' + $db = "pma_db"; + $table = "*"; + $ret = PMA_getSqlQueryForDisplayPrivTable( + $db, $table, $username, $hostname + ); + $sql = "SELECT * FROM `mysql`.`db`" + ." WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'" + ." AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "'" + ." AND '" . PMA_Util::unescapeMysqlWildcards($db) . "'" + ." LIKE `Db`;"; + $this->assertEquals( + $sql, + $ret + ); + + //$table == 'pma_table' + $db = "pma_db"; + $table = "pma_table"; + $ret = PMA_getSqlQueryForDisplayPrivTable( + $db, $table, $username, $hostname + ); + $sql = "SELECT `Table_priv`" + ." FROM `mysql`.`tables_priv`" + ." WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'" + ." AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "'" + ." AND `Db` = '" . PMA_Util::unescapeMysqlWildcards($db) . "'" + ." AND `Table_name` = '" . PMA_Util::sqlAddSlashes($table) . "';"; + $this->assertEquals( + $sql, + $ret + ); + } + /** * Test for PMA_getDataForChangeOrCopyUser *