@@ -66,6 +66,8 @@ public function setUp() {
66
66
public function test_ajax_response_get_query_data_valid_query () {
67
67
$ this ->_setRole ( 'administrator ' );
68
68
69
+ $ this ->enable_pro ();
70
+
69
71
$ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION );
70
72
71
73
global $ wpdb ;
@@ -93,6 +95,8 @@ public function test_ajax_response_get_query_data_valid_query() {
93
95
public function test_ajax_response_get_query_data_invalid_query () {
94
96
$ this ->_setRole ( 'administrator ' );
95
97
98
+ $ this ->enable_pro ();
99
+
96
100
$ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION );
97
101
98
102
$ _POST ['params ' ] = array (
@@ -120,6 +124,8 @@ public function test_ajax_response_get_query_data_invalid_query() {
120
124
public function test_ajax_response_get_query_data_valid_query_with_filtered_columns () {
121
125
$ this ->_setRole ( 'administrator ' );
122
126
127
+ $ this ->enable_pro ();
128
+
123
129
$ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION );
124
130
125
131
$ _POST ['params ' ] = array (
@@ -203,6 +209,8 @@ public function test_ajax_response_get_query_data_subcriber_dissallow() {
203
209
public function test_ajax_response_get_query_data_invalid_query_subquery () {
204
210
$ this ->_setRole ( 'administrator ' );
205
211
212
+ $ this ->enable_pro ();
213
+
206
214
$ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION );
207
215
208
216
$ _POST ['params ' ] = array (
@@ -230,6 +238,8 @@ public function test_ajax_response_get_query_data_invalid_query_subquery() {
230
238
public function test_ajax_response_get_query_data_invalid_query_comment () {
231
239
$ this ->_setRole ( 'administrator ' );
232
240
241
+ $ this ->enable_pro ();
242
+
233
243
$ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION );
234
244
235
245
$ _POST ['params ' ] = array (
@@ -264,4 +274,66 @@ public function test_sql_comment_strip() {
264
274
$ source = new Visualizer_Source_Query ( "/* SELECT */ DELETE * FROM test_table /* WHERE post_type = 'post' */ " );
265
275
$ this ->assertEquals ( 'DELETE * FROM test_table ' , $ source ->get_query () );
266
276
}
277
+
278
+ /**
279
+ * Test Save Query not allowed for subscriber.
280
+ */
281
+ public function test_sql_save_chart_subscriber () {
282
+ $ this ->_setRole ( 'subscriber ' );
283
+
284
+ $ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION );
285
+ $ _GET ['chart ' ] = '1 ' ;
286
+
287
+ $ _POST ['params ' ] = array (
288
+ 'query ' => "SELECT * FROM wp_posts LIMIT 1 " ,
289
+ );
290
+ try {
291
+ // Trigger the AJAX action
292
+ $ this ->_handleAjax ( Visualizer_Plugin::ACTION_SAVE_DB_QUERY );
293
+ } catch ( WPAjaxDieContinueException $ e ) {
294
+ // We expected this, do nothing.
295
+ }
296
+
297
+ $ response = json_decode ( $ this ->_last_response );
298
+ $ this ->assertIsObject ( $ response );
299
+ $ this ->assertObjectHasAttribute ( 'success ' , $ response );
300
+ $ this ->assertObjectHasAttribute ( 'data ' , $ response );
301
+ $ this ->assertEquals ( 'Action not allowed for this user. ' , $ response ->data ->msg );
302
+ $ this ->assertFalse ( $ response ->success );
303
+ }
304
+
305
+ /**
306
+ * Test Save Query not allowed if not pro.
307
+ */
308
+ public function test_sql_save_chart_admin () {
309
+ wp_set_current_user ( $ this ->admin_user_id );
310
+ $ this ->_setRole ( 'administrator ' );
311
+
312
+ $ _GET ['security ' ] = wp_create_nonce ( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION );
313
+ $ _GET ['chart ' ] = '1 ' ;
314
+
315
+ $ _POST ['params ' ] = array (
316
+ 'query ' => "SELECT * FROM wp_posts LIMIT 1 " ,
317
+ );
318
+ try {
319
+ // Trigger the AJAX action
320
+ $ this ->_handleAjax ( Visualizer_Plugin::ACTION_SAVE_DB_QUERY );
321
+ } catch ( WPAjaxDieContinueException $ e ) {
322
+ // We expected this, do nothing.
323
+ }
324
+
325
+ $ response = json_decode ( $ this ->_last_response );
326
+ $ this ->assertIsObject ( $ response );
327
+ $ this ->assertObjectHasAttribute ( 'success ' , $ response );
328
+ $ this ->assertObjectHasAttribute ( 'data ' , $ response );
329
+ $ this ->assertEquals ( 'Feature is not available. ' , $ response ->data ->msg );
330
+ $ this ->assertFalse ( $ response ->success );
331
+ }
332
+
333
+ /**
334
+ * Utility method to mock pro version.
335
+ */
336
+ private function enable_pro () {
337
+ add_filter ( 'visualizer_is_pro ' , '__return_true ' );
338
+ }
267
339
}
0 commit comments