Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

more UTs for PMA_server_privileges #697

Merged
merged 2 commits into from 7 months ago

4 participants

xmujay Coveralls Michal Čihař Marc Delisle
xmujay

No description provided.

Coveralls

Coverage Status

Coverage increased (+0.81%) when pulling 072d79b on xmujay:0915_UT_server_privileges into 0d9e452 on phpmyadmin:master.

Coveralls

Coverage Status

Coverage increased (+0.81%) when pulling 130bff3 on xmujay:0915_UT_server_privileges into 0d9e452 on phpmyadmin:master.

xmujay

failed, but it is not related with this case. I will double-check it, so close it firstly

xmujay xmujay closed this September 15, 2013
Michal Čihař
Owner

The failure is indeed not related, it's just timing problem in tracker test...

Michal Čihař nijel reopened this September 15, 2013
Coveralls

Coverage Status

Coverage increased (+0.8%) when pulling 130bff3 on xmujay:0915_UT_server_privileges into 0d9e452 on phpmyadmin:master.

xmujay

thanks @nijel for double-checking

from the trival build result : https://travis-ci.org/phpmyadmin/phpmyadmin/builds/11386382

the cases in this pull request are passed. thanks

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

Showing 2 unique commits by 1 author.

Sep 15, 2013
xmujay UTs for PMA_server_privileges 072d79b
xmujay refactor the code style 130bff3
This page is out of date. Refresh to see the latest.
434  test/libraries/PMA_server_privileges_test.php
@@ -65,12 +65,14 @@ public function setUp()
65 65
         $GLOBALS['cfg']['DefaultTabTable'] = "db_structure.php";
66 66
         $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = "db_structure.php";
67 67
         $GLOBALS['cfg']['Confirm'] = "Confirm";
  68
+        $GLOBALS['cfg']['ShowHint'] = true;
68 69
 
69 70
         $GLOBALS['table'] = "table";
70 71
         $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
71 72
         $GLOBALS['pmaThemeImage'] = 'image';
72 73
         $GLOBALS['server'] = 1;
73  
-        $GLOBALS['username'] = "pma_username";
  74
+        $GLOBALS['hostname'] = "hostname";
  75
+        $GLOBALS['username'] = "username";
74 76
         $GLOBALS['collation_connection'] = "collation_connection";
75 77
         $GLOBALS['text_dir'] = "text_dir";
76 78
 
@@ -230,6 +232,12 @@ public function testPMARangeOfUsers()
230 232
             " WHERE `User` LIKE 'INIT%' OR `User` LIKE 'init%'",
231 233
             $ret
232 234
         );
  235
+
  236
+        $ret = PMA_rangeOfUsers();
  237
+        $this->assertEquals(
  238
+            '',
  239
+            $ret
  240
+        );
233 241
     }
234 242
 
235 243
     /**
@@ -809,7 +817,7 @@ public function testPMAGetHtmlToDisplayPrivilegesTable()
809 817
                 . 'Create_user,Repl_slave,Repl_client',
810 818
             'Type' => "'Super1','Select','Insert','Update','Create','Alter','Index',"
811 819
                 . "'Drop','Delete','File','Super','Process','Reload','Shutdown','"
812  
-                . "Show_db','Repl_slave','Create_tmp_table'," 
  820
+                . "Show_db','Repl_slave','Create_tmp_table',"
813 821
                 . "'Show_view','Create_routine','"
814 822
                 . "Repl_client','Lock_tables','References','Alter_routine','"
815 823
                 . "Create_user','Repl_slave','Repl_client','Execute','Grant','ddd",
@@ -970,4 +978,426 @@ public function testPMAGetSqlQueriesForDisplayAndAddUser()
970 978
             $message->getMessage()
971 979
         );
972 980
     }
  981
+
  982
+    /**
  983
+     * Test for PMA_getHtmlForTableSpecificPrivileges
  984
+     *
  985
+     * @return void
  986
+     */
  987
