Your IP : 216.73.216.114


Current Path : /home/ereika83/www/wp-content/plugins/edit-flow/tests/
Upload File :
Current File : /home/ereika83/www/wp-content/plugins/edit-flow/tests/test-edit-flow-custom-status-ajax.php

<?php

/**
 * @runTestsInSeparateProcesses
 * @preserveGlobalState disabled
 */
class WP_Test_Edit_Flow_Custom_Status_Ajax extends WP_Edit_Flow_Ajax_UnitTestCase {

	function setUp() {
		parent::setUp();

		require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
	}

	/**
	 * A post with 'future' status should not have post_date_gmt
	 * altered when an autosave occurs
	 */
	function test_autosave_post() {
		$admin_user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
		// The original post_author
		wp_set_current_user( $admin_user_id );

		$user = new WP_User( $admin_user_id );

		$future_date = strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) );
		$post = $this->factory->post->create_and_get( array(
			'post_author' => $admin_user_id,
			'post_status' => 'future',
			'post_content' => rand_str(),
			'post_title' => rand_str(),
			'post_date'  => $future_date,
			'post_date_gmt' => $future_date
		) );

		// Set up the $_POST request
		$md5 = md5( uniqid() );
		$_POST = array(
			'action' =>	'heartbeat',
			'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
			'data' => array(
				'wp_autosave' => array(
				    'post_id'       => $post->ID,
				    '_wpnonce'      => wp_create_nonce( 'update-post_' . $post->ID ),
				    'post_content'  => $post->post_content . PHP_EOL . $md5,
					'post_type'     => 'post',
				),
			),
		);

		try {
			$this->_handleAjax( 'heartbeat' );
		} catch ( WPAjaxDieContinueException $e ) {
			unset( $e );
		}

		// Get the response, it is in heartbeat's response
		$response = json_decode( $this->_last_response, true );

		// Ensure everything is correct
		$this->assertNotEmpty( $response['wp_autosave'] );
		$this->assertTrue( $response['wp_autosave']['success'] );

		$autoSavedPost = get_post( $post->ID );
		$this->assertEquals( $autoSavedPost->post_date_gmt, $future_date );
	}
}