@@ -29,28 +29,41 @@ class Test_Import extends WP_Ajax_UnitTestCase {
29
29
* @access private
30
30
*/
31
31
private function create_chart () {
32
- $ id = wp_insert_post (array (
33
- 'post_type ' => 'visualizer ' ,
34
- 'post_content ' => 'a:5:{i:0;a:2:{i:0;s:17:"Work";i:1;d:11;}i:1;a:2:{i:0;s:3:"Eat";i:1;d:2;}i:2;a:2:{i:0;s:7:"Commute";i:1;d:2;}i:3;a:2:{i:0;s:8:"Watch TV";i:1;d:2;}i:4;a:2:{i:0;s:5:"Sleep";i:1;d:7;}} ' ,
35
- 'post_status ' => 'publish ' ,
36
- ));
32
+ $ this ->_setRole ( 'administrator ' );
33
+
34
+ $ _GET = array (
35
+ 'library ' => 'yes ' ,
36
+ 'tab ' => 'visualizer ' ,
37
+ );
37
38
38
- update_post_meta ( $ id , 'visualizer-chart-type ' , 'pie ' );
39
- update_post_meta ( $ id , 'visualizer-series ' , 'a:2:{i:0;a:2:{s:5:"label";s:4:"Task";s:4:"type";s:6:"string";}i:1;a:2:{s:5:"label";s:13:"Hours per Day";s:4:"type";s:6:"number";}} ' );
40
- update_post_meta ( $ id , 'visualizer-default-data ' , 0 );
41
- update_post_meta ( $ id , 'visualizer-source ' , 'Visualizer_Source_Csv ' );
42
- update_post_meta ( $ id , 'visualizer-settings ' , 'a:20:{s:5:"title";s:0:"";s:14:"titleTextStyle";a:1:{s:5:"color";s:4:"#000";}s:8:"fontName";s:0:"";s:8:"fontSize";s:0:"";s:6:"legend";a:3:{s:8:"position";s:4:"left";s:9:"alignment";s:0:"";s:9:"textStyle";a:1:{s:5:"color";s:4:"#000";}}s:7:"tooltip";a:3:{s:7:"trigger";s:0:"";s:13:"showColorCode";s:0:"";s:4:"text";s:0:"";}s:4:"is3D";s:0:"";s:17:"reverseCategories";s:0:"";s:12:"pieSliceText";s:0:"";s:7:"pieHole";s:0:"";s:13:"pieStartAngle";s:0:"";s:19:"pieSliceBorderColor";s:4:"#fff";s:24:"sliceVisibilityThreshold";s:0:"";s:20:"pieResidueSliceLabel";s:0:"";s:20:"pieResidueSliceColor";s:4:"#ccc";s:6:"slices";a:5:{i:0;a:2:{s:6:"offset";s:0:"";s:5:"color";s:0:"";}i:1;a:2:{s:6:"offset";s:0:"";s:5:"color";s:0:"";}i:2;a:2:{s:6:"offset";s:0:"";s:5:"color";s:0:"";}i:3;a:2:{s:6:"offset";s:0:"";s:5:"color";s:0:"";}i:4;a:2:{s:6:"offset";s:0:"";s:5:"color";s:0:"";}}s:5:"width";s:0:"";s:6:"height";s:0:"";s:15:"backgroundColor";a:3:{s:11:"strokeWidth";s:0:"";s:6:"stroke";s:4:"#666";s:4:"fill";s:4:"#fff";}s:9:"chartArea";a:4:{s:4:"left";s:0:"";s:3:"top";s:0:"";s:5:"width";s:0:"";s:6:"height";s:0:"";}} ' );
39
+ // swallow the output
40
+ ob_start ();
41
+ try {
42
+ $ this ->_handleAjax ( 'visualizer-create-chart ' );
43
+ } catch ( WPAjaxDieContinueException $ e ) {
44
+ // We expected this, do nothing.
45
+ } catch ( WPAjaxDieStopException $ ee ) {
46
+ // We expected this, do nothing.
47
+ }
48
+ ob_end_clean ();
43
49
44
- $ this ->chart = $ id ;
50
+ $ query = new WP_Query (array (
51
+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
52
+ 'post_status ' => 'auto-draft ' ,
53
+ 'numberposts ' => 1 ,
54
+ 'fields ' => 'ids ' ,
55
+ ));
56
+ $ this ->chart = $ query ->posts [0 ];
45
57
}
46
58
47
59
/**
48
- * Testing file import feature.
60
+ * Testing url import feature.
49
61
*
50
62
* @access public
51
63
* @dataProvider urlProvider
52
64
*/
53
65
public function test_url_import ( $ url ) {
66
+ $ this ->markTestSkipped ( 'this test is disabled till we can figure out how to provide a "local" url ' );
54
67
$ this ->create_chart ();
55
68
$ this ->_setRole ( 'administrator ' );
56
69
@@ -78,22 +91,80 @@ public function test_url_import( $url ) {
78
91
$ src = get_post_meta ( $ this ->chart , 'visualizer-source ' , true );
79
92
$ content = $ chart ->post_content ;
80
93
81
- $ content_line = 'a:2:{s:6:"source";s:66 :" ' . $ url . '";s:4:"data";a:14 :{i:0;a:4 :{i:0;s:1:"A ";i:1;d:1 ;i:2;d:1 ;i:3;d:0.5;}i:1;a:4:{i:0;s:1:"B";i:1;d:2;i:2;d:0.5;i:3;d:1;}i:2;a:4 :{i:0;s:1:"C ";i:1;d:4 ;i:2;d:1 ;i:3;d:0.5;}i:3;a:4:{i:0;s:1:"D";i:1;d:8; i:2;d:0.5;i:3;d:1;}i:4;a:4: {i:0;s:1:"E ";i:1;d:7 ;i:2;d:1 ;i:3;d:0.5;}i:5;a:4:{i:0;s:1:"F";i:1;d:7;i:2;d:0.5;i:3;d:1;}i:6;a:4 :{i:0;s:1:"G ";i:1;d:8 ;i:2;d:1 ;i:3;d:0.5;}i:7;a:4:{i:0;s:1:"H";i:1;d:4;i:2;d:0.5;i:3;d:1; }i:8 ;a:4 :{i:0;s:1:"I ";i:1;d:2 ;i:2;d:1 ;i:3;d:0.5;}i:9;a:4:{i:0;s:1:"J";i:1;d:3.5;i:2;d:0.5;i:3;d:1;}i:10;a:4:{i:0;s:1:"K";i:1;d:3;i:2;d:1;i:3;d:0.5;}i:11;a:4: {i:0;s:1:"L";i:1;d:3.5;i:2;d:0.5;i:3;d:1;}i:12;a:4:{i:0;s:1:"M ";i:1;d:1 ;i:2;d:1 ;i:3;d:0.5;}i:13;a:4:{i:0;s:1:"N";i:1;d:1;i:2;d:0.5;i:3;d:1 ;}}} ' ;
94
+ $ content_line = 'a:2:{s:6:"source";s: ' . strlen ( $ url ) . ' :" ' . $ url . '";s:4:"data";a:6 :{i:0;a:5 :{i:0;s:4:"2003 ";i:1;d:1336060 ;i:2;d:400361 ;i:3;d:1001582;i:4;d:997974;}i:1;a:5 :{i:0;s:4:"2004 ";i:1;d:1538156 ;i:2;d:366849 ;i:3;d:1119450;i:4;d:941795;} i:2;a:5: {i:0;s:4:"2005 ";i:1;d:1576579 ;i:2;d:440514 ;i:3;d:993360;i:4;d:930593;}i:3;a:5 :{i:0;s:4:"2006 ";i:1;d:1600652 ;i:2;d:434552 ;i:3;d:1004163;i:4;d:897127; }i:4 ;a:5 :{i:0;s:4:"2007 ";i:1;d:1968113 ;i:2;d:393032 ;i:3;d:979198;i:4;d:1080887;}i:5;a:5: {i:0;s:4:"2008 ";i:1;d:1901067 ;i:2;d:517206 ;i:3;d:916965;i:4;d:1056036 ;}}} ' ;
82
95
83
- $ series_line = unserialize ( 'a:4 :{i:0;a:2:{s:5:"label";s:1:"x ";s:4:"type";s:6:"string";}i:1;a:2:{s:5:"label";s:4:"Cats ";s:4:"type";s:6:"number";}i:2;a:2:{s:5:"label";s:8:"Blanket1 ";s:4:"type";s:6:"number";}i:3;a:2:{s:5:"label";s:8:"Blanket2 ";s:4:"type";s:6:"number";}} ' );
96
+ $ series_line = unserialize ( 'a:5 :{i:0;a:2:{s:5:"label";s:4:"Year ";s:4:"type";s:6:"string";}i:1;a:2:{s:5:"label";s:7:"Austria ";s:4:"type";s:6:"number";}i:2;a:2:{s:5:"label";s:8:"Bulgaria ";s:4:"type";s:6:"number";}i:3;a:2:{s:5:"label";s:7:"Denmark";s:4:"type";s:6:"number";}i:4;a:2:{s:5:"label";s:6:"Greece ";s:4:"type";s:6:"number";}} ' );
84
97
85
98
$ this ->assertEquals ( 'Visualizer_Source_Csv_Remote ' , $ src );
86
99
$ this ->assertEquals ( $ content , $ content_line );
87
100
$ this ->assertEquals ( $ series , $ series_line );
88
101
}
89
102
103
+ /**
104
+ * Testing file import feature.
105
+ *
106
+ * @access public
107
+ * @dataProvider fileProvider
108
+ */
109
+ public function test_file_import ( $ file ) {
110
+ $ this ->create_chart ();
111
+ $ this ->_setRole ( 'administrator ' );
112
+
113
+ $ dest = dirname ( __FILE__ ) . DIRECTORY_SEPARATOR . basename ( $ file );
114
+ copy ( $ file , $ dest );
115
+
116
+ $ _FILES = array (
117
+ 'local_data ' => array (
118
+ 'tmp_name ' => $ dest ,
119
+ 'error ' => 0 ,
120
+ ),
121
+ );
122
+ $ _GET = array (
123
+ 'nonce ' => wp_create_nonce (),
124
+ 'chart ' => $ this ->chart ,
125
+ );
126
+
127
+ // swallow the output
128
+ ob_start ();
129
+ try {
130
+ $ this ->_handleAjax ( 'visualizer-upload-data ' );
131
+ } catch ( WPAjaxDieContinueException $ e ) {
132
+ // We expected this, do nothing.
133
+ } catch ( WPAjaxDieStopException $ ee ) {
134
+ // We expected this, do nothing.
135
+ }
136
+ ob_end_clean ();
137
+ unlink ( $ dest );
138
+
139
+ $ series = get_post_meta ( $ this ->chart , 'visualizer-series ' , true );
140
+ $ chart = get_post ( $ this ->chart );
141
+ $ src = get_post_meta ( $ this ->chart , 'visualizer-source ' , true );
142
+ $ content = $ chart ->post_content ;
143
+
144
+ $ content_line = 'a:6:{i:0;a:5:{i:0;s:4:"2003";i:1;d:1336060;i:2;d:400361;i:3;d:1001582;i:4;d:997974;}i:1;a:5:{i:0;s:4:"2004";i:1;d:1538156;i:2;d:366849;i:3;d:1119450;i:4;d:941795;}i:2;a:5:{i:0;s:4:"2005";i:1;d:1576579;i:2;d:440514;i:3;d:993360;i:4;d:930593;}i:3;a:5:{i:0;s:4:"2006";i:1;d:1600652;i:2;d:434552;i:3;d:1004163;i:4;d:897127;}i:4;a:5:{i:0;s:4:"2007";i:1;d:1968113;i:2;d:393032;i:3;d:979198;i:4;d:1080887;}i:5;a:5:{i:0;s:4:"2008";i:1;d:1901067;i:2;d:517206;i:3;d:916965;i:4;d:1056036;}} ' ;
145
+
146
+ $ series_line = unserialize ( 'a:5:{i:0;a:2:{s:5:"label";s:4:"Year";s:4:"type";s:6:"string";}i:1;a:2:{s:5:"label";s:7:"Austria";s:4:"type";s:6:"number";}i:2;a:2:{s:5:"label";s:8:"Bulgaria";s:4:"type";s:6:"number";}i:3;a:2:{s:5:"label";s:7:"Denmark";s:4:"type";s:6:"number";}i:4;a:2:{s:5:"label";s:6:"Greece";s:4:"type";s:6:"number";}} ' );
147
+
148
+ $ this ->assertEquals ( 'Visualizer_Source_Csv ' , $ src );
149
+ $ this ->assertEquals ( $ content , $ content_line );
150
+ $ this ->assertEquals ( $ series , $ series_line );
151
+ }
152
+
153
+ /**
154
+ * Provide the fileURL for uploading the file
155
+ *
156
+ * @access public
157
+ */
158
+ public function fileProvider () {
159
+ return [ [ VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . 'bar.csv ' ] ];
160
+ }
90
161
91
162
/**
92
163
* Provide the URL for uploading the file
93
164
*
94
165
* @access public
95
166
*/
96
167
public function urlProvider () {
97
- return [ [ 'http://localhost/wp-content/plugins/wp-visualizer/samples/line .csv ' ] ];
168
+ return [ [ 'http://localhost/wp-content/plugins/wp-visualizer/samples/bar .csv ' ] ];
98
169
}
99
170
}
0 commit comments