Changeset 42343 for trunk/tests/phpunit/tests/ajax/DeleteComment.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/DeleteComment.php
r42342 r42343 18 18 /** 19 19 * List of comments 20 * 20 21 * @var array 21 22 */ … … 24 25 /** 25 26 * ID of a post. 27 * 26 28 * @var int 27 29 */ … … 31 33 self::$post_id = $factory->post->create(); 32 34 33 $comment_ids = $factory->comment->create_post_comments( self::$post_id, 8 );35 $comment_ids = $factory->comment->create_post_comments( self::$post_id, 8 ); 34 36 self::$comments = array_map( 'get_comment', $comment_ids ); 35 37 } … … 39 41 */ 40 42 protected function _clear_post_action() { 41 unset( $_POST['trash']);42 unset( $_POST['untrash']);43 unset( $_POST['spam']);44 unset( $_POST['unspam']);45 unset( $_POST['delete']);43 unset( $_POST['trash'] ); 44 unset( $_POST['untrash'] ); 45 unset( $_POST['spam'] ); 46 unset( $_POST['unspam'] ); 47 unset( $_POST['delete'] ); 46 48 $this->_last_response = ''; 47 49 } … … 54 56 * Test as a privilged user (administrator) 55 57 * Expects test to pass 58 * 56 59 * @param mixed $comment Comment object 57 60 * @param string action trash, untrash, etc. … … 69 72 $_POST['id'] = $comment->comment_ID; 70 73 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); 71 $_POST[ $action]= 1;74 $_POST[ $action ] = 1; 72 75 $_POST['_total'] = count( self::$comments ); 73 76 $_POST['_per_page'] = 100; … … 95 98 $total = $_POST['_total'] - 1; 96 99 97 // unspam, untrash should make the total go up100 // unspam, untrash should make the total go up 98 101 } elseif ( in_array( $action, array( 'untrash', 'unspam' ) ) ) { 99 102 $total = $_POST['_total'] + 1; … … 102 105 // The total is calculated based on a page break -OR- a random number. Let's look for both possible outcomes 103 106 $comment_count = wp_count_comments( 0 ); 104 $recalc_total = $comment_count->total_comments;107 $recalc_total = $comment_count->total_comments; 105 108 106 109 // Check for either possible total 107 $message = sprintf( 'returned value: %1$d $total: %2$d $recalc_total: %3$d', (int) 108 $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0] 110 $message = sprintf( 'returned value: %1$d $total: %2$d $recalc_total: %3$d', (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], $total, $recalc_total ); 111 $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ), $message ); 109 112 } 110 113 … … 112 115 * Test as a non-privileged user (subscriber) 113 116 * Expects test to fail 117 * 114 118 * @param mixed $comment Comment object 115 119 * @param string action trash, untrash, etc. … … 127 131 $_POST['id'] = $comment->comment_ID; 128 132 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); 129 $_POST[ $action]= 1;133 $_POST[ $action ] = 1; 130 134 $_POST['_total'] = count( self::$comments ); 131 135 $_POST['_per_page'] = 100; … … 142 146 * Test with a bad nonce 143 147 * Expects test to fail 148 * 144 149 * @param mixed $comment Comment object 145 150 * @param string action trash, untrash, etc. … … 157 162 $_POST['id'] = $comment->comment_ID; 158 163 $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() ); 159 $_POST[ $action]= 1;164 $_POST[ $action ] = 1; 160 165 $_POST['_total'] = count( self::$comments ); 161 166 $_POST['_per_page'] = 100; … … 171 176 * Test with a bad id 172 177 * Expects test to fail 178 * 173 179 * @param mixed $comment Comment object 174 180 * @param string action trash, untrash, etc. … … 186 192 $_POST['id'] = 12346789; 187 193 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' ); 188 $_POST[ $action]= 1;194 $_POST[ $action ] = 1; 189 195 $_POST['_total'] = count( self::$comments ); 190 196 $_POST['_per_page'] = 100; … … 207 213 * Test doubling the action (e.g. trash a trashed comment) 208 214 * Expects test to fail 215 * 209 216 * @param mixed $comment Comment object 210 217 * @param string action trash, untrash, etc. … … 222 229 $_POST['id'] = $comment->comment_ID; 223 230 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); 224 $_POST[ $action]= 1;231 $_POST[ $action ] = 1; 225 232 $_POST['_total'] = count( self::$comments ); 226 233 $_POST['_per_page'] = 100; … … 255 262 /** 256 263 * Delete a comment as an administrator (expects success) 264 * 257 265 * @return void 258 266 */ … … 272 280 /** 273 281 * Delete a comment as a subscriber (expects permission denied) 282 * 274 283 * @return void 275 284 */ … … 289 298 /** 290 299 * Delete a comment with no id 300 * 291 301 * @return void 292 302 */ … … 306 316 /** 307 317 * Delete a comment with a bad nonce 318 * 308 319 * @return void 309 320 */ … … 323 334 /** 324 335 * Test trashing an already trashed comment, etc. 336 * 325 337 * @return void 326 338 */
Note: See TracChangeset
for help on using the changeset viewer.