@@ -156,22 +156,22 @@ public function test_file_import( $file ) {
156
156
* @access public
157
157
* @dataProvider editorDataProvider
158
158
*/
159
- public function test_pro_editor ( $ data ) {
160
- if ( ! defined ( 'VISUALIZER_PRO_VERSION ' ) ) {
161
- $ this ->markTestSkipped ( 'PRO not installed/available, skipping test ' );
162
- }
159
+ public function test_pro_editor ($ data ) {
160
+ if ( !defined ( 'VISUALIZER_PRO_VERSION ' ) ) {
161
+ $ this ->markTestSkipped ( 'PRO not installed/available, skipping test ' );
162
+ }
163
163
164
164
$ this ->create_chart ();
165
165
$ this ->_setRole ( 'administrator ' );
166
166
167
167
$ _POST = array (
168
- 'chart_data ' => $ data,
168
+ 'chart_data ' => $ data
169
169
);
170
170
$ _GET = array (
171
171
'nonce ' => wp_create_nonce (),
172
172
'chart ' => $ this ->chart ,
173
173
);
174
- $ _FILES = array ();
174
+ $ _FILES = array ();
175
175
176
176
// swallow the output
177
177
ob_start ();
@@ -192,45 +192,81 @@ public function test_pro_editor( $data ) {
192
192
$ this ->assertEquals ( $ content , $ content_line );
193
193
}
194
194
195
+ /**
196
+ * Testing fetch from chat feature. We only need to test fetching, because we already have a test case for uploading data
197
+ *
198
+ * @access public
199
+ */
200
+ public function test_pro_fetch_from_chart () {
201
+ if ( !defined ( 'VISUALIZER_PRO_VERSION ' ) ) {
202
+ $ this ->markTestSkipped ( 'PRO not installed/available, skipping test ' );
203
+ }
204
+
205
+ $ this ->create_chart ();
206
+ $ this ->_setRole ( 'administrator ' );
207
+
208
+ $ _GET = array (
209
+ 'nonce ' => wp_create_nonce (),
210
+ 'chart_id ' => $ this ->chart ,
211
+ );
212
+
213
+ // swallow the output
214
+ ob_start ();
215
+ try {
216
+ $ this ->_handleAjax ( 'visualizer-fetch-data ' );
217
+ } catch ( WPAjaxDieContinueException $ e ) {
218
+ // We expected this, do nothing.
219
+ } catch ( WPAjaxDieStopException $ ee ) {
220
+ // We expected this, do nothing.
221
+ }
222
+ ob_end_clean ();
223
+
224
+ $ response = json_decode ( $ this ->_last_response );
225
+ $ this ->assertInternalType ( 'object ' , $ response );
226
+ $ this ->assertObjectHasAttribute ( 'success ' , $ response );
227
+ $ this ->assertObjectHasAttribute ( 'data ' , $ response );
228
+ $ this ->assertTrue ( $ response ->success );
229
+ }
230
+
195
231
/**
196
232
* Provide the "edited" data
197
233
*
198
234
* @access public
199
235
*/
200
236
public function editorDataProvider () {
201
- $ data = array ();
202
- $ file = VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . 'line.csv ' ;
203
- if ( ($ handle = fopen ( $ file , ' r ' )) !== false ) {
204
- $ row = 0 ;
205
- while ( ($ line = fgetcsv ( $ handle , 0 , VISUALIZER_CSV_DELIMITER , VISUALIZER_CSV_ENCLOSURE )) !== false ) {
206
- if ( $ row ++ <= 1 ) {
207
- $ cols = count ( $ line );
208
- $ datum = array ();
209
- for ( $ col = 0 ; $ col < $ cols ; $ col ++ ) {
210
- $ datum [] = '" ' . $ line [ $ col ] . '" ' ;
211
- }
212
- } else {
213
- $ cols = count ( $ line );
214
- $ datum = array ();
215
- for ( $ col = 0 ; $ col < $ cols ; $ col ++ ) {
216
- if ( is_numeric ( $ line [ $ col ] ) ) {
217
- // multiply all numbers by 10
218
- $ datum [] = $ line [ $ col ] * 10 ;
219
- } else {
220
- $ datum [] = '" ' . $ line [ $ col ] . '" ' ;
221
- }
222
- }
223
- }
224
- $ data [] = $ datum ;
225
- }
226
- }
237
+ $ data = array ();
238
+ $ file = VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . 'line.csv ' ;
239
+ if (($ handle = fopen ($ file , " r " )) !== FALSE ) {
240
+ $ row = 0 ;
241
+ while (($ line = fgetcsv ($ handle , 0 , VISUALIZER_CSV_DELIMITER , VISUALIZER_CSV_ENCLOSURE )) !== FALSE ) {
242
+ if ($ row ++ <= 1 ) {
243
+ $ cols = count ($ line );
244
+ $ datum = array ();
245
+ for ($ col = 0 ; $ col < $ cols ; $ col ++) {
246
+ $ datum [] = '" ' . $ line [$ col ] . '" ' ;
247
+ }
248
+ } else {
249
+ $ cols = count ($ line );
250
+ $ datum = array ();
251
+ for ($ col = 0 ; $ col < $ cols ; $ col ++) {
252
+ if (is_numeric ($ line [$ col]) ) {
253
+ // multiply all numbers by 10
254
+ $ datum [] = $ line [$ col ] * 10 ;
255
+ } else {
256
+ $ datum [] = '" ' . $ line [$ col ] . '" ' ;
257
+ }
258
+ }
259
+ }
260
+ $ data [] = $ datum ;
261
+ }
262
+ }
227
263
228
- $ csv = array ();
229
- foreach ( $ data as $ row ) {
230
- $ csv [] = ' [ ' . implode ( ' , ' , $ row ) . ' ] ' ;
231
- }
232
- $ csv = ' [ ' . implode ( ' , ' , $ csv ) . ' ] ' ;
233
- return array ( array ( $ csv ) );
264
+ $ csv = array ();
265
+ foreach ($ data as $ row ) {
266
+ $ csv [] = " [ " . implode (" , " , $ row ) . " ] " ;
267
+ }
268
+ $ csv = " [ " . implode (" , " , $ csv ) . " ] " ;
269
+ return array (array ($ csv) );
234
270
}
235
271
/**
236
272
* Provide the fileURL for uploading the file
@@ -239,8 +275,8 @@ public function editorDataProvider() {
239
275
*/
240
276
public function fileProvider () {
241
277
return array (
242
- array ( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . 'bar.csv ' ),
243
- );
278
+ array (VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . 'bar.csv ' )
279
+ );
244
280
}
245
281
246
282
/**
@@ -250,7 +286,7 @@ public function fileProvider() {
250
286
*/
251
287
public function urlProvider () {
252
288
return array (
253
- array ( 'http://localhost/wp-content/plugins/wp-visualizer/samples/bar.csv ' ),
254
- );
289
+ array ('http://localhost/wp-content/plugins/wp-visualizer/samples/bar.csv ' )
290
+ );
255
291
}
256
292
}
0 commit comments