8
8
* @since 3.10.12
9
9
*/
10
10
11
+ /**
12
+ * Test the AJAX functionality.
13
+ */
11
14
class Test_Visualizer_Ajax extends WP_Ajax_UnitTestCase {
12
15
16
+ /**
17
+ * Admin user ID.
18
+ *
19
+ * @var int
20
+ */
13
21
private $ admin_user_id ;
14
22
15
- public function setUp () :void {
23
+ /**
24
+ * Set up.
25
+ */
26
+ public function setUp () {
16
27
parent ::setUp ();
17
28
$ this ->admin_user_id = $ this ->factory ->user ->create (
18
29
array (
@@ -23,6 +34,9 @@ public function setUp() :void {
23
34
24
35
}
25
36
37
+ /**
38
+ * Test the AJAX response for fetching the database data.
39
+ */
26
40
public function test_ajax_response_get_query_data_valid_query () {
27
41
$ this ->_setRole ( 'administrator ' );
28
42
@@ -34,7 +48,7 @@ public function test_ajax_response_get_query_data_valid_query() {
34
48
try {
35
49
// Trigger the AJAX action
36
50
$ this ->_handleAjax ( Visualizer_Plugin::ACTION_FETCH_DB_DATA );
37
- } catch (WPAjaxDieContinueException $ e ) {
51
+ } catch ( WPAjaxDieContinueException $ e ) {
38
52
// We expected this, do nothing.
39
53
}
40
54
@@ -45,6 +59,9 @@ public function test_ajax_response_get_query_data_valid_query() {
45
59
$ this ->assertTrue ( $ response ->success );
46
60
}
47
61
62
+ /**
63
+ * Test the AJAX response for fetching the database data with invalid query.
64
+ */
48
65
public function test_ajax_response_get_query_data_invalid_query () {
49
66
$ this ->_setRole ( 'administrator ' );
50
67
@@ -56,7 +73,7 @@ public function test_ajax_response_get_query_data_invalid_query() {
56
73
try {
57
74
// Trigger the AJAX action
58
75
$ this ->_handleAjax ( Visualizer_Plugin::ACTION_FETCH_DB_DATA );
59
- } catch (WPAjaxDieContinueException $ e ) {
76
+ } catch ( WPAjaxDieContinueException $ e ) {
60
77
// We expected this, do nothing.
61
78
}
62
79
@@ -68,6 +85,9 @@ public function test_ajax_response_get_query_data_invalid_query() {
68
85
$ this ->assertFalse ( $ response ->success );
69
86
}
70
87
88
+ /**
89
+ * Test the AJAX response for fetching the database data with user capability.
90
+ */
71
91
public function test_ajax_response_get_query_data_subcriber_dissallow () {
72
92
$ this ->_setRole ( 'subscriber ' );
73
93
@@ -79,7 +99,7 @@ public function test_ajax_response_get_query_data_subcriber_dissallow() {
79
99
try {
80
100
// Trigger the AJAX action
81
101
$ this ->_handleAjax ( Visualizer_Plugin::ACTION_FETCH_DB_DATA );
82
- } catch (WPAjaxDieContinueException $ e ) {
102
+ } catch ( WPAjaxDieContinueException $ e ) {
83
103
// We expected this, do nothing.
84
104
}
85
105
0 commit comments