Changeset 48220 for trunk/tests/phpunit/tests/ajax/EditComment.php
- Timestamp:
- 06/30/2020 12:41:30 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/EditComment.php
r48217 r48220 17 17 18 18 /** 19 * A post with at least one comment 19 * A post with at least one comment. 20 20 * 21 21 * @var mixed … … 24 24 25 25 /** 26 * Set up the test fixture26 * Sets up the test fixture. 27 27 */ 28 28 public function setUp() { … … 39 39 40 40 /** 41 * Get comments as a privilged user (administrator) 42 * Expects test to pass 43 * 44 * @return void 41 * Gets comments as a privileged user (administrator). 42 * 43 * Expects test to pass. 45 44 */ 46 45 public function test_as_admin() { … … 133 132 134 133 /** 134 * Gets comments as a non-privileged user (subscriber). 135 * 136 * Expects test to fail. 137 */ 138 public function test_as_subscriber() { 139 140 // Become a subscriber. 141 $this->_setRole( 'subscriber' ); 142 143 // Get a comment. 144 $comments = get_comments( 145 array( 146 'post_id' => $this->_comment_post->ID, 147 ) 148 ); 149 $comment = array_pop( $comments ); 150 151 // Set up a default request. 152 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 153 $_POST['comment_ID'] = $comment->comment_ID; 154 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 155 156 // Make the request. 157 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 158 $this->_handleAjax( 'edit-comment' ); 159 } 160 161 /** 162 * Gets comments with a bad nonce. 163 * 164 * Expects test to fail. 165 */ 166 public function test_bad_nonce() { 167 168 // Become an administrator. 169 $this->_setRole( 'administrator' ); 170 171 // Get a comment. 172 $comments = get_comments( 173 array( 174 'post_id' => $this->_comment_post->ID, 175 ) 176 ); 177 $comment = array_pop( $comments ); 178 179 // Set up a default request. 180 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() ); 181 $_POST['comment_ID'] = $comment->comment_ID; 182 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 183 184 // Make the request. 185 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 186 $this->_handleAjax( 'get-comments' ); 187 } 188 189 /** 190 * Gets comments for an invalid post. 191 * 192 * This should return valid XML. 193 */ 194 public function test_invalid_comment() { 195 196 // Become an administrator. 197 $this->_setRole( 'administrator' ); 198 199 // Set up a default request. 200 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 201 $_POST['comment_ID'] = 123456789; 202 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 203 204 // Make the request. 205 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 206 $this->_handleAjax( 'edit-comment' ); 207 } 208 209 /** 135 210 * @ticket 39732 136 211 */ 137 212 public function test_wp_update_comment_data_is_wp_error() { 138 // Become an administrator 139 $this->_setRole( 'administrator' ); 140 141 // Get a comment 142 $comments = get_comments( 143 array( 144 'post_id' => $this->_comment_post->ID, 145 ) 146 ); 147 $comment = array_pop( $comments ); 148 149 // Set up a default request 150 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 151 $_POST['comment_ID'] = $comment->comment_ID; 152 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 153 154 // Simulate filter check error 213 // Become an administrator. 214 $this->_setRole( 'administrator' ); 215 216 // Get a comment. 217 $comments = get_comments( 218 array( 219 'post_id' => $this->_comment_post->ID, 220 ) 221 ); 222 $comment = array_pop( $comments ); 223 224 // Set up a default request. 225 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 226 $_POST['comment_ID'] = $comment->comment_ID; 227 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 228 229 // Simulate filter check error. 155 230 add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 156 231 157 // Make the request 232 // Make the request. 158 233 $this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' ); 159 234 $this->_handleAjax( 'edit-comment' ); … … 161 236 162 237 /** 163 * Block comments from being updated by returning WP_Error238 * Blocks comments from being updated by returning WP_Error. 164 239 */ 165 240 public function _wp_update_comment_data_filter( $data, $comment, $commentarr ) { 166 241 return new WP_Error( 'comment_wrong', 'wp_update_comment_data filter fails for this comment.', 500 ); 167 242 } 168 169 /**170 * Get comments as a non-privileged user (subscriber)171 * Expects test to fail172 *173 * @return void174 */175 public function test_as_subscriber() {176 177 // Become a subscriber.178 $this->_setRole( 'subscriber' );179 180 // Get a comment.181 $comments = get_comments(182 array(183 'post_id' => $this->_comment_post->ID,184 )185 );186 $comment = array_pop( $comments );187 188 // Set up a default request.189 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );190 $_POST['comment_ID'] = $comment->comment_ID;191 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';192 193 // Make the request.194 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );195 $this->_handleAjax( 'edit-comment' );196 }197 198 /**199 * Get comments with a bad nonce200 * Expects test to fail201 *202 * @return void203 */204 public function test_bad_nonce() {205 206 // Become an administrator.207 $this->_setRole( 'administrator' );208 209 // Get a comment.210 $comments = get_comments(211 array(212 'post_id' => $this->_comment_post->ID,213 )214 );215 $comment = array_pop( $comments );216 217 // Set up a default request.218 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() );219 $_POST['comment_ID'] = $comment->comment_ID;220 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';221 222 // Make the request.223 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );224 $this->_handleAjax( 'get-comments' );225 }226 227 /**228 * Get comments for an invalid post229 * This should return valid XML230 *231 * @return void232 */233 public function test_invalid_comment() {234 235 // Become an administrator.236 $this->_setRole( 'administrator' );237 238 // Set up a default request.239 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );240 $_POST['comment_ID'] = 123456789;241 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';242 243 // Make the request.244 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );245 $this->_handleAjax( 'edit-comment' );246 }247 243 }
Note: See TracChangeset
for help on using the changeset viewer.