Changeset 35311 for trunk/tests/phpunit/tests/ajax/DeleteComment.php
- Timestamp:
- 10/21/2015 03:17:36 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/DeleteComment.php
r35242 r35311 20 20 * @var array 21 21 */ 22 protected $_comments = array(); 23 24 /** 25 * Set up the test fixture 26 */ 27 public function setUp() { 28 parent::setUp(); 29 $post_id = self::factory()->post->create(); 30 $this->_comments = self::factory()->comment->create_post_comments( $post_id, 15 ); 31 $this->_comments = array_map( 'get_comment', $this->_comments ); 22 protected static $comments = array(); 23 24 protected static $admin_id = 0; 25 protected static $editor_id = 0; 26 protected static $post; 27 protected static $post_id; 28 protected static $user_ids = array(); 29 30 public static function wpSetUpBeforeClass( $factory ) { 31 self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 32 self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 33 34 self::$post_id = $factory->post->create(); 35 self::$post = get_post( self::$post_id ); 36 37 $comment_ids = $factory->comment->create_post_comments( self::$post_id, 8 ); 38 self::$comments = array_map( 'get_comment', $comment_ids ); 39 } 40 41 public static function wpTearDownAfterClass() { 42 foreach ( self::$user_ids as $user_id ) { 43 self::delete_user( $user_id ); 44 } 45 46 wp_delete_post( self::$post_id, true ); 47 48 foreach ( self::$comments as $c ) { 49 wp_delete_comment( $c->ID, true ); 50 } 32 51 } 33 52 … … 67 86 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); 68 87 $_POST[$action] = 1; 69 $_POST['_total'] = count( $this->_comments );88 $_POST['_total'] = count( self::$comments ); 70 89 $_POST['_per_page'] = 100; 71 90 $_POST['_page'] = 1; … … 125 144 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); 126 145 $_POST[$action] = 1; 127 $_POST['_total'] = count( $this->_comments );146 $_POST['_total'] = count( self::$comments ); 128 147 $_POST['_per_page'] = 100; 129 148 $_POST['_page'] = 1; … … 155 174 $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() ); 156 175 $_POST[$action] = 1; 157 $_POST['_total'] = count( $this->_comments );176 $_POST['_total'] = count( self::$comments ); 158 177 $_POST['_per_page'] = 100; 159 178 $_POST['_page'] = 1; … … 184 203 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' ); 185 204 $_POST[$action] = 1; 186 $_POST['_total'] = count( $this->_comments );205 $_POST['_total'] = count( self::$comments ); 187 206 $_POST['_per_page'] = 100; 188 207 $_POST['_page'] = 1; … … 220 239 $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); 221 240 $_POST[$action] = 1; 222 $_POST['_total'] = count( $this->_comments );241 $_POST['_total'] = count( self::$comments ); 223 242 $_POST['_per_page'] = 100; 224 243 $_POST['_page'] = 1; … … 255 274 */ 256 275 public function test_ajax_comment_trash_actions_as_administrator() { 257 258 // Test trash/untrash 259 $comment = array_pop( $this->_comments ); 260 $this->_test_as_admin( $comment, 'trash' ); 261 $this->_test_as_admin( $comment, 'untrash' ); 262 263 // Test spam/unspam 264 $comment = array_pop( $this->_comments ); 265 $this->_test_as_admin( $comment, 'spam' ); 266 $this->_test_as_admin( $comment, 'unspam' ); 267 268 // Test delete 269 $comment = array_pop( $this->_comments ); 270 $this->_test_as_admin( $comment, 'delete' ); 276 // Test trash/untrash 277 $this->_test_as_admin( self::$comments[0], 'trash' ); 278 $this->_test_as_admin( self::$comments[0], 'untrash' ); 279 280 // Test spam/unspam 281 $this->_test_as_admin( self::$comments[1], 'spam' ); 282 $this->_test_as_admin( self::$comments[1], 'unspam' ); 283 284 // Test delete 285 $this->_test_as_admin( self::$comments[2], 'delete' ); 271 286 } 272 287 … … 276 291 */ 277 292 public function test_ajax_comment_trash_actions_as_subscriber() { 278 279 // Test trash/untrash 280 $comment = array_pop( $this->_comments ); 281 $this->_test_as_subscriber( $comment, 'trash' ); 282 $this->_test_as_subscriber( $comment, 'untrash' ); 283 284 // Test spam/unspam 285 $comment = array_pop( $this->_comments ); 286 $this->_test_as_subscriber( $comment, 'spam' ); 287 $this->_test_as_subscriber( $comment, 'unspam' ); 288 289 // Test delete 290 $comment = array_pop( $this->_comments ); 291 $this->_test_as_subscriber( $comment, 'delete' ); 293 // Test trash/untrash 294 $this->_test_as_subscriber( self::$comments[0], 'trash' ); 295 $this->_test_as_subscriber( self::$comments[0], 'untrash' ); 296 297 // Test spam/unspam 298 $this->_test_as_subscriber( self::$comments[1], 'spam' ); 299 $this->_test_as_subscriber( self::$comments[1], 'unspam' ); 300 301 // Test delete 302 $this->_test_as_subscriber( self::$comments[2], 'delete' ); 292 303 } 293 304 … … 297 308 */ 298 309 public function test_ajax_trash_comment_no_id() { 299 300 // Test trash/untrash 301 $comment = array_pop( $this->_comments ); 302 $this->_test_as_admin( $comment, 'trash' ); 303 $this->_test_as_admin( $comment, 'untrash' ); 304 305 // Test spam/unspam 306 $comment = array_pop( $this->_comments ); 307 $this->_test_as_admin( $comment, 'spam' ); 308 $this->_test_as_admin( $comment, 'unspam' ); 309 310 // Test delete 311 $comment = array_pop( $this->_comments ); 312 $this->_test_as_admin( $comment, 'delete' ); 310 // Test trash/untrash 311 $this->_test_as_admin( self::$comments[0], 'trash' ); 312 $this->_test_as_admin( self::$comments[0], 'untrash' ); 313 314 // Test spam/unspam 315 $this->_test_as_admin( self::$comments[1], 'spam' ); 316 $this->_test_as_admin( self::$comments[1], 'unspam' ); 317 318 // Test delete 319 $this->_test_as_admin( self::$comments[2], 'delete' ); 313 320 } 314 321 … … 318 325 */ 319 326 public function test_ajax_trash_comment_bad_nonce() { 320 321 // Test trash/untrash 322 $comment = array_pop( $this->_comments ); 323 $this->_test_with_bad_nonce( $comment, 'trash' ); 324 $this->_test_with_bad_nonce( $comment, 'untrash' ); 325 326 // Test spam/unspam 327 $comment = array_pop( $this->_comments ); 328 $this->_test_with_bad_nonce( $comment, 'spam' ); 329 $this->_test_with_bad_nonce( $comment, 'unspam' ); 330 331 // Test delete 332 $comment = array_pop( $this->_comments ); 333 $this->_test_with_bad_nonce( $comment, 'delete' ); 327 // Test trash/untrash 328 $this->_test_with_bad_nonce( self::$comments[0], 'trash' ); 329 $this->_test_with_bad_nonce( self::$comments[0], 'untrash' ); 330 331 // Test spam/unspam 332 $this->_test_with_bad_nonce( self::$comments[1], 'spam' ); 333 $this->_test_with_bad_nonce( self::$comments[1], 'unspam' ); 334 335 // Test delete 336 $this->_test_with_bad_nonce( self::$comments[2], 'delete' ); 334 337 } 335 338 … … 339 342 */ 340 343 public function test_ajax_trash_double_action() { 341 342 // Test trash/untrash 343 $comment = array_pop( $this->_comments ); 344 $this->_test_double_action( $comment, 'trash' ); 345 $this->_test_double_action( $comment, 'untrash' ); 346 347 // Test spam/unspam 348 $comment = array_pop( $this->_comments ); 349 $this->_test_double_action( $comment, 'spam' ); 350 $this->_test_double_action( $comment, 'unspam' ); 351 352 // Test delete 353 $comment = array_pop( $this->_comments ); 354 $this->_test_double_action( $comment, 'delete' ); 344 // Test trash/untrash 345 $this->_test_double_action( self::$comments[0], 'trash' ); 346 $this->_test_double_action( self::$comments[0], 'untrash' ); 347 348 // Test spam/unspam 349 $this->_test_double_action( self::$comments[1], 'spam' ); 350 $this->_test_double_action( self::$comments[1], 'unspam' ); 351 352 // Test delete 353 $this->_test_double_action( self::$comments[2], 'delete' ); 355 354 } 356 355 }
Note: See TracChangeset
for help on using the changeset viewer.