Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

UTs for PMA_server_privileges #584

Merged
merged 1 commit into from 11 months ago

2 participants

xmujay Marc Delisle
xmujay

No description provided.

xmujay

Hi Marc,

I added more cases for PMA_server_privileges. about the coverage for newly added functions, I will add UT when the refactored pull request are merged, thanks

Marc Delisle lem9 merged commit 490f960 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 11, 2013
xmujay xmujay add test case for PMA_server_privileges 9e2639e
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 115 additions and 0 deletions. Show diff stats Hide diff stats

  1. +115 0 test/libraries/PMA_server_privileges_test.php
115 test/libraries/PMA_server_privileges_test.php
@@ -18,6 +18,7 @@
18 18 require_once 'libraries/sanitizing.lib.php';
19 19 require_once 'libraries/sqlparser.lib.php';
20 20 require_once 'libraries/js_escape.lib.php';
  21 +require_once 'libraries/Message.class.php';
21 22 require_once 'libraries/server_privileges.lib.php';
22 23
23 24 /**
@@ -66,11 +67,101 @@ public function setUp()
66 67 $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
67 68 ->disableOriginalConstructor()
68 69 ->getMock();
  70 +
  71 + $dbi->expects($this->any())
  72 + ->method('fetchResult')
  73 + ->will(
  74 + $this->returnValue(
  75 + array(
  76 + 'grant user1 select',
  77 + 'grant user2 delete'
  78 + )
  79 + )
  80 + );
69 81
70 82 $GLOBALS['dbi'] = $dbi;
71 83 }
72 84
73 85 /**
  86 + * Test for PMA_getHtmlForExportUserDefinition
  87 + *
  88 + * @return void
  89 + */
  90 + public function testPMAGetHtmlForExportUserDefinition()
  91 + {
  92 + $username = "PMA_username";
  93 + $hostname = "PMA_hostname";
  94 + $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb';
  95 + $GLOBALS['cfg']['Server']['usergroups'] = 'usergroups';
  96 + $GLOBALS['cfg']['Server']['users'] = 'users';
  97 + $GLOBALS['cfg']['TextareaCols'] = 'TextareaCols';
  98 + $GLOBALS['cfg']['TextareaRows'] = 'TextareaCols';
  99 +
  100 + list($title, $export)
  101 + = PMA_getHtmlForExportUserDefinition($username, $hostname);
  102 +
  103 + //validate 1: $export
  104 + $result = '<textarea class="export" cols="' . $GLOBALS['cfg']['TextareaCols']
  105 + . '" rows="' . $GLOBALS['cfg']['TextareaRows'];
  106 + $this->assertContains(
  107 + 'grant user2 delete',
  108 + $export
  109 + );
  110 + $this->assertContains(
  111 + 'grant user1 select',
  112 + $export
  113 + );
  114 + $this->assertContains(
  115 + $result,
  116 + $export
  117 + );
  118 +
  119 + //validate 2: $title
  120 + $title_user = __('User') . ' `' . htmlspecialchars($username)
  121 + . '`@`' . htmlspecialchars($hostname) . '`';
  122 + $this->assertContains(
  123 + $title_user,
  124 + $title
  125 + );
  126 + }
  127 +
  128 + /**
  129 + * Test for PMA_getHtmlForSubMenusOnUsersPage
  130 + *
  131 + * @return void
  132 + */
  133 + public function testPMAGetHtmlForSubMenusOnUsersPage()
  134 + {
  135 + $html = PMA_getHtmlForSubMenusOnUsersPage('server_privileges.php');
  136 +
  137 + //validate 1: topmenu2
  138 + $this->assertContains(
  139 + '<ul id="topmenu2">',
  140 + $html
  141 + );
  142 +
  143 + //validate 2: tabactive for server_privileges.php
  144 + $this->assertContains(
  145 + '<a class="tabactive" href="server_privileges.php',
  146 + $html
  147 + );
  148 + $this->assertContains(
  149 + __('Users overview'),
  150 + $html
  151 + );
  152 +
  153 + //validate 3: not-active for server_user_groups.php
  154 + $this->assertContains(
  155 + '<a href="server_user_groups.php',
  156 + $html
  157 + );
  158 + $this->assertContains(
  159 + __('User groups'),
  160 + $html
  161 + );
  162 + }
  163 +
  164 + /**
74 165 * Test for PMA_getSqlQueriesForDisplayAndAddUser
75 166 *
76 167 * @return void
@@ -80,6 +171,7 @@ public function testPMAGetSqlQueriesForDisplayAndAddUser()
80 171 $username = "PMA_username";
81 172 $hostname = "PMA_hostname";
82 173 $password = "PMA_password";
  174 + $dbname = "PMA_db";
83 175
84 176 list($create_user_real, $create_user_show, $real_sql_query, $sql_query)
85 177 = PMA_getSqlQueriesForDisplayAndAddUser($username, $hostname, $password);
@@ -108,5 +200,28 @@ public function testPMAGetSqlQueriesForDisplayAndAddUser()
108 200 $sql_query
109 201 );
110 202
  203 +
  204 + //test for PMA_addUserAndCreateDatabase
  205 + list($sql_query, $message) = PMA_addUserAndCreateDatabase(
  206 + false, $real_sql_query, $sql_query, $username, $hostname, $dbname
  207 + );
  208 +
  209 + //validate 5: $sql_query
  210 + $this->assertEquals(
  211 + "GRANT USAGE ON *.* TO 'PMA_username'@'PMA_hostname';"
  212 + . "CREATE DATABASE IF NOT EXISTS `PMA_username`;"
  213 + . "GRANT ALL PRIVILEGES ON `PMA\_username`.* TO "
  214 + . "'PMA_username'@'PMA_hostname';"
  215 + . "GRANT ALL PRIVILEGES ON `PMA_username\_%`.* TO "
  216 + . "'PMA_username'@'PMA_hostname';"
  217 + . "GRANT ALL PRIVILEGES ON `PMA_db`.* TO 'PMA_username'@'PMA_hostname';",
  218 + $sql_query
  219 + );
  220 +
  221 + //validate 6: $message
  222 + $this->assertEquals(
  223 + "",
  224 + $message->getMessage()
  225 + );
111 226 }
112 227 }

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.