+    public function testPMAGetHtmlForTableSpecificPrivileges()
  988
+    {
  989
+        $GLOBALS['strPrivDescCreate_viewTbl'] = "strPrivDescCreate_viewTbl";
  990
+        $GLOBALS['strPrivDescShowViewTbl'] = "strPrivDescShowViewTbl";
  991
+        $username = "PMA_username";
  992
+        $hostname = "PMA_hostname";
  993
+        $db = "PMA_db";
  994
+        $table = "PMA_table";
  995
+        $columns = array(
  996
+            'row1' => 'name1'
  997
+        );
  998
+        $row = array(
  999
+            'Select_priv' => 'Y',
  1000
+            'Insert_priv' => 'Y',
  1001
+            'Update_priv' => 'Y',
  1002
+            'References_priv' => 'Y',
  1003
+            'Create_view_priv' => 'Y',
  1004
+            'ShowView_priv' => 'Y',
  1005
+        );
  1006
+
  1007
+        $html = PMA_getHtmlForTableSpecificPrivileges(
  1008
+            $username, $hostname, $db, $table, $columns, $row
  1009
+        );
  1010
+
  1011
+        //validate 1: PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn
  1012
+        $item = PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn(
  1013
+            $columns, $row
  1014
+        );
  1015
+        $this->assertContains(
  1016
+            $item,
  1017
+            $html
  1018
+        );
  1019
+        $this->assertContains(
  1020
+            __('Allows reading data.'),
  1021
+            $html
  1022
+        );
  1023
+        $this->assertContains(
  1024
+            __('Allows inserting and replacing data'),
  1025
+            $html
  1026
+        );
  1027
+        $this->assertContains(
  1028
+            __('Allows changing data.'),
  1029
+            $html
  1030
+        );
  1031
+        $this->assertContains(
  1032
+            __('Has no effect in this MySQL version.'),
  1033
+            $html
  1034
+        );
  1035
+
  1036
+        //validate 2: PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn
  1037
+        $item = PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn(
  1038
+            $row
  1039
+        );
  1040
+        $this->assertContains(
  1041
+            $item,
  1042
+            $html
  1043
+        );
  1044
+        $this->assertContains(
  1045
+            'Create_view_priv',
  1046
+            $html
  1047
+        );
  1048
+        $this->assertContains(
  1049
+            'ShowView_priv',
  1050
+            $html
  1051
+        );
  1052
+    }
  1053
+
  1054
+    /**
  1055
+     * Test for PMA_getHtmlForDisplayLoginInformationFields
  1056
+     *
  1057
+     * @return void
  1058
+     */
  1059
+    public function testPMAGetHtmlForDisplayLoginInformationFields()
  1060
+    {
  1061
+        $GLOBALS['username'] = 'pma_username';
  1062
+
  1063
+        $dbi_old = $GLOBALS['dbi'];
  1064
+        $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
  1065
+            ->disableOriginalConstructor()
  1066
+            ->getMock();
  1067
+        $fields_info = array(
  1068
+            "Host" => array(
  1069
+                "Field" => "host",
  1070
+                "Type" => "char(60)",
  1071
+                "Null" => "NO",
  1072
+            )
  1073
+        );
  1074
+        $dbi->expects($this->any())->method('getColumns')
  1075
+            ->will($this->returnValue($fields_info));
  1076
+
  1077
+        $fetchValue = "fetchValue";
  1078
+        $dbi->expects($this->any())->method('fetchValue')
  1079
+            ->will($this->returnValue($fetchValue));
  1080
+
  1081
+        $GLOBALS['dbi'] = $dbi;
  1082
+
  1083
+        $html = PMA_getHtmlForDisplayLoginInformationFields();
  1084
+        list($username_length, $hostname_length)
  1085
+            = PMA_getUsernameAndHostnameLength();
  1086
+
  1087
+        //validate 1: __('Login Information')
  1088
+        $this->assertContains(
  1089
+            __('Login Information'),
  1090
+            $html
  1091
+        );
  1092
+        $this->assertContains(
  1093
+            __('User name:'),
  1094
+            $html
  1095
+        );
  1096
+        $this->assertContains(
  1097
+            __('Any user'),
  1098
+            $html
  1099
+        );
  1100
+        $this->assertContains(
  1101
+            __('Use text field'),
  1102
+            $html
  1103
+        );
  1104
+
  1105
+        $output = PMA_Util::showHint(
  1106
+            __(
  1107
+                'When Host table is used, this field is ignored '
  1108
+                . 'and values stored in Host table are used instead.'
  1109
+            )
  1110
+        );
  1111
+        $this->assertContains(
  1112
+            $output,
  1113
+            $html
  1114
+        );
  1115
+
  1116
+        $GLOBALS['dbi'] = $dbi_old;
  1117
+    }
  1118
