Skip to content

Commit 2236d8e

Browse files
make sure edit data is working as before #48
1 parent 0511105 commit 2236d8e

File tree

6 files changed

+128
-19
lines changed

6 files changed

+128
-19
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,9 @@ public function uploadData() {
462462
$source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
463463
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
464464
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
465-
466465
// 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'] );
466+
} elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
467+
$source = apply_filters( 'visualizer_pro_handle_chart_data', '', $_POST['chart_data'] );
470468
// Added by Ash/Upwork
471469
} else {
472470
$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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,15 @@ class="visualizer-select">
163163
<h2 class="group-title sub-group visualizer-editor-tab"
164164
data-current="chart"><?php _e( 'Edit current data', 'visualizer' ); ?><span
165165
class="dashicons dashicons-lock"></span></h2>
166+
<form id="editor-form" action="<?php echo $upload_link?>" method="post" target="thehole">
167+
<input type="hidden" id="chart-data" name="chart_data">
168+
</form>
169+
166170
<div class="group-content edit-data-content">
167171
<div>
168-
169172
<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' ); ?>" >
173+
<input type="button" id="editor-chart-button" class="button button-primary "
174+
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' );?>">
172175

173176
<?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
174177
</div>

languages/visualizer.pot

Lines changed: 16 additions & 12 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-16 05:02:53+00:00\n"
7+
"POT-Creation-Date: 2017-03-16 09:39:48+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"
@@ -118,19 +118,19 @@ msgstr ""
118118
msgid "Insert Chart"
119119
msgstr ""
120120

121-
#: classes/Visualizer/Module/Chart.php:472
121+
#: classes/Visualizer/Module/Chart.php:470
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:485
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

@@ -290,27 +290,31 @@ msgstr ""
290290
msgid "Edit current data"
291291
msgstr ""
292292

293-
#: classes/Visualizer/Render/Page/Data.php:169
293+
#: classes/Visualizer/Render/Page/Data.php:172
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:174
298+
msgid "View Editor"
299299
msgstr ""
300300

301-
#: classes/Visualizer/Render/Page/Data.php:181
302-
msgid "Advanced Settings"
301+
#: classes/Visualizer/Render/Page/Data.php:174
302+
msgid "Show Chart"
303303
msgstr ""
304304

305305
#: classes/Visualizer/Render/Page/Data.php:184
306+
msgid "Advanced Settings"
307+
msgstr ""
308+
309+
#: classes/Visualizer/Render/Page/Data.php:187
306310
msgid "Chart Settings"
307311
msgstr ""
308312

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

313-
#: classes/Visualizer/Render/Page/Data.php:214
317+
#: classes/Visualizer/Render/Page/Data.php:217
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 );

tests/test-import.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,88 @@ public function test_file_import( $file ) {
150150
$this->assertEquals( $series, $series_line );
151151
}
152152

153+
/**
154+
* Testing editor feature.
155+
*
156+
* @access public
157+
* @dataProvider editorDataProvider
158+
*/
159+
public function test_pro_editor( $data ) {
160+
if ( ! defined( 'VISUALIZER_PRO_VERSION' ) ) {
161+
$this->markTestSkipped( 'PRO not installed/available, skipping test' );
162+
}
163+
164+
$this->create_chart();
165+
$this->_setRole( 'administrator' );
166+
167+
$_POST = array(
168+
'chart_data' => $data,
169+
);
170+
$_GET = array(
171+
'nonce' => wp_create_nonce(),
172+
'chart' => $this->chart,
173+
);
174+
$_FILES = array();
175+
176+
// swallow the output
177+
ob_start();
178+
try {
179+
$this->_handleAjax( 'visualizer-upload-data' );
180+
} catch ( WPAjaxDieContinueException $e ) {
181+
// We expected this, do nothing.
182+
} catch ( WPAjaxDieStopException $ee) {
183+
// We expected this, do nothing.
184+
}
185+
ob_end_clean();
186+
187+
$chart = get_post( $this->chart );
188+
$content = $chart->post_content;
189+
190+
$content_line = 'a:14:{i:0;a:4:{i:0;s:1:"A";i:1;d:10;i:2;d:10;i:3;d:5;}i:1;a:4:{i:0;s:1:"B";i:1;d:20;i:2;d:5;i:3;d:10;}i:2;a:4:{i:0;s:1:"C";i:1;d:40;i:2;d:10;i:3;d:5;}i:3;a:4:{i:0;s:1:"D";i:1;d:80;i:2;d:5;i:3;d:10;}i:4;a:4:{i:0;s:1:"E";i:1;d:70;i:2;d:10;i:3;d:5;}i:5;a:4:{i:0;s:1:"F";i:1;d:70;i:2;d:5;i:3;d:10;}i:6;a:4:{i:0;s:1:"G";i:1;d:80;i:2;d:10;i:3;d:5;}i:7;a:4:{i:0;s:1:"H";i:1;d:40;i:2;d:5;i:3;d:10;}i:8;a:4:{i:0;s:1:"I";i:1;d:20;i:2;d:10;i:3;d:5;}i:9;a:4:{i:0;s:1:"J";i:1;d:35;i:2;d:5;i:3;d:10;}i:10;a:4:{i:0;s:1:"K";i:1;d:30;i:2;d:10;i:3;d:5;}i:11;a:4:{i:0;s:1:"L";i:1;d:35;i:2;d:5;i:3;d:10;}i:12;a:4:{i:0;s:1:"M";i:1;d:10;i:2;d:10;i:3;d:5;}i:13;a:4:{i:0;s:1:"N";i:1;d:10;i:2;d:5;i:3;d:10;}}';
191+
192+
$this->assertEquals( $content, $content_line );
193+
}
194+
195+
/**
196+
* Provide the "edited" data
197+
*
198+
* @access public
199+
*/
200+
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+
}
227+
228+
$csv = array();
229+
foreach ( $data as $row ) {
230+
$csv[] = '[' . implode( ',', $row ) . ']';
231+
}
232+
$csv = '[' . implode( ',', $csv ) . ']';
233+
return array( array( $csv ) );
234+
}
153235
/**
154236
* Provide the fileURL for uploading the file
155237
*

0 commit comments

Comments
 (0)