Merge pull request #579 from xmujay/fixUT

fix UT error and add UT for PMA_server_privileges
This commit is contained in:
Marc Delisle 2013-08-09 08:23:43 -07:00
commit db39b07d95
2 changed files with 140 additions and 13 deletions

View File

@ -0,0 +1,112 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for server_privileges.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/Util.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/js_escape.lib.php';
require_once 'libraries/server_privileges.lib.php';
/**
* PMA_ServerPrivileges_Test class
*
* this class is for testing server_privileges.lib.php functions
*
* @package PhpMyAdmin-test
*/
class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
{
/**
* Prepares environment for the test.
*
* @return void
*/
public function setUp()
{
//$_REQUEST
$_REQUEST['log'] = "index1";
$_REQUEST['pos'] = 3;
//$GLOBALS
$GLOBALS['cfg']['MaxRows'] = 10;
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['RememberSorting'] = true;
$GLOBALS['cfg']['SQP'] = array();
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
$GLOBALS['cfg']['ShowSQL'] = true;
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
$GLOBALS['cfg']['LimitChars'] = 100;
$GLOBALS['cfg']['DBG']['sql'] = false;
$GLOBALS['table'] = "table";
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
$GLOBALS['pmaThemeImage'] = 'image';
$GLOBALS['server'] = 1;
//$_POST
$_POST['pred_password'] = 'none';
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
//Mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
}
/**
* Test for PMA_getSqlQueriesForDisplayAndAddUser
*
* @return void
*/
public function testPMAGetSqlQueriesForDisplayAndAddUser()
{
$username = "PMA_username";
$hostname = "PMA_hostname";
$password = "PMA_password";
list($create_user_real, $create_user_show, $real_sql_query, $sql_query)
= PMA_getSqlQueriesForDisplayAndAddUser($username, $hostname, $password);
//validate 1: $create_user_real
$this->assertEquals(
"CREATE USER 'PMA_username'@'PMA_hostname';",
$create_user_real
);
//validate 2: $create_user_show
$this->assertEquals(
"CREATE USER 'PMA_username'@'PMA_hostname';",
$create_user_show
);
//validate 3:$real_sql_query
$this->assertEquals(
"GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname';",
$real_sql_query
);
//validate 4:$sql_query
$this->assertEquals(
"GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname';",
$sql_query
);
}
}

View File

@ -63,9 +63,10 @@ class PMA_ServerUserGroupsTest extends PHPUnit_Framework_TestCase
'<table id="userGroupsTable">',
$html
);
$url_tag = '<a href="server_user_groups.php'
. PMA_URL_getCommon(array('addUserGroup' => 1));
$this->assertContains(
'<a href="server_user_groups.php?'
. PMA_URL_getCommon() . '&addUserGroup=1">',
$url_tag,
$html
);
}
@ -97,7 +98,7 @@ class PMA_ServerUserGroupsTest extends PHPUnit_Framework_TestCase
->will(
$this->returnValue(
array(
'usergroup' => 'usergroup<',
'usergroup' => 'usergroup',
'server_sql' => 'Y',
'server_databases' => 'N',
'db_sql' => 'Y',
@ -117,25 +118,39 @@ class PMA_ServerUserGroupsTest extends PHPUnit_Framework_TestCase
$html = PMA_getHtmlForUserGroupsTable();
$this->assertContains(
'<td>usergroup&lt;</td>',
'<td>usergroup</td>',
$html
);
$url_tag = '<a class="" href="server_user_groups.php?'
. PMA_URL_getCommon(
array(
'viewUsers'=>1, 'userGroup'=>htmlspecialchars('usergroup')
)
);
$this->assertContains(
'<a class="" href="server_user_groups.php?'
. PMA_URL_getCommon() . '&viewUsers=1&userGroup='
. urlencode('usergroup<') . '">',
$url_tag,
$html
);
$url_tag = '<a class="" href="server_user_groups.php?'
. PMA_URL_getCommon(
array(
'editUserGroup'=>1,
'userGroup'=>htmlspecialchars('usergroup')
)
);
$this->assertContains(
'<a class="" href="server_user_groups.php?'
. PMA_URL_getCommon() . '&editUserGroup=1&userGroup='
. urlencode('usergroup<') . '">',
$url_tag,
$html
);
$url_tag = '<a class="deleteUserGroup ajax" href="server_user_groups.php?'
. PMA_URL_getCommon(
array(
'deleteUserGroup'=> 1,
'userGroup'=>htmlspecialchars('usergroup')
)
);
$this->assertContains(
'<a class="deleteUserGroup ajax" href="server_user_groups.php?'
. PMA_URL_getCommon() . '&deleteUserGroup=1&userGroup='
. urlencode('usergroup<') . '">',
$url_tag,
$html
);
}