Skip to content

Commit 996bc5b

Browse files
phpunit more tests #142
2 parents 2bf8356 + 1cb2994 commit 996bc5b

File tree

5 files changed

+83
-39
lines changed

5 files changed

+83
-39
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ public function __construct( Visualizer_Plugin $plugin ) {
6161

6262
// Added by Ash/Upwork
6363
$this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' );
64-
if ( defined( 'Visualizer_Pro' ) ) {
65-
global $Visualizer_Pro;
66-
list($action, $name, $class) = $Visualizer_Pro->_getAjaxAction( $this );
67-
$this->_addAjaxAction( $action, $name, $class );
68-
}
6964
// Added by Ash/Upwork
7065
}
7166

@@ -77,12 +72,12 @@ public function __construct( Visualizer_Plugin $plugin ) {
7772
* @access private
7873
* @param array $results The response array.
7974
*/
80-
public function _sendResponse( $results ) {
75+
public static function _sendResponse( $results ) {
8176
header( 'Content-type: application/json' );
8277
nocache_headers();
8378

8479
echo json_encode( $results );
85-
exit;
80+
wp_die();
8681
}
8782

8883
/**
@@ -153,7 +148,7 @@ public function getCharts() {
153148
$charts[] = $chart_data;
154149
}
155150

156-
$this->_sendResponse( array(
151+
self::_sendResponse( array(
157152
'success' => true,
158153
'data' => $charts,
159154
'total' => $query->max_num_pages,
@@ -188,7 +183,7 @@ public function deleteChart() {
188183
}
189184

190185
if ( $is_post ) {
191-
$this->_sendResponse( array( 'success' => $success ) );
186+
self::_sendResponse( array( 'success' => $success ) );
192187
}
193188

194189
wp_redirect( wp_get_referer() );
@@ -462,11 +457,9 @@ public function uploadData() {
462457
$source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
463458
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
464459
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
465-
466460
// Added by Ash/Upwork
467-
} elseif ( defined( 'Visualizer_Pro' ) && isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
468-
global $Visualizer_Pro;
469-
$source = $Visualizer_Pro->_handleChartData( $_POST['chart_data'] );
461+
} elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
462+
$source = apply_filters( 'visualizer_pro_handle_chart_data', '', $_POST['chart_data'] );
470463
// Added by Ash/Upwork
471464
} else {
472465
$render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' );

classes/Visualizer/Module/Sources.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public function filterChartData( $data, $chart_id ) {
133133
* @return string The new html code.
134134
*/
135135
public function addProUpsell( $old ) {
136+
if ( defined( 'Visualizer_Pro' ) ) {
137+
remove_filter( 'visualizer_pro_upsell', 'addProUpsell', 10, 1 );
138+
return;
139+
}
136140
$return = '<div class="only-pro-content">';
137141
$return .= ' <div class="only-pro-container">';
138142
$return .= ' <div class="only-pro-inner">';

classes/Visualizer/Render/Page/Data.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,33 @@ class="dashicons dashicons-lock"></span></h2>
150150
<div>
151151
<p class="group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
152152
<form>
153-
<select name="vz-import-from-chart" id="vz-import-from-chart"
154-
class="visualizer-select">
155-
<option value="#"><?php _e( 'Chart #123', 'visualizer' ); ?></option>
153+
<select name="vz-import-from-chart" id="chart-id" class="visualizer-select">
154+
<?php
155+
$fetch_link = add_query_arg( array(
156+
'action' => Visualizer_Pro::ACTION_FETCH_DATA,
157+
'nonce' => wp_create_nonce(),
158+
), admin_url( 'admin-ajax.php' ) );
159+
160+
$query_args_charts = array(
161+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
162+
'posts_per_page' => -1,
163+
'no_found_rows' => true,
164+
);
165+
$charts = array();
166+
$query = new WP_Query( $query_args_charts );
167+
while ( $query->have_posts() ) {
168+
$chart = $query->next_post();
169+
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
170+
?>
171+
<option value="<?php echo $chart->ID; ?>"><?php echo empty( $settings['title'] ) ? '#' . $chart->ID : $settings['title']; ?></option>
172+
<?php
173+
}
174+
?>
175+
156176
</select>
157177
</form>
178+
<input type="button" id="existing-chart" class="button button-primary"
179+
value="<?php _e( 'Import Chart', 'visualizer' ); ?>" data-viz-link="<?php echo $fetch_link;?>">
158180
<?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
159181
</div>
160182
</div>
@@ -163,12 +185,15 @@ class="visualizer-select">
163185
<h2 class="group-title sub-group visualizer-editor-tab"
164186
data-current="chart"><?php _e( 'Edit current data', 'visualizer' ); ?><span
165187
class="dashicons dashicons-lock"></span></h2>
188+
<form id="editor-form" action="<?php echo $upload_link?>" method="post" target="thehole">
189+
<input type="hidden" id="chart-data" name="chart_data">
190+
</form>
191+
166192
<div class="group-content edit-data-content">
167193
<div>
168-
169194
<p class="group-description"><?php _e( 'You can manually edit the chart data using the spreadsheet like editor.', 'visualizer' ); ?></p>
170-
<input type="button" id="view-editor" class="button button-primary "
171-
value="<?php _e( 'View editor', 'visualizer' ); ?>" >
195+
<input type="button" id="editor-chart-button" class="button button-primary "
196+
value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart" data-t-editor="<?php _e( 'Show Chart', 'visualizer' );?>" data-t-chart="<?php _e( 'View Editor', 'visualizer' );?>">
172197

173198
<?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
174199
</div>

languages/visualizer.pot

Lines changed: 24 additions & 20 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:38:04+00:00\n"
7+
"POT-Creation-Date: 2017-03-16 15:47:05+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"
@@ -101,36 +101,36 @@ msgstr ""
101101
msgid "Pro Addon"
102102
msgstr ""
103103

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

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

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

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

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

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

129-
#: classes/Visualizer/Module/Sources.php:139
129+
#: classes/Visualizer/Module/Sources.php:143
130130
msgid "Enable this feature in PRO version!"
131131
msgstr ""
132132

133-
#: classes/Visualizer/Module/Sources.php:140
133+
#: classes/Visualizer/Module/Sources.php:144
134134
msgid "Buy now"
135135
msgstr ""
136136

@@ -282,35 +282,39 @@ msgstr ""
282282
msgid "You can import here data from your previously created charts"
283283
msgstr ""
284284

285-
#: classes/Visualizer/Render/Page/Data.php:155
286-
msgid "Chart #123"
285+
#: classes/Visualizer/Render/Page/Data.php:179
286+
msgid "Import Chart"
287287
msgstr ""
288288

289-
#: classes/Visualizer/Render/Page/Data.php:164
289+
#: classes/Visualizer/Render/Page/Data.php:186
290290
msgid "Edit current data"
291291
msgstr ""
292292

293-
#: classes/Visualizer/Render/Page/Data.php:169
293+
#: classes/Visualizer/Render/Page/Data.php:194
294294
msgid "You can manually edit the chart data using the spreadsheet like editor."
295295
msgstr ""
296296

297-
#: classes/Visualizer/Render/Page/Data.php:171
298-
msgid "View editor"
297+
#: classes/Visualizer/Render/Page/Data.php:196
298+
msgid "View Editor"
299299
msgstr ""
300300

301-
#: classes/Visualizer/Render/Page/Data.php:181
301+
#: classes/Visualizer/Render/Page/Data.php:196
302+
msgid "Show Chart"
303+
msgstr ""
304+
305+
#: classes/Visualizer/Render/Page/Data.php:206
302306
msgid "Advanced Settings"
303307
msgstr ""
304308

305-
#: classes/Visualizer/Render/Page/Data.php:184
309+
#: classes/Visualizer/Render/Page/Data.php:209
306310
msgid "Chart Settings"
307311
msgstr ""
308312

309-
#: classes/Visualizer/Render/Page/Data.php:195
313+
#: classes/Visualizer/Render/Page/Data.php:220
310314
msgid "Rate our plugin"
311315
msgstr ""
312316

313-
#: classes/Visualizer/Render/Page/Data.php:214
317+
#: classes/Visualizer/Render/Page/Data.php:239
314318
#: classes/Visualizer/Render/Page/Settings.php:55
315319
msgid "Back"
316320
msgstr ""

tests/bootstrap.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,29 @@
2020
*/
2121
function _manually_load_plugin() {
2222
require dirname( dirname( __FILE__ ) ) . '/index.php';
23+
_pro_exists( false );
24+
}
25+
26+
/**
27+
* Load pro if it exists
28+
*/
29+
function _pro_exists( $only_check = true ) {
30+
$pro = dirname( dirname( dirname( __FILE__ ) ) ) . '/visualizer-pro/visualizer-pro.php';
31+
if ( file_exists( $pro ) ) {
32+
if ( ! $only_check ) {
33+
require $pro;
34+
}
35+
return true;
36+
}
37+
return false;
2338
}
2439

2540
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
2641
// Start up the WP testing environment.
2742
require $_tests_dir . '/includes/bootstrap.php';
43+
if ( _pro_exists() ) {
44+
activate_plugin( 'visualizer-pro/visualizer-pro.php' );
45+
}
2846
activate_plugin( 'visualizer/index.php' );
2947
global $current_user;
3048
$current_user = new WP_User( 1 );

0 commit comments

Comments
 (0)