forked from Codeinwp/visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-export.php
More file actions
92 lines (82 loc) · 2.01 KB
/
Copy pathtest-export.php
File metadata and controls
92 lines (82 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Test class for the exporting features.
*
* @package Visualizer
* @subpackage Tests
* @copyright Copyright (c) 2017, Marius Cristea
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.0.0
*/
class Test_Export extends WP_Ajax_UnitTestCase {
/**
* The chart id of the chart created
*
* @since 2.0.0
*
* @access private
* @var int
*/
private $chart;
/**
* Create a chart
*
* @since 2.0.0
*
* @access private
*/
private function create_chart() {
$this->_setRole( 'administrator' );
$_GET = array(
'library' => 'yes',
'tab' => 'visualizer',
);
// swallow the output
ob_start();
try {
$this->_handleAjax( 'visualizer-create-chart' );
} catch ( WPAjaxDieContinueException $e ) {
// We expected this, do nothing.
} catch ( WPAjaxDieStopException $ee ) {
// We expected this, do nothing.
}
ob_end_clean();
$query = new WP_Query(
array(
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
'post_status' => 'auto-draft',
'numberposts' => 1,
'fields' => 'ids',
)
);
$this->chart = $query->posts[0];
}
/**
* Testing export
*
* @access public
*/
public function test_download_export() {
$this->create_chart();
$this->_setRole( 'administrator' );
$_GET = array(
'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ),
'chart' => $this->chart,
);
// swallow the output
ob_start();
try {
$this->_handleAjax( 'visualizer-export-data' );
} catch ( WPAjaxDieContinueException $e ) {
// We expected this, do nothing.
} catch ( WPAjaxDieStopException $ee ) {
// We expected this, do nothing.
}
ob_end_clean();
$response = json_decode( $this->_last_response );
$this->assertIsObject( $response );
$this->assertObjectHasAttribute( 'success', $response );
$this->assertObjectHasAttribute( 'data', $response );
$this->assertTrue( $response->success );
}
}