Skip to:
Content

bbPress.org

Changeset 7800


Ignore:
Timestamp:
10/04/2026 09:18:18 AM (3 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover topic metadata and option helpers.

Replace ten topic-function stubs with assertions for status and type choices, sticky lists, user relationship cleanup, topic IDs, pagination options, and autoembed hooks.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/topics/functions/topic.php

    r7467 r7800  
    426426        /**
    427427         * @covers ::bbp_get_topic_statuses
    428          * @todo   Implement test_bbp_get_topic_statuses().
    429428         */
    430429        public function test_bbp_get_topic_statuses() {
    431                 // Remove the following lines when you implement this test.
    432                 $this->markTestIncomplete(
    433                         'This test has not been implemented yet.'
    434                 );
     430                $statuses = bbp_get_topic_statuses();
     431                $this->assertSame( array( 'Open', 'Closed', 'Spam', 'Trash', 'Pending' ), array_values( $statuses ) );
     432                $this->assertSame( array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ), array_keys( $statuses ) );
    435433        }
    436434
    437435        /**
    438436         * @covers ::bbp_get_topic_types
    439          * @todo   Implement test_bbp_get_topic_types().
    440437         */
    441438        public function test_bbp_get_topic_types() {
    442                 // Remove the following lines when you implement this test.
    443                 $this->markTestIncomplete(
    444                         'This test has not been implemented yet.'
    445                 );
     439                $this->assertSame( array( 'unstick' => 'Normal', 'stick' => 'Sticky', 'super' => 'Super Sticky' ), bbp_get_topic_types() );
    446440        }
    447441
    448442        /**
    449443         * @covers ::bbp_get_stickies
    450          * @todo   Implement test_bbp_get_stickies().
    451444         */
    452445        public function test_bbp_get_stickies() {
    453                 // Remove the following lines when you implement this test.
    454                 $this->markTestIncomplete(
    455                         'This test has not been implemented yet.'
    456                 );
     446                $forum_id = $this->factory->forum->create();
     447                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     448                $this->assertSame( array(), bbp_get_stickies( $forum_id ) );
     449                update_post_meta( $forum_id, '_bbp_sticky_topics', array( (string) $topic_id, (string) $topic_id ) );
     450                $this->assertSame( array( $topic_id ), bbp_get_stickies( $forum_id ) );
    457451        }
    458452
    459453        /**
    460454         * @covers ::bbp_get_super_stickies
    461          * @todo   Implement test_bbp_get_super_stickies().
    462455         */
    463456        public function test_bbp_get_super_stickies() {
    464                 // Remove the following lines when you implement this test.
    465                 $this->markTestIncomplete(
    466                         'This test has not been implemented yet.'
    467                 );
     457                $topic_id = $this->factory->topic->create();
     458                update_option( '_bbp_super_sticky_topics', array( (string) $topic_id, (string) $topic_id ) );
     459                $this->assertSame( array( $topic_id ), bbp_get_super_stickies() );
     460                $this->assertSame( array( $topic_id ), bbp_get_stickies() );
    468461        }
    469462
    … …  
    481474        /**
    482475         * @covers ::bbp_remove_topic_from_all_favorites
    483          * @todo   Implement test_bbp_remove_topic_from_all_favorites().
    484476         */
    485477        public function test_bbp_remove_topic_from_all_favorites() {
    486                 // Remove the following lines when you implement this test.
    487                 $this->markTestIncomplete(
    488                         'This test has not been implemented yet.'
    489                 );
     478                $topic_id = $this->factory->topic->create();
     479                $user_ids = $this->factory->user->create_many( 2 );
     480                foreach ( $user_ids as $user_id ) {
     481                        bbp_add_user_favorite( $user_id, $topic_id );
     482                }
     483                $this->assertEqualSets( $user_ids, bbp_get_topic_favoriters( $topic_id ) );
     484                bbp_remove_topic_from_all_favorites( $topic_id );
     485                $this->assertEmpty( bbp_get_topic_favoriters( $topic_id ) );
    490486        }
    491487
    492488        /**
    493489         * @covers ::bbp_remove_topic_from_all_subscriptions
    494          * @todo   Implement test_bbp_remove_topic_from_all_subscriptions().
    495490         */
    496491        public function test_bbp_remove_topic_from_all_subscriptions() {
    497                 // Remove the following lines when you implement this test.
    498                 $this->markTestIncomplete(
    499                         'This test has not been implemented yet.'
    500                 );
     492                $topic_id = $this->factory->topic->create();
     493                $user_ids = $this->factory->user->create_many( 2 );
     494                foreach ( $user_ids as $user_id ) {
     495                        bbp_add_user_topic_subscription( $user_id, $topic_id );
     496                }
     497                $this->assertEqualSets( $user_ids, bbp_get_topic_subscribers( $topic_id ) );
     498                bbp_remove_topic_from_all_subscriptions( $topic_id );
     499                $this->assertEmpty( bbp_get_topic_subscribers( $topic_id ) );
    501500        }
    502501
    … …  
    529528        /**
    530529         * @covers ::bbp_update_topic_topic_id
    531          * @todo   Implement test_bbp_update_topic_topic_id().
    532530         */
    533531        public function test_bbp_update_topic_topic_id() {
    534                 // Remove the following lines when you implement this test.
    535                 $this->markTestIncomplete(
    536                         'This test has not been implemented yet.'
    537                 );
     532                $topic_id = $this->factory->topic->create();
     533                delete_post_meta( $topic_id, '_bbp_topic_id' );
     534                $this->assertSame( $topic_id, bbp_update_topic_topic_id( $topic_id ) );
     535                $this->assertSame( (string) $topic_id, get_post_meta( $topic_id, '_bbp_topic_id', true ) );
    538536        }
    539537
    … …  
    693691        /**
    694692         * @covers ::bbp_get_topics_per_page
    695          * @todo   Implement test_bbp_get_topics_per_page().
    696693         */
    697694        public function test_bbp_get_topics_per_page() {
    698                 // Remove the following lines when you implement this test.
    699                 $this->markTestIncomplete(
    700                         'This test has not been implemented yet.'
    701                 );
     695                update_option( '_bbp_topics_per_page', 0 );
     696                $this->assertSame( 12, bbp_get_topics_per_page( 12 ) );
     697                update_option( '_bbp_topics_per_page', '22' );
     698                $this->assertSame( 22, bbp_get_topics_per_page() );
    702699        }
    703700
    704701        /**
    705702         * @covers ::bbp_get_topics_per_rss_page
    706          * @todo   Implement test_bbp_get_topics_per_rss_page().
    707703         */
    708704        public function test_bbp_get_topics_per_rss_page() {
    709                 // Remove the following lines when you implement this test.
    710                 $this->markTestIncomplete(
    711                         'This test has not been implemented yet.'
    712                 );
     705                update_option( '_bbp_topics_per_rss_page', 0 );
     706                $this->assertSame( 18, bbp_get_topics_per_rss_page( 18 ) );
     707                update_option( '_bbp_topics_per_rss_page', '30' );
     708                $this->assertSame( 30, bbp_get_topics_per_rss_page() );
    713709        }
    714710
    715711        /**
    716712         * @covers ::bbp_topic_content_autoembed
    717          * @todo   Implement test_bbp_topic_content_autoembed().
    718713         */
    719714        public function test_bbp_topic_content_autoembed() {
    720                 // Remove the following lines when you implement this test.
    721                 $this->markTestIncomplete(
    722                         'This test has not been implemented yet.'
    723                 );
     715                global $wp_embed;
     716
     717                $callback = array( $wp_embed, 'autoembed' );
     718                $priority = has_filter( 'bbp_get_topic_content', $callback );
     719                remove_filter( 'bbp_get_topic_content', $callback, $priority );
     720                add_filter( 'bbp_use_autoembed', '__return_false' );
     721
     722                try {
     723                        bbp_topic_content_autoembed();
     724                        $this->assertFalse( has_filter( 'bbp_get_topic_content', $callback ) );
     725                        remove_filter( 'bbp_use_autoembed', '__return_false' );
     726                        add_filter( 'bbp_use_autoembed', '__return_true' );
     727                        bbp_topic_content_autoembed();
     728                        $this->assertSame( 2, has_filter( 'bbp_get_topic_content', $callback ) );
     729                } finally {
     730                        remove_filter( 'bbp_use_autoembed', '__return_false' );
     731                        remove_filter( 'bbp_use_autoembed', '__return_true' );
     732                        remove_filter( 'bbp_get_topic_content', $callback, 2 );
     733                        if ( false !== $priority ) {
     734                                add_filter( 'bbp_get_topic_content', $callback, $priority );
     735                        }
     736                }
    724737        }
    725738
Note: See TracChangeset for help on using the changeset viewer.