-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathtest-schedule.php
More file actions
45 lines (39 loc) · 1.63 KB
/
Copy pathtest-schedule.php
File metadata and controls
45 lines (39 loc) · 1.63 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
<?php
/**
* Tests for background/scheduled import behavior.
*
* @package visualizer
* @subpackage Tests
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
/**
* Scheduled/background refresh must still import with no logged-in user (regression for visualizer-pro#590).
*
* ponytail: defines VISUALIZER_DO_NOT_DIE process-wide; isolate this test if one ever needs the exit/die path.
*/
class Test_Visualizer_Schedule extends WP_UnitTestCase {
/**
* Internal upload (no user, VISUALIZER_DO_NOT_DIE set) must still import and persist chart data.
*/
public function test_internal_upload_imports_without_logged_in_user() {
wp_set_current_user( 0 );
$this->assertFalse( current_user_can( 'edit_posts' ), 'precondition: background context has no editing user' );
$chart_id = self::factory()->post->create(
array(
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
'post_status' => 'publish',
'post_content' => 'OLD-CONTENT',
)
);
// mimic Pro's internal invocation; clean superglobals so prior tests don't reroute uploadData().
$_GET = $_POST = $_FILES = array();
define( 'VISUALIZER_DO_NOT_DIE', true );
$_GET['nonce'] = wp_create_nonce( 'visualizer-upload-data' );
$_GET['chart'] = $chart_id;
$_POST['editor-type'] = 'text';
$_POST['chart_data'] = "Name,Value\nstring,number\nAlpha,111\nBeta,222";
do_action( 'wp_ajax_' . Visualizer_Plugin::ACTION_UPLOAD_DATA );
$content = get_post_field( 'post_content', $chart_id );
$this->assertStringContainsString( 'Alpha', $content, 'scheduled/background import must update chart data without a logged-in user' );
}
}