+
  1119
+    /**
  1120
+     * Test for PMA_getWithClauseForAddUserAndUpdatePrivs
  1121
+     *
  1122
+     * @return void
  1123
+     */
  1124
+    public function testPMAGetWithClauseForAddUserAndUpdatePrivs()
  1125
+    {
  1126
+        $_POST['Grant_priv'] = 'Y';
  1127
+        $_POST['max_questions'] = 10;
  1128
+        $_POST['max_connections'] = 20;
  1129
+        $_POST['max_updates'] = 30;
  1130
+        $_POST['max_user_connections'] = 40;
  1131
+
  1132
+        $sql_query = PMA_getWithClauseForAddUserAndUpdatePrivs();
  1133
+        $expect = "WITH GRANT OPTION MAX_QUERIES_PER_HOUR 10 "
  1134
+            . "MAX_CONNECTIONS_PER_HOUR 20"
  1135
+            . " MAX_UPDATES_PER_HOUR 30 MAX_USER_CONNECTIONS 40";
  1136
+        $this->assertContains(
  1137
+            $expect,
  1138
+            $sql_query
  1139
+        );
  1140
+
  1141
+    }
  1142
+
  1143
+    /**
  1144
+     * Test for PMA_getListOfPrivilegesAndComparedPrivileges
  1145
+     *
  1146
+     * @return void
  1147
+     */
  1148
+    public function testPMAGetListOfPrivilegesAndComparedPrivileges()
  1149
+    {
  1150
+        list($list_of_privileges, $list_of_compared_privileges)
  1151
+            = PMA_getListOfPrivilegesAndComparedPrivileges();
  1152
+        $expect = "`User`, `Host`, `Select_priv`, `Insert_priv`";
  1153
+        $this->assertContains(
  1154
+            $expect,
  1155
+            $list_of_privileges
  1156
+        );
  1157
+        $expect = "`Select_priv` = 'N' AND `Insert_priv` = 'N'";
  1158
+        $this->assertContains(
  1159
+            $expect,
  1160
+            $list_of_compared_privileges
  1161
+        );
  1162
+        $expect = "`Create_routine_priv` = 'N' AND `Alter_routine_priv` = 'N'";
  1163
+        $this->assertContains(
  1164
+            $expect,
  1165
+            $list_of_compared_privileges
  1166
+        );
  1167
+    }
  1168
+
  1169
+    /**
  1170
+     * Test for PMA_getHtmlForAddUser
  1171
+     *
  1172
+     * @return void
  1173
+     */
  1174
+    public function testPMAGetHtmlForAddUser()
  1175
