Skip to content

Commit b515456

Browse files
phpunit more tests #142
1 parent acbf74b commit b515456

File tree

9 files changed

+123
-56
lines changed

9 files changed

+123
-56
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,55 @@ public function setupMediaViewStrings( $strings ) {
135135
*/
136136
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) {
137137
$types = array(
138-
'pie' => array( 'name' => esc_html__( 'Pie', 'visualizer' ), 'enabled' => true ),
139-
'line' => array( 'name' => esc_html__( 'Line', 'visualizer' ), 'enabled' => true ),
140-
'area' => array( 'name' => esc_html__( 'Area', 'visualizer' ), 'enabled' => true ),
141-
'geo' => array( 'name' => esc_html__( 'Geo', 'visualizer' ), 'enabled' => true ),
142-
'bar' => array( 'name' => esc_html__( 'Bar', 'visualizer' ), 'enabled' => true ),
143-
'column' => array( 'name' => esc_html__( 'Column', 'visualizer' ), 'enabled' => true ),
144-
'gauge' => array( 'name' => esc_html__( 'Gauge', 'visualizer' ), 'enabled' => true ),
145-
'scatter' => array( 'name' => esc_html__( 'Scatter', 'visualizer' ), 'enabled' => true ),
146-
'candlestick' => array( 'name' => esc_html__( 'Candlestick', 'visualizer' ), 'enabled' => true ),
138+
'pie' => array(
139+
'name' => esc_html__( 'Pie', 'visualizer' ),
140+
'enabled' => true,
141+
),
142+
'line' => array(
143+
'name' => esc_html__( 'Line', 'visualizer' ),
144+
'enabled' => true,
145+
),
146+
'area' => array(
147+
'name' => esc_html__( 'Area', 'visualizer' ),
148+
'enabled' => true,
149+
),
150+
'geo' => array(
151+
'name' => esc_html__( 'Geo', 'visualizer' ),
152+
'enabled' => true,
153+
),
154+
'bar' => array(
155+
'name' => esc_html__( 'Bar', 'visualizer' ),
156+
'enabled' => true,
157+
),
158+
'column' => array(
159+
'name' => esc_html__( 'Column', 'visualizer' ),
160+
'enabled' => true,
161+
),
162+
'gauge' => array(
163+
'name' => esc_html__( 'Gauge', 'visualizer' ),
164+
'enabled' => true,
165+
),
166+
'scatter' => array(
167+
'name' => esc_html__( 'Scatter', 'visualizer' ),
168+
'enabled' => true,
169+
),
170+
'candlestick' => array(
171+
'name' => esc_html__( 'Candlestick', 'visualizer' ),
172+
'enabled' => true,
173+
),
147174
// pro types
148-
'table' => array( 'name' => esc_html__( 'Table', 'visualizer' ), 'enabled' => false ),
149-
'timeline' => array( 'name' => esc_html__( 'Timeline', 'visualizer' ), 'enabled' => false ),
150-
'combo' => array( 'name' => esc_html__( 'Combo', 'visualizer' ), 'enabled' => false ),
175+
'table' => array(
176+
'name' => esc_html__( 'Table', 'visualizer' ),
177+
'enabled' => false,
178+
),
179+
'timeline' => array(
180+
'name' => esc_html__( 'Timeline', 'visualizer' ),
181+
'enabled' => false,
182+
),
183+
'combo' => array(
184+
'name' => esc_html__( 'Combo', 'visualizer' ),
185+
'enabled' => false,
186+
),
151187
);
152188

153189
$types = apply_filters( 'visualizer_pro_chart_types', $types );

classes/Visualizer/Module/Chart.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ public function deleteChart() {
171171
$nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
172172
$capable = current_user_can( 'delete_posts' );
173173
if ( $nonce && $capable ) {
174-
$chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
174+
$chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array(
175+
'options' => array(
176+
'min_range' => 1,
177+
),
178+
) );
175179
if ( $chart_id ) {
176180
$chart = get_post( $chart_id );
177181
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -183,7 +187,9 @@ public function deleteChart() {
183187
}
184188

185189
if ( $is_post ) {
186-
self::_sendResponse( array( 'success' => $success ) );
190+
self::_sendResponse( array(
191+
'success' => $success,
192+
) );
187193
}
188194

189195
wp_redirect( wp_get_referer() );
@@ -222,7 +228,9 @@ public function renderChartPages() {
222228
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
223229
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
224230
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
225-
add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array( 'focusTarget' => 'datum' ) );
231+
add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
232+
'focusTarget' => 'datum',
233+
) );
226234
}
227235

