Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

fix UT error and add UT for PMA_server_privileges #579

Merged
merged 1 commit into from 11 months ago

2 participants

xmujay Marc Delisle
xmujay

No description provided.

xmujay

HI,
this pull request is to fix the existed UT error due to PMA_common_url and add simple case for PMA_server_privileges.

I will send another pull request about refactor of PMA_server_privileges. thanks

Marc Delisle lem9 merged commit db39b07 into from
Marc Delisle lem9 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 09, 2013
xmujay xmujay fix UT error and add UT for PMA_server_privileges d1a70dc
This page is out of date. Refresh to see the latest.
112 test/libraries/PMA_server_privileges_test.php
... ... @@ -0,0 +1,112 @@
  1 +<?php
  2 +/* vim: set expandtab sw=4 ts=4 sts=4: */
  3 +/**
  4 + * tests for server_privileges.lib.php
  5 + *
  6 + * @package PhpMyAdmin-test
  7 + */
  8 +
  9 +/*
  10 + * Include to test.
  11 + */
  12 +require_once 'libraries/Util.class.php';
  13 +require_once 'libraries/php-gettext/gettext.inc';
  14 +require_once 'libraries/url_generating.lib.php';
  15 +require_once 'libraries/Theme.class.php';
  16 +require_once 'libraries/database_interface.inc.php';
  17 +require_once 'libraries/Message.class.php';
  18 +require_once 'libraries/sanitizing.lib.php';
  19 +require_once 'libraries/sqlparser.lib.php';
  20 +require_once 'libraries/js_escape.lib.php';
  21 +require_once 'libraries/server_privileges.lib.php';
  22 +
  23 +/**
  24 + * PMA_ServerPrivileges_Test class
  25 + *
  26 + * this class is for testing server_privileges.lib.php functions
  27 + *
  28 + * @package PhpMyAdmin-test
  29 + */
  30 +class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase
  31 +{
  32 + /**
  33 + * Prepares environment for the test.
  34 + *
  35 + * @return void
  36 + */
  37 + public function setUp()
  38 + {
  39 + //$_REQUEST
  40 + $_REQUEST['log'] = "index1";
  41 + $_REQUEST['pos'] = 3;
  42 +
  43 + //$GLOBALS
  44 + $GLOBALS['cfg']['MaxRows'] = 10;
  45 + $GLOBALS['cfg']['ServerDefault'] = "server";
  46 + $GLOBALS['cfg']['RememberSorting'] = true;
  47 + $GLOBALS['cfg']['SQP'] = array();
  48 + $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
  49 + $GLOBALS['cfg']['ShowSQL'] = true;
  50 + $GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
  51 + $GLOBALS['cfg']['LimitChars'] = 100;
  52 + $GLOBALS['cfg']['DBG']['sql'] = false;
  53 +
  54 + $GLOBALS['table'] = "table";
  55 + $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
  56 + $GLOBALS['pmaThemeImage'] = 'image';
  57 + $GLOBALS['server'] = 1;
  58 +
  59 + //$_POST
  60 + $_POST['pred_password'] = 'none';
  61 + //$_SESSION
  62 + $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
  63 + $_SESSION['PMA_Theme'] = new PMA_Theme();
  64 +
  65 + //Mock DBI
  66 + $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
  67 + ->disableOriginalConstructor()
  68 + ->getMock();
  69 +
  70 + $GLOBALS['dbi'] = $dbi;
  71 + }
  72 +
  73 + /**
  74 + * Test for PMA_getSqlQueriesForDisplayAndAddUser
  75 + *
  76 + * @return void
  77 + */
  78 + public function testPMAGetSqlQueriesForDisplayAndAddUser()
  79 + {
  80 + $username = "PMA_username";
  81 + $hostname = "PMA_hostname";
  82 + $password = "PMA_password";
  83 +
  84 + list($create_user_real, $create_user_show, $real_sql_query, $sql_query)
  85 + = PMA_getSqlQueriesForDisplayAndAddUser($username, $hostname, $password);
  86 +
  87 + //validate 1: $create_user_real
  88 + $this->assertEquals(
  89 + "CREATE USER 'PMA_username'@'PMA_hostname';",
  90 + $create_user_real
  91 + );
  92 +
  93 + //validate 2: $create_user_show
  94 + $this->assertEquals(
  95 + "CREATE USER 'PMA_username'@'PMA_hostname';",
  96 + $create_user_show
  97 + );
  98 +
  99 + //validate 3:$real_sql_query
  100 + $this->assertEquals(
  101 + "GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname';",
  102 + $real_sql_query
  103 + );
  104 +
  105 + //validate 4:$sql_query
  106 + $this->assertEquals(
  107 + "GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname';",
  108 + $sql_query
  109 + );
  110 +
  111 + }
  112 +}
