Make WordPress Core

Changeset 1253 in tests

Timestamp:
04/03/2013 06:19:54 PM (11 years ago)
Author:
kurtpayne
Message:

Update ajax autosave unit tests for 3.6

See #23928

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/ajax/Autosave.php

    r967 r1253  
    3333
    3434    /**
    35      * Test autosaving as a logged out user
    36      * @return void
    37      */
    38     public function test_nopriv_autosave() {
    39 
    40         // Log out
    41         wp_logout();
    42 
    43         // Set up a default request
    44         $_POST = array(
    45             'post_ID'  => 1,
    46             'autosave' => 1
    47         );
    48 
    49         // Make the request
    50         try {
    51             $this->_handleAjax( 'nopriv_autosave' );
    52         } catch ( WPAjaxDieContinueException $e ) {
    53             unset( $e );
    54         }
    55 
    56         // Get the response
    57         $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    58 
    59         // Ensure everything is correct
    60         $this->assertEquals( 1, (string) $xml->response[0]->autosave['id'] );
    61         $this->assertEquals( 'nopriv_autosave_1', (string) $xml->response['action'] );
    62     }
    63 
    64     /**
    65      * Test as a logged out user with no post id
    66      * @return void
    67      */
    68     public function test_nopriv_no_postid() {
    69 
    70         // Log out
    71         wp_logout();
    72 
    73         // Set up a request
    74         $_POST = array(
    75             'autosave'      => 1
    76         );
    77 
    78         // Make the request
    79         $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    80         $this->_handleAjax( 'nopriv_autosave' );
    81     }
    82 
    83     /**
    8435     * Test autosaving a post
    8536     * @return void
     
    9344        $md5 = md5( uniqid() );
    9445        $_POST = array(
    95             'post_ID'       => $this->_post->ID,
     46            'post_'       => $this->_post->ID,
    9647            'autosavenonce' => wp_create_nonce( 'autosave' ),
    9748            'post_content'  => $this->_post->post_content . PHP_EOL . $md5,
    98             'autosave'      => 1
     49            'post_type'     => 'post',
     50            'autosave'      => 1,
    9951        );
    10052
     
    12981        // Set up the $_POST request
    13082        $_POST = array(
    131             'post_ID'       => $this->_post->ID,
     83            'post_'       => $this->_post->ID,
    13284            'autosavenonce' => md5( uniqid() ),
    13385            'autosave'      => 1
     
    150102        // Set up the $_POST request
    151103        $_POST = array(
    152             'post_ID'       => 0,
     104            'post_'       => 0,
    153105            'autosavenonce' => wp_create_nonce( 'autosave' ),
    154             'autosave'      => 1
     106            'autosave'      => 1,
     107            'post_type'     => 'post'
    155108        );
    156109
     
    159112        $this->_handleAjax( 'autosave' );
    160113    }
    161 
    162     /**
    163      * Test with a locked post
    164      * @return void
    165      */
    166     public function test_locked_post() {
    167 
    168         // Become an administrator
    169         $this->_setRole( 'administrator' );
    170 
    171         // Lock the post
    172         wp_set_post_lock( $this->_post->ID );
    173 
    174         // Become a different administrator
    175         $this->_setRole( 'administrator' );
    176 
    177         // Set up the $_POST request
    178         $_POST = array(
    179             'post_ID'       => $this->_post->ID,
    180             'autosavenonce' => wp_create_nonce( 'autosave' ),
    181             'autosave'      => 1
    182         );
    183 
    184         // Make the request
    185         try {
    186             $this->_handleAjax( 'autosave' );
    187         } catch ( WPAjaxDieContinueException $e ) {
    188             unset( $e );
    189         }
    190 
    191         // Get the response
    192         $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    193 
    194         // Ensure everything is correct
    195         $this->assertEquals( $this->_post->ID, (int) $xml->response[0]->autosave['id'] );
    196         $this->assertEquals( 'autosave_' . $this->_post->ID, (string) $xml->response['action']);
    197         $this->assertEquals( 'disable', (string) $xml->response[0]->autosave[0]->supplemental[0]->disable_autosave);
    198     }
    199 
    200 
    201     /**
    202      * Test with a browser that is about to be logged out
    203      * @return void
    204      */
    205     public function test_past_grace_period() {
    206         global $login_grace_period;
    207         $login_grace_period = 1;
    208 
    209         // Become an admnistrator
    210         $this->_setRole( 'administrator' );
    211 
    212         // Set up the $_POST request
    213         $_POST = array(
    214             'post_ID'       => $this->_post->ID,
    215             'autosavenonce' => wp_create_nonce( 'autosave' ),
    216             'autosave'      => 1
    217         );
    218 
    219         // Make the request
    220         try {
    221             $this->_handleAjax( 'autosave' );
    222         } catch ( WPAjaxDieContinueException $e ) {
    223             unset( $e );
    224         }
    225 
    226         // Look for the warning
    227         $this->assertRegExp( '/Your login has expired. Please open a new browser window/' , $this->_last_response );
    228     }
    229114}
Note: See TracChangeset for help on using the changeset viewer.