Changeset 48220
- Timestamp:
- 06/30/2020 12:41:30 AM (5 years ago)
- Location:
- trunk/tests/phpunit/tests/ajax
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/Autosave.php
r47198 r48220 40 40 41 41 /** 42 * Set up the test fixture42 * Sets up the test fixture. 43 43 */ 44 44 public function setUp() { … … 49 49 50 50 /** 51 * Test autosaving a post 52 * 53 * @return void 51 * Tests autosaving a post. 54 52 */ 55 53 public function test_autosave_post() { … … 92 90 93 91 /** 94 * Test autosaving a locked post 95 * 96 * @return void 92 * Tests autosaving a locked post. 97 93 */ 98 94 public function test_autosave_locked_post() { … … 145 141 146 142 /** 147 * Test with an invalid nonce 148 * 149 * @return void 143 * Tests with an invalid nonce. 150 144 */ 151 145 public function test_with_invalid_nonce() { -
trunk/tests/phpunit/tests/ajax/DeleteComment.php
r47198 r48220 17 17 18 18 /** 19 * List of comments 19 * List of comments. 20 20 * 21 21 * @var array … … 38 38 39 39 /** 40 * Clear the POST actions in between requests40 * Clears the POST actions in between requests. 41 41 */ 42 42 protected function _clear_post_action() { … … 54 54 55 55 /** 56 * Test as a privilged user (administrator)57 * Expects test to pass58 * 59 * @param mixed $comment Comment object60 * @param string action trash, untrash, etc.61 * @ return void56 * Tests as a privileged user (administrator). 57 * 58 * Expects test to pass. 59 * 60 * @param WP_Comment $comment Comment object. 61 * @param string $action Action: 'trash', 'untrash', etc. 62 62 */ 63 63 public function _test_as_admin( $comment, $action ) { … … 113 113 114 114 /** 115 * Test as a non-privileged user (subscriber)116 * Expects test to fail117 * 118 * @param mixed $comment Comment object119 * @param string action trash, untrash, etc.120 * @ return void115 * Tests as a non-privileged user (subscriber). 116 * 117 * Expects test to fail. 118 * 119 * @param WP_Comment $comment Comment object. 120 * @param string $action Action: 'trash', 'untrash', etc. 121 121 */ 122 122 public function _test_as_subscriber( $comment, $action ) { … … 144 144 145 145 /** 146 * Test with a bad nonce147 * Expects test to fail148 * 149 * @param mixed $comment Comment object150 * @param string action trash, untrash, etc.151 * @ return void146 * Tests with a bad nonce. 147 * 148 * Expects test to fail. 149 * 150 * @param WP_Comment $comment Comment object. 151 * @param string $action Action: 'trash', 'untrash', etc. 152 152 */ 153 153 public function _test_with_bad_nonce( $comment, $action ) { … … 174 174 175 175 /** 176 * Test with a bad id177 * Expects test to fail178 * 179 * @param mixed $comment Comment object180 * @param string action trash, untrash, etc.181 * @ return void176 * Tests with a bad ID. 177 * 178 * Expects test to fail. 179 * 180 * @param WP_Comment $comment Comment object. 181 * @param string $action Action: 'trash', 'untrash', etc. 182 182 */ 183 183 public function _test_with_bad_id( $comment, $action ) { … … 211 211 212 212 /** 213 * Test doubling the action (e.g. trash a trashed comment)214 * Expects test to fail215 * 216 * @param mixed $comment Comment object217 * @param string action trash, untrash, etc.218 * @ return void213 * Tests doubling the action (e.g. trash a trashed comment). 214 * 215 * Expects test to fail. 216 * 217 * @param WP_Comment $comment Comment object. 218 * @param string $action Action: 'trash', 'untrash', etc. 219 219 */ 220 220 public function _test_double_action( $comment, $action ) { … … 261 261 262 262 /** 263 * Delete a comment as an administrator (expects success) 264 * 265 * @return void 263 * Deletes a comment as an administrator (expects success). 266 264 */ 267 265 public function test_ajax_comment_trash_actions_as_administrator() { … … 279 277 280 278 /** 281 * Delete a comment as a subscriber (expects permission denied) 282 * 283 * @return void 279 * Deletes a comment as a subscriber (expects permission denied). 284 280 */ 285 281 public function test_ajax_comment_trash_actions_as_subscriber() { … … 297 293 298 294 /** 299 * Delete a comment with no id 300 * 301 * @return void 295 * Deletes a comment with no ID. 302 296 */ 303 297 public function test_ajax_trash_comment_no_id() { … … 315 309 316 310 /** 317 * Delete a comment with a bad nonce 318 * 319 * @return void 311 * Deletes a comment with a bad nonce. 320 312 */ 321 313 public function test_ajax_trash_comment_bad_nonce() { … … 333 325 334 326 /** 335 * Test trashing an already trashed comment, etc. 336 * 337 * @return void 327 * Tests trashing an already trashed comment, etc. 338 328 */ 339 329 public function test_ajax_trash_double_action() { -
trunk/tests/phpunit/tests/ajax/DimComment.php
r47198 r48220 17 17 18 18 /** 19 * List of comments 19 * List of comments. 20 20 * 21 21 * @var array … … 24 24 25 25 /** 26 * Set up the test fixture26 * Sets up the test fixture. 27 27 */ 28 28 public function setUp() { … … 34 34 35 35 /** 36 * Clear the POST actions in between requests36 * Clears the POST actions in between requests. 37 37 */ 38 38 protected function _clear_post_action() { … … 47 47 48 48 /** 49 * Test as a privilged user (administrator)50 * Expects test to pass51 * 52 * @param mixed $comment Comment object53 * @ return void49 * Tests as a privileged user (administrator). 50 * 51 * Expects test to pass. 52 * 53 * @param WP_Comment $comment Comment object. 54 54 */ 55 55 public function _test_as_admin( $comment ) { … … 108 108 109 109 /** 110 * Test as a non-privileged user (subscriber)111 * Expects test to fail112 * 113 * @param mixed $comment Comment object114 * @ return void110 * Tests as a non-privileged user (subscriber). 111 * 112 * Expects test to fail. 113 * 114 * @param WP_Comment $comment Comment object. 115 115 */ 116 116 public function _test_as_subscriber( $comment ) { … … 136 136 137 137 /** 138 * Test with a bad nonce139 * Expects test to fail140 * 141 * @param mixed $comment Comment object142 * @ return void138 * Tests with a bad nonce. 139 * 140 * Expects test to fail. 141 * 142 * @param WP_Comment $comment Comment object. 143 143 */ 144 144 public function _test_with_bad_nonce( $comment ) { … … 164 164 165 165 /** 166 * Test with a bad id 167 * Expects test to fail 168 * 169 * @return void 166 * Tests with a bad ID. 167 * 168 * Expects test to fail. 170 169 */ 171 170 public function test_with_bad_id() { … … 205 204 206 205 /** 207 * Dim a comment as an administrator (expects success) 208 * 209 * @return void 206 * Dims a comment as an administrator (expects success). 210 207 */ 211 208 public function test_ajax_comment_dim_actions_as_administrator() { … … 216 213 217 214 /** 218 * Dim a comment as a subscriber (expects permission denied) 219 * 220 * @return void 215 * Dims a comment as a subscriber (expects permission denied). 221 216 */ 222 217 public function test_ajax_comment_dim_actions_as_subscriber() { … … 226 221 227 222 /** 228 * Dim a comment with no id 229 * 230 * @return void 223 * Dims a comment with no ID. 231 224 */ 232 225 public function test_ajax_dim_comment_no_id() { … … 236 229 237 230 /** 238 * Dim a comment with a bad nonce 239 * 240 * @return void 231 * Dims a comment with a bad nonce. 241 232 */ 242 233 public function test_ajax_dim_comment_bad_nonce() { -
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 } -
trunk/tests/phpunit/tests/ajax/GetComments.php
r47198 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 * A post with no comments 26 * A post with no comments. 27 27 * 28 28 * @var mixed … … 39 39 40 40 /** 41 * Get comments as a privilged user (administrator) 42 * Expects test to pass 41 * Gets comments as a privileged user (administrator). 43 42 * 44 * @return void43 * Expects test to pass. 45 44 */ 46 45 public function test_as_admin() { … … 77 76 78 77 /** 79 * Get comments as a non-privileged user (subscriber) 80 * Expects test to fail 78 * Gets comments as a non-privileged user (subscriber). 81 79 * 82 * @return void80 * Expects test to fail. 83 81 */ 84 82 public function test_as_subscriber() { … … 98 96 99 97 /** 100 * Get comments with a bad nonce 101 * Expects test to fail 98 * Gets comments with a bad nonce. 102 99 * 103 * @return void100 * Expects test to fail. 104 101 */ 105 102 public function test_bad_nonce() { … … 119 116 120 117 /** 121 * Get comments for an invalid post 122 * Bad post IDs are set to 0, this should return valid XML 118 * Gets comments for an invalid post. 123 119 * 124 * @return void120 * Bad post IDs are set to 0, this should return valid XML. 125 121 */ 126 122 public function test_invalid_post() { … … 140 136 141 137 /** 142 * Get comments for an invalid post 143 * Bad post IDs are set to 0, this should return valid XML 144 * 145 * @return void 138 * Gets comments for a post with no comments. 146 139 */ 147 140 public function test_post_with_no_comments() { -
trunk/tests/phpunit/tests/ajax/ReplytoComment.php
r48115 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 * Draft post 26 * Draft post. 27 27 * 28 28 * @var mixed … … 44 44 45 45 /** 46 * Reply as a privilged user (administrator) 47 * Expects test to pass 48 * 49 * @return void 46 * Tests reply as a privileged user (administrator). 47 * 48 * Expects test to pass. 50 49 */ 51 50 public function test_as_admin() { … … 91 90 92 91 /** 93 * Reply as a non-privileged user (subscriber) 94 * Expects test to fail 95 * 96 * @return void 92 * Tests reply as a non-privileged user (subscriber). 93 * 94 * Expects test to fail. 97 95 */ 98 96 public function test_as_subscriber() { … … 121 119 122 120 /** 123 * Reply using a bad nonce 124 * Expects test to fail 125 * 126 * @return void 121 * Tests reply using a bad nonce. 122 * 123 * Expects test to fail. 127 124 */ 128 125 public function test_bad_nonce() { … … 151 148 152 149 /** 153 * Reply to an invalid post 154 * Expects test to fail 155 * 156 * @return void 150 * Tests reply to an invalid post. 151 * 152 * Expects test to fail. 157 153 */ 158 154 public function test_invalid_post() { … … 172 168 173 169 /** 174 * Reply to a draft post 175 * Expects test to fail 176 * 177 * @return void 170 * Tests reply to a draft post. 171 * 172 * Expects test to fail. 178 173 */ 179 174 public function test_with_draft_post() { … … 193 188 194 189 /** 195 * Reply to a post with a simulated database failure 196 * Expects test to fail 190 * Tests reply to a post with a simulated database failure. 191 * 192 * Expects test to fail. 197 193 * 198 194 * @global $wpdb 199 * @return void200 195 */ 201 196 public function test_blocked_comment() { … … 226 221 227 222 /** 228 * Block comments from being saved223 * Blocks comments from being saved. 229 224 * 230 225 * @param string $sql … … 240 235 241 236 /** 242 * Raises WP_Error after Posted a new pre comment237 * Tests blocking a comment from being saved on 'pre_comment_approved'. 243 238 * 244 239 * @ticket 39730 245 * @return void246 240 */ 247 241 public function test_pre_comments_approved() { … … 264 258 265 259 /** 266 * Block comments from being saved 'pre_comment_approved', by returning WP_Error260 * Blocks comments from being saved on 'pre_comment_approved', by returning WP_Error. 267 261 */ 268 262 function _pre_comment_approved_filter( $approved, $commentdata ) {
Note: See TracChangeset
for help on using the changeset viewer.