Skip to:
Content

bbPress.org

Changeset 7783


Ignore:
Timestamp:
10/04/2026 07:57:23 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover general topic template helpers.

Replace ten incomplete tests for topic lookup, archive titles, pagination, CSS classes, notices, selectors, descriptions, and row-action hooks. Keep notice assertions isolated from the shared error queue.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

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

    r7669 r7783  
    1111        /**
    1212         * @covers ::bbp_show_lead_topic
    13          * @todo   Implement test_bbp_show_lead_topic().
    1413         */
    1514        public function test_bbp_show_lead_topic() {
    16                 // Remove the following lines when you implement this test.
    17                 $this->markTestIncomplete(
    18                         'This test has not been implemented yet.'
    19                 );
     15                $this->assertFalse( bbp_show_lead_topic() );
     16                $this->assertTrue( bbp_show_lead_topic( true ) );
     17                $this->assertFalse( bbp_show_lead_topic( 0 ) );
    2018        }
    2119
    … …  
    3937        /**
    4038         * @covers ::bbp_get_topic
    41          * @todo   Implement test_bbp_get_topic().
    4239         */
    4340        public function test_bbp_get_topic() {
    44                 // Remove the following lines when you implement this test.
    45                 $this->markTestIncomplete(
    46                         'This test has not been implemented yet.'
    47                 );
     41                $topic_id = $this->factory->topic->create();
     42                $forum_id = $this->factory->forum->create();
     43
     44                $this->assertSame( $topic_id, bbp_get_topic( $topic_id )->ID );
     45                $this->assertSame( $topic_id, bbp_get_topic( get_post( $topic_id ) )->ID );
     46                $this->assertSame( $topic_id, bbp_get_topic( $topic_id, ARRAY_A )['ID'] );
     47                $this->assertNull( bbp_get_topic( $forum_id ) );
    4848        }
    4949
    … …  
    189189         * @covers ::bbp_topic_archive_title
    190190         * @covers ::bbp_get_topic_archive_title
    191          * @todo   Implement test_bbp_get_topic_archive_title().
    192191         */
    193192        public function test_bbp_get_topic_archive_title() {
    194                 // Remove the following lines when you implement this test.
    195                 $this->markTestIncomplete(
    196                         'This test has not been implemented yet.'
    197                 );
     193                $this->assertSame( 'Topics', bbp_get_topic_archive_title() );
     194                $this->assertSame( 'Custom archive', bbp_get_topic_archive_title( 'Custom archive' ) );
     195                $this->expectOutputString( 'Custom archive' );
     196                bbp_topic_archive_title( 'Custom archive' );
    198197        }
    199198
    … …  
    319318         * @covers ::bbp_topic_pagination
    320319         * @covers ::bbp_get_topic_pagination
    321          * @todo   Implement test_bbp_get_topic_pagination().
    322320         */
    323321        public function test_bbp_get_topic_pagination() {
    324                 // Remove the following lines when you implement this test.
    325                 $this->markTestIncomplete(
    326                         'This test has not been implemented yet.'
    327                 );
     322                $topic_id = $this->factory->topic->create();
     323                $this->factory->reply->create_many( 2, array( 'post_parent' => $topic_id ) );
     324                update_option( '_bbp_replies_per_page', 1 );
     325                $args = array( 'topic_id' => $topic_id );
     326                $pagination = bbp_get_topic_pagination( $args );
     327
     328                $this->assertStringContainsString( 'bbp-topic-pagination', $pagination );
     329                $this->assertStringContainsString( 'paged=', $pagination );
     330                $this->expectOutputString( $pagination );
     331                bbp_topic_pagination( $args );
    328332        }
    329333
    … …  
    365369         * @covers ::bbp_topic_class
    366370         * @covers ::bbp_get_topic_class
    367          * @todo   Implement test_bbp_get_topic_class().
    368371         */
    369372        public function test_bbp_get_topic_class() {
    370                 // Remove the following lines when you implement this test.
    371                 $this->markTestIncomplete(
    372                         'This test has not been implemented yet.'
    373                 );
     373                $forum_id = $this->factory->forum->create();
     374                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     375                $classes  = bbp_get_topic_class( $topic_id, array( 'extra-topic-class' ) );
     376
     377                $this->assertStringContainsString( 'bbp-parent-forum-' . $forum_id, $classes );
     378                $this->assertStringContainsString( 'extra-topic-class', $classes );
     379                bbp_stick_topic( $topic_id );
     380                $classes = bbp_get_topic_class( $topic_id, array( 'extra-topic-class' ) );
     381                $this->assertStringContainsString( ' sticky', $classes );
     382                $this->expectOutputString( $classes );
     383                bbp_topic_class( $topic_id, array( 'extra-topic-class' ) );
    374384        }
    375385
    … …  
    377387         * @covers ::bbp_forum_pagination_count
    378388         * @covers ::bbp_get_forum_pagination_count
    379          * @todo   Implement test_bbp_get_forum_pagination_count().
    380389         */
    381390        public function test_bbp_get_forum_pagination_count() {
    382                 // Remove the following lines when you implement this test.
    383                 $this->markTestIncomplete(
    384                         'This test has not been implemented yet.'
    385                 );
     391                $forum_id = $this->factory->forum->create();
     392                $this->factory->topic->create_many( 2, array( 'post_parent' => $forum_id ) );
     393                bbp_has_topics( array( 'post_parent' => $forum_id, 'posts_per_page' => 1 ) );
     394                $count = bbp_get_forum_pagination_count();
     395
     396                $this->assertStringContainsString( 'Viewing', $count );
     397                $this->assertStringContainsString( '2 total', $count );
     398                $this->expectOutputString( $count );
     399                bbp_forum_pagination_count();
    386400        }
    387401
    388402        /**
    389403         * @covers ::bbp_topic_notices
    390          * @todo   Implement test_bbp_topic_notices().
    391404         */
    392405        public function test_bbp_topic_notices() {
    393                 // Remove the following lines when you implement this test.
    394                 $this->markTestIncomplete(
    395                         'This test has not been implemented yet.'
    396                 );
     406                $topic_id = $this->factory->topic->create();
     407                bbp_unapprove_topic( $topic_id );
     408                $previous_topic_id = bbpress()->current_topic_id;
     409                bbpress()->current_topic_id = $topic_id;
     410                add_filter( 'bbp_is_single_topic', '__return_true' );
     411                try {
     412                        bbp_topic_notices();
     413                        $this->assertSame( 'This topic is pending moderation.', bbpress()->errors->get_error_message( 'topic_notice' ) );
     414                } finally {
     415                        bbpress()->errors->remove( 'topic_notice' );
     416                        remove_filter( 'bbp_is_single_topic', '__return_true' );
     417                        bbpress()->current_topic_id = $previous_topic_id;
     418                }
    397419        }
    398420
    399421        /**
    400422         * @covers ::bbp_topic_type_select
    401          * @todo   Implement test_bbp_topic_type_select().
    402423         */
    403424        public function test_bbp_topic_type_select() {
    404                 // Remove the following lines when you implement this test.
    405                 $this->markTestIncomplete(
    406                         'This test has not been implemented yet.'
    407                 );
     425                $topic_id = $this->factory->topic->create();
     426                $args     = array( 'topic_id' => $topic_id );
     427                $dropdown = bbp_get_form_topic_type_dropdown( $args );
     428
     429                $this->assertStringContainsString( 'bbp_stick_topic', $dropdown );
     430                $this->assertStringContainsString( 'value="unstick"', $dropdown );
     431                $this->expectOutputString( $dropdown );
     432                bbp_topic_type_select( $args );
    408433        }
    409434
    … …  
    411436         * @covers ::bbp_single_topic_description
    412437         * @covers ::bbp_get_single_topic_description
    413          * @todo   Implement test_bbp_get_single_topic_description().
    414438         */
    415439        public function test_bbp_get_single_topic_description() {
    416                 // Remove the following lines when you implement this test.
    417                 $this->markTestIncomplete(
    418                         'This test has not been implemented yet.'
    419                 );
     440                $topic_id = $this->factory->topic->create();
     441                $args     = array( 'topic_id' => $topic_id, 'before' => '<p>', 'after' => '</p>' );
     442                $description = bbp_get_single_topic_description( $args );
     443
     444                $this->assertStringStartsWith( '<p>', $description );
     445                $this->assertStringEndsWith( '</p>', $description );
     446                $this->assertStringContainsString( 'This topic', $description );
     447                $this->expectOutputString( $description );
     448                bbp_single_topic_description( $args );
    420449        }
    421450
    422451        /**
    423452         * @covers ::bbp_topic_row_actions
    424          * @todo   Implement test_bbp_topic_row_actions().
    425453         */
    426454        public function test_bbp_topic_row_actions() {
    427                 // Remove the following lines when you implement this test.
    428                 $this->markTestIncomplete(
    429                         'This test has not been implemented yet.'
    430                 );
     455                $called = 0;
     456                $callback = function() use ( &$called ) {
     457                        ++$called;
     458                };
     459                add_action( 'bbp_topic_row_actions', $callback );
     460                try {
     461                        bbp_topic_row_actions();
     462                        $this->assertSame( 1, $called );
     463                } finally {
     464                        remove_action( 'bbp_topic_row_actions', $callback );
     465                }
    431466        }
    432467}
Note: See TracChangeset for help on using the changeset viewer.