Skip to content

Commit 9c7d33e

Browse files
authored
Merge pull request #146 from contactashish13/issue-142
phpunit more tests #142
2 parents 2c6fce4 + 0511105 commit 9c7d33e

File tree

7 files changed

+484
-251
lines changed

7 files changed

+484
-251
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ public function deleteChart() {
204204
* @access public
205205
*/
206206
public function renderChartPages() {
207-
define( 'IFRAME_REQUEST', 1 );
207+
defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );
208208

209209
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
210-
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT );
210+
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
211211
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
212212
$default_type = 'line';
213213

@@ -231,7 +231,7 @@ public function renderChartPages() {
231231
}
232232

233233
wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
234-
exit;
234+
wp_die();
235235
}
236236

237237
// enqueue and register scripts and styles
@@ -250,8 +250,8 @@ public function renderChartPages() {
250250
}
251251

252252
// dispatch pages
253-
$this->_chart = $chart;
254-
switch ( filter_input( INPUT_GET, 'tab' ) ) {
253+
$this->_chart = get_post( $chart_id );
254+
switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) {
255255
case 'settings':
256256
// changed by Ash/Upwork
257257
$this->_handleDataAndSettingsPage();
@@ -262,7 +262,7 @@ public function renderChartPages() {
262262
break;
263263
}
264264

265-
exit;
265+
wp_die();
266266
}
267267

268268
/**
@@ -351,7 +351,7 @@ private function _handleDataPage() {
351351
* Handle data and settings page
352352
*/
353353
private function _handleDataAndSettingsPage() {
354-
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) {
354+
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
355355
if ( $this->_chart->post_status == 'auto-draft' ) {
356356
$this->_chart->post_status = 'publish';
357357
wp_update_post( $this->_chart->to_array() );
@@ -443,21 +443,22 @@ public function renderFlattrScript() {
443443
*/
444444
public function uploadData() {
445445
// validate nonce
446-
if ( ! wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) {
446+
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
447+
if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
447448
status_header( 403 );
448449
exit;
449450
}
450451

451452
// check chart, if chart exists
452-
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT );
453+
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
453454
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
454455
status_header( 400 );
455456
exit;
456457
}
457458

458459
$source = null;
459460
$render = new Visualizer_Render_Page_Update();
460-
if ( filter_input( INPUT_POST, 'remote_data', FILTER_VALIDATE_URL ) ) {
461+
if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
461462
$source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
462463
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
463464
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
@@ -488,7 +489,7 @@ public function uploadData() {
488489
}
489490

490491
$render->render();
491-
exit;
492+
wp_die();
492493
}
493494

494495
/**
@@ -551,7 +552,7 @@ public function exportData() {
551552
$chart_id = $success = false;
552553
$capable = current_user_can( 'edit_posts' );
553554
if ( $capable ) {
554-
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
555+
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) ) : '';
555556
if ( $chart_id ) {
556557
$chart = get_post( $chart_id );
557558
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -560,7 +561,7 @@ public function exportData() {
560561

561562
if ( $success ) {
562563
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
563-
$filename = $settings['title'];
564+
$filename = isset( $settings['title'] ) ? $settings['title'] : '';
564565
if ( empty( $filename ) ) {
565566
$filename = 'export.csv';
566567
} else {
@@ -619,6 +620,6 @@ public function exportData() {
619620
));
620621
}// End if().
621622

622-
exit;
623+
wp_die();
623624
}
624625
}

index.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,20 @@ function visualizer_launch() {
9090
define( 'VISUALIZER_CSV_ENCLOSURE', '"' );
9191
}
9292

93-
// don't load the plugin if cron job is running or doing autosave
94-
$doing_autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
95-
$doing_cron = defined( 'DOING_CRON' ) && DOING_CRON;
96-
$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
97-
if ( $doing_autosave || $doing_cron ) {
98-
return;
99-
}
100-
10193
// instantiate the plugin
10294
$plugin = Visualizer_Plugin::instance();
10395

10496
// set general modules
10597
$plugin->setModule( Visualizer_Module_Setup::NAME );
10698
$plugin->setModule( Visualizer_Module_Sources::NAME );
10799

108-
if ( $doing_ajax ) {
109-
// set ajax modules
110-
$plugin->setModule( Visualizer_Module_Chart::NAME );
100+
$plugin->setModule( Visualizer_Module_Chart::NAME );
101+
if ( is_admin() ) {
102+
// set admin modules
103+
$plugin->setModule( Visualizer_Module_Admin::NAME );
111104
} else {
112-
if ( is_admin() ) {
113-
// set admin modules
114-
$plugin->setModule( Visualizer_Module_Admin::NAME );
115-
} else {
116-
// set frontend modules
117-
$plugin->setModule( Visualizer_Module_Frontend::NAME );
118-
}
105+
// set frontend modules
106+
$plugin->setModule( Visualizer_Module_Frontend::NAME );
119107
}
120108
}
121109

js/frame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
parent.addClass('open');
3232
}
3333
});
34-
$('#vz-import-file').click(function () {
34+
$('#view-remote-file').click(function () {
3535
var url = $(this).parent().find('#remote-data').val();
3636

3737
if (url !== '') {

0 commit comments

Comments
 (0)