+    {
  1176
+        $dbi_old = $GLOBALS['dbi'];
  1177
+        $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
  1178
+            ->disableOriginalConstructor()
  1179
+            ->getMock();
  1180
+        $fields_info = array(
  1181
+            "Host" => array(
  1182
+                "Field" => "host",
  1183
+                "Type" => "char(60)",
  1184
+                "Null" => "NO",
  1185
+            )
  1186
+        );
  1187
+        $dbi->expects($this->any())->method('getColumns')
  1188
+            ->will($this->returnValue($fields_info));
  1189
+
  1190
+        $GLOBALS['dbi'] = $dbi;
  1191
+
  1192
+        $dbname = "pma_dbname";
  1193
+
  1194
+        $html = PMA_getHtmlForAddUser($dbname);
  1195
+
  1196
+        //validate 1: PMA_URL_getHiddenInputs
  1197
+        $this->assertContains(
  1198
+            PMA_URL_getHiddenInputs('', ''),
  1199
+            $html
  1200
+        );
  1201
+
  1202
+        //validate 2: PMA_getHtmlForDisplayLoginInformationFields
  1203
+        $this->assertContains(
  1204
+            PMA_getHtmlForDisplayLoginInformationFields('new'),
  1205
+            $html
  1206
+        );
  1207
+
  1208
+        //validate 3: Database for user
  1209
+        $this->assertContains(
  1210
+            __('Database for user'),
  1211
+            $html
  1212
+        );
  1213
+
  1214
+        $item = PMA_Util::getCheckbox(
  1215
+            'createdb-2',
  1216
+            __('Grant all privileges on wildcard name (username\\_%).'),
  1217
+            false, false
  1218
+        );
  1219
+        $this->assertContains(
  1220
+            $item,
  1221
+            $html
  1222
+        );
  1223
+
  1224
+        //validate 4: PMA_getHtmlToDisplayPrivilegesTable
  1225
+        $this->assertContains(
  1226
+            PMA_getHtmlToDisplayPrivilegesTable('*', '*', false),
  1227
+            $html
  1228
+        );
  1229
+
  1230
+        //validate 5: button
  1231
+        $this->assertContains(
  1232
+            __('Go'),
  1233
+            $html
  1234
+        );
  1235
+
  1236
+        $GLOBALS['dbi'] = $dbi_old;
  1237
+    }
  1238
+
  1239
+    /**
  1240
+     * Test for PMA_getHtmlForSpecificDbPrivileges
  1241
+     *
  1242
+     * @return void
  1243
+     */
  1244
+    public function testPMAGetHtmlForSpecificDbPrivileges()
  1245
+    {
  1246
+        $dbi_old = $GLOBALS['dbi'];
  1247
+        $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
  1248
+            ->disableOriginalConstructor()
  1249
+            ->getMock();
  1250
+        $fields_info = array(
  1251
+            "Host" => array(
  1252
+                "Field" => "host",
  1253
+                "Type" => "char(60)",
  1254
+                "Null" => "NO",
  1255
+            )
  1256
+        );
  1257
+        $dbi->expects($this->any())->method('getColumns')
  1258
+            ->will($this->returnValue($fields_info));
  1259
+
  1260
+        $GLOBALS['dbi'] = $dbi;
  1261
+
  1262
+        $db = "pma_dbname";
  1263
+
  1264
+        $html = PMA_getHtmlForSpecificDbPrivileges($db);
  1265
+
  1266
+        //validate 1: PMA_URL_getCommon
  1267
+        $this->assertContains(
  1268
+            PMA_URL_getCommon($db),
  1269
+            $html
  1270
+        );
  1271
+
  1272
+        //validate 2: htmlspecialchars
  1273
+        $this->assertContains(
  1274
+            htmlspecialchars($db),
  1275
+            $html
  1276
+        );
  1277
+
  1278
+        //validate 3: items
  1279
+        $this->assertContains(
  1280
+            __('User'),
  1281
+            $html
  1282
+        );
  1283
+        $this->assertContains(
  1284
+            __('Host'),
  1285
+            $html
  1286
+        );
  1287
+        $this->assertContains(
  1288
+            __('Type'),
  1289
+            $html
  1290
+        );
  1291
+        $this->assertContains(
  1292
+            __('Privileges'),
  1293
+            $html
  1294
+        );
  1295
+        $this->assertContains(
  1296
+            __('Grant'),
  1297
+            $html
  1298
+        );
  1299
+        $this->assertContains(
  1300
+            __('Action'),
  1301
+            $html
  1302
+        );
  1303
+
  1304
+        //_pgettext('Create new user', 'New')
  1305
+        $this->assertContains(
  1306
+            _pgettext('Create new user', 'New'),
  1307
+            $html
  1308
+        );
  1309
+        $this->assertContains(
  1310
+            PMA_URL_getCommon(array('checkprivsdb' => $db)),
  1311
+            $html
  1312
+        );
  1313
+
  1314
+        $GLOBALS['dbi'] = $dbi_old;
  1315
+    }
  1316
