Changeset 7803
- Timestamp:
- 10/04/2026 09:31:30 AM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/replies/functions/reply.php
r7727 r7803 10 10 class BBP_Tests_Replies_Functions_Reply extends BBP_UnitTestCase { 11 11 12 private function assert_reply_action( $function, $hook ) { 13 $topic_id = $this->factory->topic->create(); 14 $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 15 $seen = array(); 16 $callback = function ( $id ) use ( &$seen ) { 17 $seen[] = $id; 18 }; 19 add_action( $hook, $callback ); 20 21 try { 22 $this->assertFalse( $function( PHP_INT_MAX ) ); 23 $function( $reply_id ); 24 $this->assertSame( array( $reply_id ), $seen ); 25 } finally { 26 remove_action( $hook, $callback ); 27 } 28 } 29 12 30 /** 13 31 * @group canonical … … 76 94 /** 77 95 * @covers ::bbp_update_reply 78 * @todo Implement test_bbp_update_reply().79 96 */ 80 97 public function test_bbp_update_reply() { 81 // Remove the following lines when you implement this test. 82 $this->markTestIncomplete( 83 'This test has not been implemented yet.' 84 ); 98 $old_user = get_current_user_id(); 99 $user_id = $this->factory->user->create(); 100 $forum_id = $this->factory->forum->create(); 101 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 102 $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) ); 103 update_post_meta( $reply_id, '_edit_lock', 'stale' ); 104 delete_post_meta( $reply_id, '_bbp_forum_id' ); 105 delete_post_meta( $reply_id, '_bbp_topic_id' ); 106 $this->set_current_user( $user_id ); 107 108 try { 109 bbp_update_reply( $reply_id, $topic_id, $forum_id, array(), $user_id, true ); 110 $this->assertSame( (string) $user_id, get_post_meta( $reply_id, '_edit_last', true ) ); 111 $this->assertFalse( metadata_exists( 'post', $reply_id, '_edit_lock' ) ); 112 $this->assertSame( (string) $forum_id, get_post_meta( $reply_id, '_bbp_forum_id', true ) ); 113 $this->assertSame( (string) $topic_id, get_post_meta( $reply_id, '_bbp_topic_id', true ) ); 114 delete_post_meta( $reply_id, '_bbp_author_ip' ); 115 bbp_update_reply( $reply_id, $topic_id, $forum_id, array(), $user_id, false ); 116 $this->assertNotEmpty( get_post_meta( $reply_id, '_bbp_author_ip', true ) ); 117 } finally { 118 $this->set_current_user( $old_user ); 119 } 85 120 } 86 121 … … 233 268 /** 234 269 * @covers ::bbp_update_reply_revision_log 235 * @todo Implement test_bbp_update_reply_revision_log().236 270 */ 237 271 public function test_bbp_update_reply_revision_log() { 238 // Remove the following lines when you implement this test. 239 $this->markTestIncomplete( 240 'This test has not been implemented yet.' 241 ); 272 $topic_id = $this->factory->topic->create(); 273 $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 274 $user_id = $this->factory->user->create(); 275 $log = bbp_update_reply_revision_log( array( 'reply_id' => $reply_id, 'author_id' => $user_id, 'revision_id' => 17, 'reason' => 'Clarify wording' ) ); 276 $this->assertSame( $user_id, $log[17]['author'] ); 277 $this->assertSame( 'Clarify wording', $log[17]['reason'] ); 278 $this->assertSame( $log, bbp_get_reply_raw_revision_log( $reply_id ) ); 242 279 } 243 280 … … 391 428 /** 392 429 * @covers ::bbp_delete_reply 393 * @todo Implement test_bbp_delete_reply().394 430 */ 395 431 public function test_bbp_delete_reply() { 396 // Remove the following lines when you implement this test. 397 $this->markTestIncomplete( 398 'This test has not been implemented yet.' 399 ); 432 $this->assert_reply_action( 'bbp_delete_reply', 'bbp_delete_reply' ); 400 433 } 401 434 402 435 /** 403 436 * @covers ::bbp_trash_reply 404 * @todo Implement test_bbp_trash_reply().405 437 */ 406 438 public function test_bbp_trash_reply() { 407 // Remove the following lines when you implement this test. 408 $this->markTestIncomplete( 409 'This test has not been implemented yet.' 410 ); 439 $this->assert_reply_action( 'bbp_trash_reply', 'bbp_trash_reply' ); 411 440 } 412 441 413 442 /** 414 443 * @covers ::bbp_untrash_reply 415 * @todo Implement test_bbp_untrash_reply().416 444 */ 417 445 public function test_bbp_untrash_reply() { 418 // Remove the following lines when you implement this test. 419 $this->markTestIncomplete( 420 'This test has not been implemented yet.' 421 ); 446 $this->assert_reply_action( 'bbp_untrash_reply', 'bbp_untrash_reply' ); 422 447 } 423 448 424 449 /** 425 450 * @covers ::bbp_deleted_reply 426 * @todo Implement test_bbp_deleted_reply().427 451 */ 428 452 public function test_bbp_deleted_reply() { 429 // Remove the following lines when you implement this test. 430 $this->markTestIncomplete( 431 'This test has not been implemented yet.' 432 ); 453 $this->assert_reply_action( 'bbp_deleted_reply', 'bbp_deleted_reply' ); 433 454 } 434 455 435 456 /** 436 457 * @covers ::bbp_trashed_reply 437 * @todo Implement test_bbp_trashed_reply().438 458 */ 439 459 public function test_bbp_trashed_reply() { 440 // Remove the following lines when you implement this test. 441 $this->markTestIncomplete( 442 'This test has not been implemented yet.' 443 ); 460 $this->assert_reply_action( 'bbp_trashed_reply', 'bbp_trashed_reply' ); 444 461 } 445 462 446 463 /** 447 464 * @covers ::bbp_untrashed_reply 448 * @todo Implement test_bbp_untrashed_reply().449 465 */ 450 466 public function test_bbp_untrashed_reply() { 451 // Remove the following lines when you implement this test. 452 $this->markTestIncomplete( 453 'This test has not been implemented yet.' 454 ); 467 $this->assert_reply_action( 'bbp_untrashed_reply', 'bbp_untrashed_reply' ); 455 468 } 456 469 457 470 /** 458 471 * @covers ::bbp_get_replies_per_page 459 * @todo Implement test_bbp_get_replies_per_page().460 472 */ 461 473 public function test_bbp_get_replies_per_page() { 462 // Remove the following lines when you implement this test.463 $this-> markTestIncomplete(464 'This test has not been implemented yet.'465 );474 update_option( '_bbp_replies_per_page', 0 ); 475 $this->assertSame( 12, bbp_get_replies_per_page( 12 ) ); 476 update_option( '_bbp_replies_per_page', '22' ); 477 $this->assertSame( 22, bbp_get_replies_per_page() ); 466 478 } 467 479 468 480 /** 469 481 * @covers ::bbp_get_replies_per_rss_page 470 * @todo Implement test_bbp_get_replies_per_rss_page().471 482 */ 472 483 public function test_bbp_get_replies_per_rss_page() { 473 // Remove the following lines when you implement this test.474 $this-> markTestIncomplete(475 'This test has not been implemented yet.'476 );484 update_option( '_bbp_replies_per_rss_page', 0 ); 485 $this->assertSame( 18, bbp_get_replies_per_rss_page( 18 ) ); 486 update_option( '_bbp_replies_per_rss_page', '30' ); 487 $this->assertSame( 30, bbp_get_replies_per_rss_page() ); 477 488 } 478 489 479 490 /** 480 491 * @covers ::bbp_reply_content_autoembed 481 * @todo Implement test_bbp_reply_content_autoembed().482 492 */ 483 493 public function test_bbp_reply_content_autoembed() { 484 // Remove the following lines when you implement this test. 485 $this->markTestIncomplete( 486 'This test has not been implemented yet.' 487 ); 494 global $wp_embed; 495 496 $callback = array( $wp_embed, 'autoembed' ); 497 $priority = has_filter( 'bbp_get_reply_content', $callback ); 498 remove_filter( 'bbp_get_reply_content', $callback, $priority ); 499 add_filter( 'bbp_use_autoembed', '__return_false' ); 500 501 try { 502 bbp_reply_content_autoembed(); 503 $this->assertFalse( has_filter( 'bbp_get_reply_content', $callback ) ); 504 remove_filter( 'bbp_use_autoembed', '__return_false' ); 505 add_filter( 'bbp_use_autoembed', '__return_true' ); 506 bbp_reply_content_autoembed(); 507 $this->assertSame( 2, has_filter( 'bbp_get_reply_content', $callback ) ); 508 } finally { 509 remove_filter( 'bbp_use_autoembed', '__return_false' ); 510 remove_filter( 'bbp_use_autoembed', '__return_true' ); 511 remove_filter( 'bbp_get_reply_content', $callback, 2 ); 512 if ( false !== $priority ) { 513 add_filter( 'bbp_get_reply_content', $callback, $priority ); 514 } 515 } 488 516 } 489 517 490 518 /** 491 519 * @covers ::_bbp_has_replies_where 492 * @todo Implement test_bbp_has_replies_where().493 520 */ 494 521 public function test_bbp_has_replies_where() { 495 // Remove the following lines when you implement this test. 496 $this->markTestIncomplete( 497 'This test has not been implemented yet.' 498 ); 522 $topic_id = $this->factory->topic->create(); 523 $posts = bbp_db()->prefix . 'posts'; 524 $where = "WHERE 1=1 AND {$posts}.post_parent = {$topic_id}"; 525 $query = new WP_Query(); 526 $query->set( 'post_parent', $topic_id ); 527 $query->set( 'post_type', array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ); 528 529 $this->assertSame( $where, _bbp_has_replies_where( $where, false ) ); 530 $this->assertSame( "WHERE 1=1 AND ({$posts}.ID = {$topic_id} OR {$posts}.post_parent = {$topic_id})", _bbp_has_replies_where( $where, $query ) ); 531 $query->set( 'post__in', array( $topic_id ) ); 532 $this->assertSame( $where, _bbp_has_replies_where( $where, $query ) ); 499 533 } 500 534 … … 534 568 /** 535 569 * @covers ::bbp_get_reply_position_raw 536 * @todo Implement test_bbp_get_reply_position_raw().537 570 */ 538 571 public function test_bbp_get_reply_position_raw() { 539 // Remove the following lines when you implement this test. 540 $this->markTestIncomplete( 541 'This test has not been implemented yet.' 542 ); 572 $topic_id = $this->factory->topic->create(); 573 $first_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 574 $next_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) ); 575 $this->assertSame( 0, bbp_get_reply_position_raw( $topic_id, $topic_id ) ); 576 $this->assertSame( 1, bbp_get_reply_position_raw( $first_id, $topic_id ) ); 577 $this->assertSame( 2, bbp_get_reply_position_raw( $next_id, $topic_id ) ); 543 578 } 544 579
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)