Changeset 1253 in tests
- Timestamp:
- 04/03/2013 06:19:54 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/ajax/Autosave.php
r967 r1253 33 33 34 34 /** 35 * Test autosaving as a logged out user36 * @return void37 */38 public function test_nopriv_autosave() {39 40 // Log out41 wp_logout();42 43 // Set up a default request44 $_POST = array(45 'post_ID' => 1,46 'autosave' => 147 );48 49 // Make the request50 try {51 $this->_handleAjax( 'nopriv_autosave' );52 } catch ( WPAjaxDieContinueException $e ) {53 unset( $e );54 }55 56 // Get the response57 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );58 59 // Ensure everything is correct60 $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 id66 * @return void67 */68 public function test_nopriv_no_postid() {69 70 // Log out71 wp_logout();72 73 // Set up a request74 $_POST = array(75 'autosave' => 176 );77 78 // Make the request79 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );80 $this->_handleAjax( 'nopriv_autosave' );81 }82 83 /**84 35 * Test autosaving a post 85 36 * @return void … … 93 44 $md5 = md5( uniqid() ); 94 45 $_POST = array( 95 'post_ ID' => $this->_post->ID,46 'post_id' => $this->_post->ID, 96 47 'autosavenonce' => wp_create_nonce( 'autosave' ), 97 48 'post_content' => $this->_post->post_content . PHP_EOL . $md5, 98 'autosave' => 1 49 'post_type' => 'post', 50 'autosave' => 1, 99 51 ); 100 52 … … 129 81 // Set up the $_POST request 130 82 $_POST = array( 131 'post_ ID' => $this->_post->ID,83 'post_id' => $this->_post->ID, 132 84 'autosavenonce' => md5( uniqid() ), 133 85 'autosave' => 1 … … 150 102 // Set up the $_POST request 151 103 $_POST = array( 152 'post_ ID' => 0,104 'post_id' => 0, 153 105 'autosavenonce' => wp_create_nonce( 'autosave' ), 154 'autosave' => 1 106 'autosave' => 1, 107 'post_type' => 'post' 155 108 ); 156 109 … … 159 112 $this->_handleAjax( 'autosave' ); 160 113 } 161 162 /**163 * Test with a locked post164 * @return void165 */166 public function test_locked_post() {167 168 // Become an administrator169 $this->_setRole( 'administrator' );170 171 // Lock the post172 wp_set_post_lock( $this->_post->ID );173 174 // Become a different administrator175 $this->_setRole( 'administrator' );176 177 // Set up the $_POST request178 $_POST = array(179 'post_ID' => $this->_post->ID,180 'autosavenonce' => wp_create_nonce( 'autosave' ),181 'autosave' => 1182 );183 184 // Make the request185 try {186 $this->_handleAjax( 'autosave' );187 } catch ( WPAjaxDieContinueException $e ) {188 unset( $e );189 }190 191 // Get the response192 $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );193 194 // Ensure everything is correct195 $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 out203 * @return void204 */205 public function test_past_grace_period() {206 global $login_grace_period;207 $login_grace_period = 1;208 209 // Become an admnistrator210 $this->_setRole( 'administrator' );211 212 // Set up the $_POST request213 $_POST = array(214 'post_ID' => $this->_post->ID,215 'autosavenonce' => wp_create_nonce( 'autosave' ),216 'autosave' => 1217 );218 219 // Make the request220 try {221 $this->_handleAjax( 'autosave' );222 } catch ( WPAjaxDieContinueException $e ) {223 unset( $e );224 }225 226 // Look for the warning227 $this->assertRegExp( '/Your login has expired. Please open a new browser window/' , $this->_last_response );228 }229 114 }
Note: See TracChangeset
for help on using the changeset viewer.