Changeset 7775
- Timestamp:
- 10/04/2026 02:49:39 AM (5 weeks ago)
- Location:
- trunk/tests/phpunit/testcases/forums/template
- Files:
-
- 2 edited
-
counts.php (modified) (1 diff)
-
forum.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/forums/template/counts.php
r7449 r7775 256 256 $this->assertSame( $int_value, $count ); 257 257 } 258 259 /** 260 * @covers ::bbp_forum_reply_count_hidden 261 * @covers ::bbp_get_forum_reply_count_hidden 262 */ 263 public function test_bbp_get_forum_reply_count_hidden() { 264 $forum_id = $this->factory->forum->create(); 265 update_post_meta( $forum_id, '_bbp_reply_count_hidden', 2 ); 266 update_post_meta( $forum_id, '_bbp_total_reply_count_hidden', 5 ); 267 268 $this->assertSame( 2, bbp_get_forum_reply_count_hidden( $forum_id, false, true ) ); 269 $this->assertSame( 5, bbp_get_forum_reply_count_hidden( $forum_id, true, true ) ); 270 271 ob_start(); 272 bbp_forum_reply_count_hidden( $forum_id, false, true ); 273 $this->assertSame( '2', ob_get_clean() ); 274 275 $filter = function( $count, $filtered_forum_id ) use ( $forum_id ) { 276 $this->assertSame( $forum_id, $filtered_forum_id ); 277 return $count + 1; 278 }; 279 add_filter( 'bbp_get_forum_reply_count_hidden_int', $filter, 10, 2 ); 280 try { 281 $this->assertSame( 3, bbp_get_forum_reply_count_hidden( $forum_id, false, true ) ); 282 } finally { 283 remove_filter( 'bbp_get_forum_reply_count_hidden_int', $filter ); 284 } 285 } 258 286 } -
trunk/tests/phpunit/testcases/forums/template/forum.php
r7669 r7775 23 23 /** 24 24 * @covers ::bbp_get_forum 25 * @todo Implement test_bbp_get_forum().26 25 */ 27 26 public function test_bbp_get_forum() { 28 // Remove the following lines when you implement this test. 29 $this->markTestIncomplete( 30 'This test has not been implemented yet.' 31 ); 27 $forum_id = $this->factory->forum->create(); 28 $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) ); 29 $forum = bbp_get_forum( $forum_id ); 30 31 $this->assertInstanceOf( 'WP_Post', $forum ); 32 $this->assertSame( $forum_id, $forum->ID ); 33 $this->assertSame( $forum_id, bbp_get_forum( $forum )->ID ); 34 $this->assertSame( $forum_id, bbp_get_forum( $forum_id, ARRAY_A )['ID'] ); 35 $this->assertSame( array_values( get_object_vars( $forum ) ), bbp_get_forum( $forum_id, ARRAY_N ) ); 36 $this->assertNull( bbp_get_forum( $topic_id ) ); 37 $this->assertNull( bbp_get_forum( 999999 ) ); 32 38 } 33 39 … … 117 123 * @covers ::bbp_forum_archive_title 118 124 * @covers ::bbp_get_forum_archive_title 119 * @todo Implement test_bbp_forum_archive_title().120 * @todo Implement test_bbp_get_forum_archive_title().121 125 */ 122 126 public function test_bbp_get_forum_archive_title() { 123 // Remove the following lines when you implement this test. 124 $this->markTestIncomplete( 125 'This test has not been implemented yet.' 126 ); 127 $title = get_post_type_object( bbp_get_forum_post_type() )->labels->name; 128 129 $this->assertSame( $title, bbp_get_forum_archive_title() ); 130 $this->assertSame( 'Custom archive', bbp_get_forum_archive_title( 'Custom archive' ) ); 131 $this->expectOutputString( 'Custom archive' ); 132 bbp_forum_archive_title( 'Custom archive' ); 127 133 } 128 134 … … 527 533 /** 528 534 * @covers ::bbp_get_forum_ancestors 529 * @todo Implement test_bbp_get_forum_ancestors().530 535 */ 531 536 public function test_bbp_get_forum_ancestors() { 532 // Remove the following lines when you implement this test. 533 $this->markTestIncomplete( 534 'This test has not been implemented yet.' 535 ); 537 $root_id = $this->factory->forum->create(); 538 $parent_id = $this->factory->forum->create( array( 'post_parent' => $root_id ) ); 539 $child_id = $this->factory->forum->create( array( 'post_parent' => $parent_id ) ); 540 541 $this->assertSame( array(), bbp_get_forum_ancestors( $root_id ) ); 542 $this->assertSame( array( $parent_id, $root_id ), bbp_get_forum_ancestors( $child_id ) ); 543 $this->assertSame( array(), bbp_get_forum_ancestors( 999999 ) ); 536 544 } 537 545 538 546 /** 539 547 * @covers ::bbp_forum_get_subforums 540 * @todo Implement test_bbp_forum_get_subforums().541 548 */ 542 549 public function test_bbp_forum_get_subforums() { 543 // Remove the following lines when you implement this test. 544 $this->markTestIncomplete( 545 'This test has not been implemented yet.' 546 ); 550 $parent_id = $this->factory->forum->create(); 551 $first_id = $this->factory->forum->create( array( 'post_parent' => $parent_id, 'post_title' => 'Alpha' ) ); 552 $second_id = $this->factory->forum->create( array( 'post_parent' => $parent_id, 'post_title' => 'Beta' ) ); 553 $this->factory->forum->create(); 554 bbp_update_forum_subforum_count( $parent_id ); 555 556 $this->assertSame( array(), bbp_forum_get_subforums( 999999 ) ); 557 $this->assertSame( array( $first_id, $second_id ), wp_list_pluck( bbp_forum_get_subforums( $parent_id ), 'ID' ) ); 558 $this->assertSame( array( $second_id ), wp_list_pluck( bbp_forum_get_subforums( array( 'post_parent' => $parent_id, 'posts_per_page' => 1, 'order' => 'DESC' ) ), 'ID' ) ); 547 559 } 548 560 549 561 /** 550 562 * @covers ::bbp_list_forums 551 * @todo Implement test_bbp_list_forums().552 563 */ 553 564 public function test_bbp_list_forums() { 554 // Remove the following lines when you implement this test. 555 $this->markTestIncomplete( 556 'This test has not been implemented yet.' 557 ); 565 $parent_id = $this->factory->forum->create(); 566 $child_id = $this->factory->forum->create( array( 'post_parent' => $parent_id, 'post_title' => 'Listed child' ) ); 567 $category_id = $this->factory->forum->create( array( 'post_parent' => $parent_id, 'post_title' => 'Listed category' ) ); 568 bbp_categorize_forum( $category_id ); 569 bbp_update_forum_subforum_count( $parent_id ); 570 571 $this->assertSame( '', bbp_list_forums( array( 'forum_id' => $child_id, 'echo' => false ) ) ); 572 $list = bbp_list_forums( array( 'forum_id' => $parent_id, 'echo' => false, 'show_topic_count' => false, 'show_reply_count' => false ) ); 573 $this->assertStringContainsString( '<ul class="bbp-forums-list">', $list ); 574 $this->assertStringContainsString( 'Listed child', $list ); 575 $this->assertStringContainsString( 'Listed category', $list ); 576 $this->assertStringContainsString( esc_url( bbp_get_forum_permalink( $child_id ) ), $list ); 577 $this->assertStringNotContainsString( ' (0, 0)', $list ); 578 $counted_list = bbp_list_forums( array( 'forum_id' => $parent_id, 'echo' => false ) ); 579 $this->assertStringContainsString( 'Listed child (0, 0)', $counted_list ); 580 $this->assertStringContainsString( 'Listed category</a>', $counted_list ); 581 582 ob_start(); 583 bbp_list_forums( array( 'forum_id' => $parent_id, 'show_topic_count' => false, 'show_reply_count' => false ) ); 584 $this->assertSame( $list, ob_get_clean() ); 558 585 } 559 586 … … 561 588 * @covers ::bbp_forum_subscription_link 562 589 * @covers ::bbp_get_forum_subscription_link 563 * @todo Implement test_bbp_get_forum_subscription_link().564 590 */ 565 591 public function test_bbp_get_forum_subscription_link() { 566 // Remove the following lines when you implement this test. 567 $this->markTestIncomplete( 568 'This test has not been implemented yet.' 569 ); 592 $forum_id = $this->factory->forum->create(); 593 $user_id = $this->factory->user->create( array( 'role' => bbp_get_participant_role() ) ); 594 $this->set_current_user( $user_id ); 595 596 $args = array( 'user_id' => $user_id, 'object_id' => $forum_id ); 597 $this->assertTrue( bbp_is_subscriptions_active() ); 598 $this->assertFalse( bbp_is_forum_category() ); 599 $this->assertTrue( current_user_can( 'read_forum', $forum_id ) ); 600 $this->assertTrue( current_user_can( 'edit_user', $user_id ) ); 601 $link = bbp_get_forum_subscription_link( $args ); 602 $this->assertStringContainsString( 'Subscribe', $link ); 603 $this->assertStringContainsString( 'data-bbp-object-id="' . $forum_id . '"', $link ); 604 $this->assertStringContainsString( 'data-bbp-object-type="post"', $link ); 605 $this->assertTrue( bbp_add_user_subscription( $user_id, $forum_id ) ); 606 $subscribed_link = bbp_get_forum_subscription_link( $args ); 607 $this->assertStringContainsString( 'Unsubscribe', $subscribed_link ); 608 $this->assertStringContainsString( 'is-subscribed', $subscribed_link ); 609 610 ob_start(); 611 bbp_forum_subscription_link( $args ); 612 $this->assertSame( $subscribed_link, ob_get_clean() ); 613 614 $this->set_current_user( 0 ); 615 $this->assertFalse( bbp_get_forum_subscription_link( array( 'object_id' => $forum_id ) ) ); 570 616 } 571 617 … … 573 619 * @covers ::bbp_forum_topics_link 574 620 * @covers ::bbp_get_forum_topics_link 575 * @todo Implement test_bbp_get_forum_topics_link().576 621 */ 577 622 public function test_bbp_get_forum_topics_link() { 578 // Remove the following lines when you implement this test. 579 $this->markTestIncomplete( 580 'This test has not been implemented yet.' 581 ); 623 $forum_id = $this->factory->forum->create(); 624 $this->assertSame( '0 topics', bbp_get_forum_topics_link( $forum_id ) ); 625 626 $this->factory->topic->create( array( 'post_parent' => $forum_id, 'topic_meta' => array( 'forum_id' => $forum_id ) ) ); 627 $this->assertSame( '1 topic', bbp_get_forum_topics_link( $forum_id ) ); 628 629 ob_start(); 630 bbp_forum_topics_link( $forum_id ); 631 $this->assertSame( '1 topic', ob_get_clean() ); 582 632 } 583 633 … … 585 635 * @covers ::bbp_forum_class 586 636 * @covers ::bbp_get_forum_class 587 * @todo Implement test_bbp_get_forum_class().588 637 */ 589 638 public function test_bbp_get_forum_class() { 590 // Remove the following lines when you implement this test. 591 $this->markTestIncomplete( 592 'This test has not been implemented yet.' 593 ); 639 $parent_id = $this->factory->forum->create(); 640 $child_id = $this->factory->forum->create( array( 'post_parent' => $parent_id ) ); 641 bbp_categorize_forum( $child_id ); 642 bbp_close_forum( $child_id ); 643 644 $class = bbp_get_forum_class( $child_id, array( 'custom-forum-class' ) ); 645 $this->assertStringContainsString( 'custom-forum-class', $class ); 646 $this->assertStringContainsString( 'bbp-forum-status-closed', $class ); 647 $this->assertStringContainsString( 'bbp-forum-visibility-publish', $class ); 648 $this->assertStringContainsString( 'status-category', $class ); 649 $this->assertStringContainsString( 'bbp-parent-forum-' . $parent_id, $class ); 650 651 ob_start(); 652 bbp_forum_class( $child_id, array( 'custom-forum-class' ) ); 653 $this->assertSame( $class, ob_get_clean() ); 594 654 } 595 655
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)