Changeset 7812
- Timestamp:
- 10/04/2026 03:28:53 PM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/replies/functions/reply.php
r7807 r7812 68 68 $this->assertSame( $f, bbp_get_reply_forum_id( $r ) ); 69 69 $this->assertSame( $t, bbp_get_reply_topic_id( $r ) ); 70 }71 72 /**73 * @covers ::bbp_new_reply_handler74 * @todo Implement test_bbp_new_reply_handler().75 */76 public function test_bbp_new_reply_handler() {77 // Remove the following lines when you implement this test.78 $this->markTestIncomplete(79 'This test has not been implemented yet.'80 );81 }82 83 /**84 * @covers ::bbp_edit_reply_handler85 * @todo Implement test_bbp_edit_reply_handler().86 */87 public function test_bbp_edit_reply_handler() {88 // Remove the following lines when you implement this test.89 $this->markTestIncomplete(90 'This test has not been implemented yet.'91 );92 70 } 93 71 … … 285 263 286 264 /** 287 * @covers ::bbp_move_reply_handler288 * @todo Implement test_bbp_move_reply_handler().289 */290 public function test_bbp_move_reply_handler() {291 // Remove the following lines when you implement this test.292 $this->markTestIncomplete(293 'This test has not been implemented yet.'294 );295 }296 297 /**298 265 * @covers ::bbp_move_reply_count 299 266 */ … … 422 389 /** 423 390 * @covers ::bbp_toggle_reply_handler 424 * @todo Implement test_bbp_toggle_reply_handler().425 391 */ 426 392 public function test_bbp_toggle_reply_handler() { 427 // Remove the following lines when you implement this test. 428 $this->markTestIncomplete( 429 'This test has not been implemented yet.' 430 ); 393 $forum_id = $this->factory->forum->create(); 394 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 395 $reply_id = $this->factory->reply->create( array( 396 'post_parent' => $topic_id, 397 'post_status' => bbp_get_pending_status_id(), 398 'reply_meta' => array( 'forum_id' => $forum_id, 'topic_id' => $topic_id ), 399 ) ); 400 $old_get = $_GET; 401 $old_request = $_REQUEST; 402 $old_user = get_current_user_id(); 403 $old_errors = bbpress()->errors; 404 $redirect = null; 405 $seen = array(); 406 $prevent_redirect = function ( $location ) use ( &$redirect ) { 407 $redirect = $location; 408 throw new RuntimeException( 'Reply toggle redirect.' ); 409 }; 410 $record_toggle = function ( $status, $data, $action ) use ( &$seen ) { 411 $seen[] = array( $status, $data, $action ); 412 }; 413 414 $_GET = array(); 415 $_REQUEST = array(); 416 bbpress()->errors = new WP_Error(); 417 add_filter( 'wp_redirect', $prevent_redirect ); 418 add_action( 'bbp_toggle_reply_handler', $record_toggle, 10, 3 ); 419 420 try { 421 $this->assertNull( bbp_toggle_reply_handler( 'bbp_toggle_reply_approve' ) ); 422 $_GET['reply_id'] = $reply_id; 423 $this->assertNull( bbp_toggle_reply_handler( 'invalid-action' ) ); 424 $this->assertTrue( bbp_is_reply_pending( $reply_id ) ); 425 426 $_GET['reply_id'] = 999999; 427 bbp_toggle_reply_handler( 'bbp_toggle_reply_approve' ); 428 $this->assertContains( 'bbp_toggle_reply_missing', bbpress()->errors->get_error_codes() ); 429 430 $_GET['reply_id'] = $reply_id; 431 $this->set_current_user( 0 ); 432 bbp_toggle_reply_handler( 'bbp_toggle_reply_approve' ); 433 $this->assertContains( 'bbp_toggle_reply_permission', bbpress()->errors->get_error_codes() ); 434 $this->assertTrue( bbp_is_reply_pending( $reply_id ) ); 435 436 $admin_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 437 bbp_set_user_role( $admin_id, bbp_get_keymaster_role() ); 438 $this->set_current_user( $admin_id ); 439 $_REQUEST['_wpnonce'] = wp_create_nonce( 'approve-' . bbp_get_reply_post_type() . '_' . $reply_id ); 440 try { 441 bbp_toggle_reply_handler( 'bbp_toggle_reply_approve' ); 442 $this->fail( 'Approving the reply should redirect.' ); 443 } catch ( RuntimeException $exception ) { 444 if ( 'Reply toggle redirect.' !== $exception->getMessage() ) { 445 throw $exception; 446 } 447 } 448 $this->assertSame( bbp_get_public_status_id(), get_post_status( $reply_id ) ); 449 $this->assertSame( bbp_get_reply_url( $reply_id ), $redirect ); 450 $this->assertCount( 1, $seen ); 451 $this->assertSame( $reply_id, $seen[0][1]['ID'] ); 452 $this->assertSame( 'bbp_toggle_reply_approve', $seen[0][2] ); 453 } finally { 454 remove_action( 'bbp_toggle_reply_handler', $record_toggle, 10 ); 455 remove_filter( 'wp_redirect', $prevent_redirect ); 456 $_GET = $old_get; 457 $_REQUEST = $old_request; 458 bbpress()->errors = $old_errors; 459 $this->set_current_user( $old_user ); 460 } 431 461 } 432 462 … … 551 581 /** 552 582 * @covers ::bbp_check_reply_edit 553 * @todo Implement test_bbp_check_reply_edit().554 583 */ 555 584 public function test_bbp_check_reply_edit() { 556 // Remove the following lines when you implement this test. 557 $this->markTestIncomplete( 558 'This test has not been implemented yet.' 559 ); 585 $forum_id = $this->factory->forum->create(); 586 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 587 $reply_id = $this->factory->reply->create( array( 588 'post_parent' => $topic_id, 589 'reply_meta' => array( 'forum_id' => $forum_id, 'topic_id' => $topic_id ), 590 ) ); 591 $old_user = get_current_user_id(); 592 $old_reply_id = bbpress()->current_reply_id; 593 $redirect = null; 594 $prevent_redirect = function ( $location ) use ( &$redirect ) { 595 $redirect = $location; 596 throw new RuntimeException( 'Reply edit redirect.' ); 597 }; 598 599 bbpress()->current_reply_id = $reply_id; 600 add_filter( 'wp_redirect', $prevent_redirect ); 601 602 try { 603 $this->set_current_user( 0 ); 604 $this->assertNull( bbp_check_reply_edit() ); 605 $this->assertNull( $redirect ); 606 607 add_filter( 'bbp_is_reply_edit', '__return_true' ); 608 try { 609 bbp_check_reply_edit(); 610 $this->fail( 'Anonymous reply editing should redirect.' ); 611 } catch ( RuntimeException $exception ) { 612 if ( 'Reply edit redirect.' !== $exception->getMessage() ) { 613 throw $exception; 614 } 615 } 616 $this->assertSame( bbp_get_reply_url( $reply_id ), $redirect ); 617 618 $admin_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 619 bbp_set_user_role( $admin_id, bbp_get_keymaster_role() ); 620 $this->set_current_user( $admin_id ); 621 $redirect = null; 622 $this->assertNull( bbp_check_reply_edit() ); 623 $this->assertNull( $redirect ); 624 } finally { 625 remove_filter( 'bbp_is_reply_edit', '__return_true' ); 626 remove_filter( 'wp_redirect', $prevent_redirect ); 627 bbpress()->current_reply_id = $old_reply_id; 628 $this->set_current_user( $old_user ); 629 } 560 630 } 561 631
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)