41 test/libraries/PMA_server_user_groups_test.php
@@ -63,9 +63,10 @@ public function testGetHtmlForUserGroupsTableWithNoUserGroups()
63 63 '<table id="userGroupsTable">',
64 64 $html
65 65 );
  66 + $url_tag = '<a href="server_user_groups.php'
  67 + . PMA_URL_getCommon(array('addUserGroup' => 1));
66 68 $this->assertContains(
67   - '<a href="server_user_groups.php?'
68   - . PMA_URL_getCommon() . '&addUserGroup=1">',
  69 + $url_tag,
69 70 $html
70 71 );
71 72 }
@@ -97,7 +98,7 @@ public function testGetHtmlForUserGroupsTableWithUserGroups()
97 98 ->will(
98 99 $this->returnValue(
99 100 array(
100   - 'usergroup' => 'usergroup<',
  101 + 'usergroup' => 'usergroup',
101 102 'server_sql' => 'Y',
102 103 'server_databases' => 'N',
103 104 'db_sql' => 'Y',
@@ -117,25 +118,39 @@ public function testGetHtmlForUserGroupsTableWithUserGroups()
117 118
118 119 $html = PMA_getHtmlForUserGroupsTable();
119 120 $this->assertContains(
120   - '<td>usergroup&lt;</td>',
  121 + '<td>usergroup</td>',
121 122 $html
122 123 );
  124 + $url_tag = '<a class="" href="server_user_groups.php?'
  125 + . PMA_URL_getCommon(
  126 + array(
  127 + 'viewUsers'=>1, 'userGroup'=>htmlspecialchars('usergroup')
  128 + )
  129 + );
123 130 $this->assertContains(
124   - '<a class="" href="server_user_groups.php?'
125   - . PMA_URL_getCommon() . '&viewUsers=1&userGroup='
126   - . urlencode('usergroup<') . '">',
  131 + $url_tag,
127 132 $html
128 133 );
  134 + $url_tag = '<a class="" href="server_user_groups.php?'
  135 + . PMA_URL_getCommon(
  136 + array(
  137 + 'editUserGroup'=>1,
  138 + 'userGroup'=>htmlspecialchars('usergroup')
  139 + )
  140 + );
129 141 $this->assertContains(
130   - '<a class="" href="server_user_groups.php?'
131   - . PMA_URL_getCommon() . '&editUserGroup=1&userGroup='
132   - . urlencode('usergroup<') . '">',
  142 + $url_tag,
133 143 $html
134 144 );
  145 + $url_tag = '<a class="deleteUserGroup ajax" href="server_user_groups.php?'
  146 + . PMA_URL_getCommon(
  147 + array(
  148 + 'deleteUserGroup'=> 1,
  149 + 'userGroup'=>htmlspecialchars('usergroup')
  150 + )
  151 + );
135 152 $this->assertContains(
136   - '<a class="deleteUserGroup ajax" href="server_user_groups.php?'
137   - . PMA_URL_getCommon() . '&deleteUserGroup=1&userGroup='
138   - . urlencode('usergroup<') . '">',
  153 + $url_tag,
139 154 $html
140 155 );
141 156 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.