diff --git a/test/libraries/PMA_server_privileges_test.php b/test/libraries/PMA_server_privileges_test.php index dd41e1bac9..13642f4340 100644 --- a/test/libraries/PMA_server_privileges_test.php +++ b/test/libraries/PMA_server_privileges_test.php @@ -102,7 +102,11 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ) ); - $fetchSingleRow = array('password' => 'pma_password'); + $fetchSingleRow = array( + 'password' => 'pma_password', + 'Table_priv' => 'pri1, pri2', + 'Type' => 'Type', + ); $dbi->expects($this->any())->method('fetchSingleRow') ->will($this->returnValue($fetchSingleRow)); @@ -228,6 +232,41 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ); } + /** + * Test for PMA_getTableGrantsArray + * + * @return void + */ + public function testPMAGetTableGrantsArray() + { + $GLOBALS['strPrivDescDelete'] = "strPrivDescDelete"; + $GLOBALS['strPrivDescCreateTbl'] = "strPrivDescCreateTbl"; + $GLOBALS['strPrivDescDropTbl'] = "strPrivDescDropTbl"; + $GLOBALS['strPrivDescIndex'] = "strPrivDescIndex"; + $GLOBALS['strPrivDescAlter'] = "strPrivDescAlter"; + $GLOBALS['strPrivDescCreateView'] = "strPrivDescCreateView"; + $GLOBALS['strPrivDescShowView'] = "strPrivDescShowView"; + $GLOBALS['strPrivDescTrigger'] = "strPrivDescTrigger"; + + $ret = PMA_getTableGrantsArray(); + $this->assertEquals( + array( + 'Delete', + 'DELETE', + $GLOBALS['strPrivDescDelete'] + ), + $ret[0] + ); + $this->assertEquals( + array( + 'Create', + 'CREATE', + $GLOBALS['strPrivDescCreateTbl'] + ), + $ret[1] + ); + } + /** * Test for PMA_getGrantsArray * @@ -616,6 +655,8 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $_POST['pred_username'] = 'any'; $_POST['pred_hostname'] = 'localhost'; $_REQUEST['createdb-3'] = true; + $_REQUEST['userGroup'] = "username"; + list( $ret_message, $ret_queries, $queries_for_display, $sql_query, @@ -739,6 +780,139 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ); } + /** + * Test for PMA_getHtmlToDisplayPrivilegesTable + * + * @return void + */ + public function testPMAGetHtmlToDisplayPrivilegesTable() + { + $dbi_old = $GLOBALS['dbi']; + $GLOBALS['hostname'] = "hostname"; + $GLOBALS['username'] = "username"; + + //Mock DBI + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fetchSingleRow = array( + 'password' => 'pma_password', + 'max_questions' => 'max_questions', + 'max_updates' => 'max_updates', + 'max_connections' => 'max_connections', + 'max_user_connections' => 'max_user_connections', + 'Table_priv' => 'Select,Insert,Update,Delete,File,Create,Alter,Index,' + . 'Drop,Super,Process,Reload,Shutdown,Create_routine,Alter_routine,' + . 'Show_db,Repl_slave,Create_tmp_table,Show_view,Execute,' + . 'Repl_client,Lock_tables,References,Grant,dd' + . 'Create_user,Repl_slave,Repl_client', + 'Type' => "'Super1','Select','Insert','Update','Create','Alter','Index'," + . "'Drop','Delete','File','Super','Process','Reload','Shutdown','" + . "Show_db','Repl_slave','Create_tmp_table'," + . "'Show_view','Create_routine','" + . "Repl_client','Lock_tables','References','Alter_routine','" + . "Create_user','Repl_slave','Repl_client','Execute','Grant','ddd", + ); + $dbi->expects($this->any())->method('fetchSingleRow') + ->will($this->returnValue($fetchSingleRow)); + + $dbi->expects($this->any())->method('tryQuery') + ->will($this->returnValue(true)); + + $columns = array('val1', 'replace1', 5); + $dbi->expects($this->at(0)) + ->method('fetchRow') + ->will($this->returnValue($columns)); + $dbi->expects($this->at(1)) + ->method('fetchRow') + ->will($this->returnValue(false)); + + $GLOBALS['dbi'] = $dbi; + + $html = PMA_getHtmlToDisplayPrivilegesTable(); + $GLOBALS['username'] = "username"; + + //validate 1: fieldset + $this->assertContains( + '