+
  1317
+    /**
  1318
+     * Test for PMA_getHtmlForSpecificTablePrivileges
  1319
+     *
  1320
+     * @return void
  1321
+     */
  1322
+    public function testPMAGetHtmlForSpecificTablePrivileges()
  1323
+    {
  1324
+        $dbi_old = $GLOBALS['dbi'];
  1325
+        $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
  1326
+            ->disableOriginalConstructor()
  1327
+            ->getMock();
  1328
+        $fields_info = array(
  1329
+            "Host" => array(
  1330
+                "Field" => "host",
  1331
+                "Type" => "char(60)",
  1332
+                "Null" => "NO",
  1333
+            )
  1334
+        );
  1335
+        $dbi->expects($this->any())->method('getColumns')
  1336
+            ->will($this->returnValue($fields_info));
  1337
+
  1338
+        $GLOBALS['dbi'] = $dbi;
  1339
+
  1340
+        $db = "pma_dbname";
  1341
+        $table = "pma_table";
  1342
+
  1343
+        $html = PMA_getHtmlForSpecificTablePrivileges($db, $table);
  1344
+
  1345
+        //validate 1: $db, $table
  1346
+        $this->assertContains(
  1347
+            htmlspecialchars($db) . '.' . htmlspecialchars($table),
  1348
+            $html
  1349
+        );
  1350
+
  1351
+        //validate 2: PMA_URL_getCommon
  1352
+        $item = PMA_URL_getCommon(
  1353
+            array(
  1354
+                'db' => $db,
  1355
+                'table' => $table,
  1356
+            )
  1357
+        );
  1358
+        $this->assertContains(
  1359
+            $item,
  1360
+            $html
  1361
+        );
  1362
+
  1363
+        //validate 3: items
  1364
+        $this->assertContains(
  1365
+            __('User'),
  1366
+            $html
  1367
+        );
  1368
+        $this->assertContains(
  1369
+            __('Host'),
  1370
+            $html
  1371
+        );
  1372
+        $this->assertContains(
  1373
+            __('Type'),
  1374
+            $html
  1375
+        );
  1376
+        $this->assertContains(
  1377
+            __('Privileges'),
  1378
+            $html
  1379
+        );
  1380
+        $this->assertContains(
  1381
+            __('Grant'),
  1382
+            $html
  1383
+        );
  1384
+        $this->assertContains(
  1385
+            __('Action'),
  1386
+            $html
  1387
+        );
  1388
+
  1389
+        //_pgettext('Create new user', 'New')
  1390
+        $this->assertContains(
  1391
+            _pgettext('Create new user', 'New'),
  1392
+            $html
  1393
+        );
  1394
+        $this->assertContains(
  1395
+            PMA_URL_getCommon(
  1396
+                array('checkprivsdb' => $db, 'checkprivstable' => $table)
  1397
+            ),
  1398
+            $html
  1399
+        );
  1400
+
  1401
+        $GLOBALS['dbi'] = $dbi_old;
  1402
+    }
973 1403
 }
Commit_comment_tip

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.