228236
wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
@@ -497,7 +505,11 @@ public function cloneChart() {
497505
$nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
498506
$capable = current_user_can( 'edit_posts' );
499507
if ( $nonce && $capable ) {
500-
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
508+
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
509+
'options' => array(
510+
'min_range' => 1,
511+
),
512+
) );
501513
if ( $chart_id ) {
502514
$chart = get_post( $chart_id );
503515
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -545,7 +557,11 @@ public function exportData() {
545557
$chart_id = $success = false;
546558
$capable = current_user_can( 'edit_posts' );
547559
if ( $capable ) {
548-
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) ) : '';
560+
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
561+
'options' => array(
562+
'min_range' => 1,
563+
),
564+
) ) : '';
549565
if ( $chart_id ) {
550566
$chart = get_post( $chart_id );
551567
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;

classes/Visualizer/Module/Frontend.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public function renderChart( $atts ) {
151151

152152
// enqueue visualizer render and update render localizations
153153
wp_enqueue_script( 'visualizer-render' );
154-
wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
154+
wp_localize_script( 'visualizer-render', 'visualizer', array(
155+
'charts' => $this->_charts,
156+
) );
155157

156158
// return placeholder div
157159
return '<div id="' . $id . '"' . $class . '></div>';

classes/Visualizer/Render/Library.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ private function _renderLibrary() {
9696
echo '<ul class="subsubsub">';
9797
foreach ( $this->types as $type => $array ) {
9898
$label = $array['name'];
99-
$link = '<a class=" " href="' . esc_url( add_query_arg( array( 'type' => $type, 'vpage' => false ) ) ) . '">';
99+
$link = '<a class=" " href="' . esc_url( add_query_arg( array(
100+
'type' => $type,
101+
'vpage' => false,
102+
) ) ) . '">';
100103
if ( ! $array['enabled'] ) {
101104
$link = "<a class=' visualizer-pro-only' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>";
102105
}

classes/Visualizer/Render/Page/Update.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ protected function _toHTML() {
5656
global $Visualizer_Pro;
5757
$Visualizer_Pro->_addUpdateHook( $this->series, $this->data );
5858
}
59-
// Added by Ash/Upwork
6059
} else {
6160
echo 'alert("', $this->message, '");';
6261
}

languages/visualizer.pot

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ msgid ""
44
msgstr ""
55
"Project-Id-Version: Visualizer: Charts and Graphs Lite 2.0.0\n"
66
"Report-Msgid-Bugs-To: https://github.com/Codeinwp/visualizer/issues\n"
7-
"POT-Creation-Date: 2017-03-30 07:48:39+00:00\n"
7+
"POT-Creation-Date: 2017-03-30 09:59:57+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"
@@ -36,93 +36,93 @@ msgstr ""
3636
msgid "Create New"
3737
msgstr ""
3838

39-
#: classes/Visualizer/Module/Admin.php:138
39+
#: classes/Visualizer/Module/Admin.php:139
4040
msgid "Pie"
4141
msgstr ""
4242

43-
#: classes/Visualizer/Module/Admin.php:139
43+
#: classes/Visualizer/Module/Admin.php:143
4444
msgid "Line"
4545
msgstr ""
4646

47-
#: classes/Visualizer/Module/Admin.php:140
47+
#: classes/Visualizer/Module/Admin.php:147
4848
msgid "Area"
4949
msgstr ""
5050

51-
#: classes/Visualizer/Module/Admin.php:141
51+
#: classes/Visualizer/Module/Admin.php:151
5252
msgid "Geo"
5353
msgstr ""
5454

55-
#: classes/Visualizer/Module/Admin.php:142
55+
#: classes/Visualizer/Module/Admin.php:155
5656
msgid "Bar"
5757
msgstr ""
5858

59-
#: classes/Visualizer/Module/Admin.php:143
59+
#: classes/Visualizer/Module/Admin.php:159
6060
msgid "Column"
6161
msgstr ""
6262

63-
#: classes/Visualizer/Module/Admin.php:144
63+
#: classes/Visualizer/Module/Admin.php:163
6464
msgid "Gauge"
6565
msgstr ""
6666

67-
#: classes/Visualizer/Module/Admin.php:145
67+
#: classes/Visualizer/Module/Admin.php:167
6868
msgid "Scatter"
6969
msgstr ""
7070

71-
#: classes/Visualizer/Module/Admin.php:146
71+
#: classes/Visualizer/Module/Admin.php:171
7272
msgid "Candlestick"
7373
msgstr ""
7474

75-
#: classes/Visualizer/Module/Admin.php:148
75+
#: classes/Visualizer/Module/Admin.php:176
7676
msgid "Table"
7777
msgstr ""
7878

79-
#: classes/Visualizer/Module/Admin.php:149
79+
#: classes/Visualizer/Module/Admin.php:180
8080
msgid "Timeline"
8181
msgstr ""
8282

83-
#: classes/Visualizer/Module/Admin.php:150
83+
#: classes/Visualizer/Module/Admin.php:184
8484
msgid "Combo"
8585
msgstr ""
8686

87-
#: classes/Visualizer/Module/Admin.php:253
88-
#: classes/Visualizer/Render/Library.php:169
87+
#: classes/Visualizer/Module/Admin.php:289
88+
#: classes/Visualizer/Render/Library.php:172
8989
msgid "Visualizer Library"
9090
msgstr ""
9191

92-
#: classes/Visualizer/Module/Admin.php:385
92+
#: classes/Visualizer/Module/Admin.php:421
9393
msgid "Library"
9494
msgstr ""
9595

96-
#: classes/Visualizer/Module/Admin.php:410
96+
#: classes/Visualizer/Module/Admin.php:446
9797
msgid "Knowledge Base"
9898
msgstr ""
9999

100-
#: classes/Visualizer/Module/Admin.php:415
100+
#: classes/Visualizer/Module/Admin.php:451
101101
msgid "Pro Addon"
102102
msgstr ""
103103

104-
#: classes/Visualizer/Module/Chart.php:327
105-
#: classes/Visualizer/Module/Chart.php:390
104+
#: classes/Visualizer/Module/Chart.php:335
105+
#: classes/Visualizer/Module/Chart.php:398
106106
msgid "You have entered invalid URL. Please, insert proper URL."
107107
msgstr ""
108108

109-
#: classes/Visualizer/Module/Chart.php:404
109+
#: classes/Visualizer/Module/Chart.php:412
110110
msgid "Save Chart"
111111
msgstr ""
112112

113-
#: classes/Visualizer/Module/Chart.php:405
113+
#: classes/Visualizer/Module/Chart.php:413
114114
msgid "Create Chart"
115115
msgstr ""
116116

117-
#: classes/Visualizer/Module/Chart.php:407
117+
#: classes/Visualizer/Module/Chart.php:415
118118
msgid "Insert Chart"
119119
msgstr ""
120120

121-
#: classes/Visualizer/Module/Chart.php:465
121+
#: classes/Visualizer/Module/Chart.php:473
122122
msgid "CSV file with chart data was not uploaded. Please, try again."
123123
msgstr ""
124124

125-
#: classes/Visualizer/Module/Chart.php:480
125+
#: classes/Visualizer/Module/Chart.php:488
126126
msgid "CSV file is broken or invalid. Please, try again."
127127
msgstr ""
128128

@@ -156,20 +156,20 @@ msgstr ""
156156
msgid "Click to select"
157157
msgstr ""
158158

159-
#: classes/Visualizer/Render/Library.php:119
159+
#: classes/Visualizer/Render/Library.php:122
160160
msgid "Search"
161161
msgstr ""
162162

163-
#: classes/Visualizer/Render/Library.php:141
163+
#: classes/Visualizer/Render/Library.php:144
164164
#: classes/Visualizer/Render/Templates.php:85
165165
msgid "No charts found"
166166
msgstr ""
167167

168-
#: classes/Visualizer/Render/Library.php:170
168+
#: classes/Visualizer/Render/Library.php:173
169169
msgid "Add New"
170170
msgstr ""
171171

172-
#: classes/Visualizer/Render/Library.php:189
172+
#: classes/Visualizer/Render/Library.php:192
173173
msgid ""
174174
"%s option is disabled in your php.ini config. Please, enable it by change "
175175
"its value to 1. This option increases the speed of remote CSV uploading."

tests/bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ function _pro_exists( $only_check = true ) {
4747
global $current_user;
4848
$current_user = new WP_User( 1 );
4949
$current_user->set_role( 'administrator' );
50-
wp_update_user( array( 'ID' => 1, 'first_name' => 'Admin', 'last_name' => 'User' ) );
50+
wp_update_user( array(
51+
'ID' => 1,
52+
'first_name' => 'Admin',
53+
'last_name' => 'User',
54+
) );

tests/test-export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function test_download_export() {
7676
$this->_handleAjax( 'visualizer-export-data' );
7777
} catch ( WPAjaxDieContinueException $e ) {
7878
// We expected this, do nothing.
79-
} catch ( WPAjaxDieStopException $ee) {
79+
} catch ( WPAjaxDieStopException $ee ) {
8080
// We expected this, do nothing.
8181
}
8282
ob_end_clean();

tests/test-import.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function test_url_import( $url, $content, $series ) {
8181
$this->_handleAjax( 'visualizer-upload-data' );
8282
} catch ( WPAjaxDieContinueException $e ) {
8383
// We expected this, do nothing.
84-
} catch ( WPAjaxDieStopException $ee) {
84+
} catch ( WPAjaxDieStopException $ee ) {
8585
// We expected this, do nothing.
8686
}
8787
ob_end_clean();
@@ -126,7 +126,7 @@ public function test_file_import( $file, $content, $series ) {
126126
$this->_handleAjax( 'visualizer-upload-data' );
127127
} catch ( WPAjaxDieContinueException $e ) {
128128
// We expected this, do nothing.
129-
} catch ( WPAjaxDieStopException $ee) {
129+
} catch ( WPAjaxDieStopException $ee ) {
130130
// We expected this, do nothing.
131131
}
132132
ob_end_clean();
@@ -171,7 +171,7 @@ public function test_pro_editor( $data, $content ) {
171171
$this->_handleAjax( 'visualizer-upload-data' );
172172
} catch ( WPAjaxDieContinueException $e ) {
173173
// We expected this, do nothing.
174-
} catch ( WPAjaxDieStopException $ee) {
174+
} catch ( WPAjaxDieStopException $ee ) {
175175
// We expected this, do nothing.
176176
}
177177
ob_end_clean();
@@ -206,7 +206,7 @@ public function test_pro_fetch_from_chart() {
206206
$this->_handleAjax( 'visualizer-fetch-data' );
207207
} catch ( WPAjaxDieContinueException $e ) {
208208
// We expected this, do nothing.
209-
} catch ( WPAjaxDieStopException $ee) {
209+
} catch ( WPAjaxDieStopException $ee ) {
210210
// We expected this, do nothing.
211211
}
212212
ob_end_clean();
@@ -286,7 +286,14 @@ public function urlProvider() {
286286
list($content, $series) = $this->parseFile( $file );
287287
unlink( $file );
288288
return array(
289-
array( $url, array( 'source' => $url, 'data' => $content ), $series ),
289+
array(
290+
$url,
291+
array(
292+
'source' => $url,
293+
'data' => $content,
294+
),
295+
$series,
296+
),
290297
);
291298
}
292299

0 commit comments

Comments
 (0)