Skip to:
Content

bbPress.org

Changeset 7791


Ignore:
Timestamp:
10/04/2026 08:39:42 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover topic tag template basics.

Replace seven incomplete stubs with checks for tag lists, taxonomy metadata, explicit tag lookup, and links. Leave edit-link and description behavior for a separately reviewed source fix.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

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

    r7465 r7791  
    1515         * @covers ::bbp_topic_tag_list
    1616         * @covers ::bbp_get_topic_tag_list
    17          * @todo   Implement test_bbp_get_topic_tag_list().
    1817         */
    1918        public function test_bbp_get_topic_tag_list() {
    20                 // Remove the following lines when you implement this test.
    21                 $this->markTestIncomplete(
    22                         'This test has not been implemented yet.'
    23                 );
     19                $topic_id = $this->factory->topic->create();
     20                $args = array( 'before' => '<p>', 'sep' => ' | ', 'after' => '</p>', 'none' => 'No tags' );
     21                $this->assertSame( 'No tags', bbp_get_topic_tag_list( $topic_id, $args ) );
     22
     23                wp_set_object_terms( $topic_id, array( 'alpha', 'beta' ), bbp_get_topic_tag_tax_id() );
     24                $html = bbp_get_topic_tag_list( $topic_id, $args );
     25                $this->assertStringStartsWith( '<p>', $html );
     26                $this->assertStringContainsString( '>alpha</a> | <a ', $html );
     27                $this->assertStringEndsWith( '</p>', $html );
     28                $this->expectOutputString( $html );
     29                bbp_topic_tag_list( $topic_id, $args );
     30
     31                add_filter( 'bbp_allow_topic_tags', '__return_false' );
     32                try {
     33                        $this->assertSame( '', bbp_get_topic_tag_list( $topic_id, $args ) );
     34                } finally {
     35                        remove_filter( 'bbp_allow_topic_tags', '__return_false' );
     36                }
    2437        }
    2538
    … …  
    2740         * @covers ::bbp_topic_tag_tax_id
    2841         * @covers ::bbp_get_topic_tag_tax_id
    29          * @todo   Implement test_bbp_get_topic_tag_tax_id().
    3042         */
    3143        public function test_bbp_get_topic_tag_tax_id() {
    32                 // Remove the following lines when you implement this test.
    33                 $this->markTestIncomplete(
    34                         'This test has not been implemented yet.'
    35                 );
     44                $this->assertSame( bbpress()->topic_tag_tax_id, bbp_get_topic_tag_tax_id() );
     45                $this->expectOutputString( bbpress()->topic_tag_tax_id );
     46                bbp_topic_tag_tax_id();
    3647        }
    3748
    3849        /**
    3950         * @covers ::bbp_get_topic_tag_tax_labels
    40          * @todo   Implement test_bbp_get_topic_tag_tax_labels().
    4151         */
    4252        public function test_bbp_get_topic_tag_tax_labels() {
    43                 // Remove the following lines when you implement this test.
    44                 $this->markTestIncomplete(
    45                         'This test has not been implemented yet.'
    46                 );
     53                $labels = bbp_get_topic_tag_tax_labels();
     54                $this->assertSame( 'Topic Tags', $labels['name'] );
     55                $this->assertSame( 'Topic Tag', $labels['singular_name'] );
     56                $this->assertArrayHasKey( 'not_found', $labels );
    4757        }
    4858
    4959        /**
    5060         * @covers ::bbp_get_topic_tag_tax_rewrite
    51          * @todo   Implement test_bbp_get_topic_tag_tax_rewrite().
    5261         */
    5362        public function test_bbp_get_topic_tag_tax_rewrite() {
    54                 // Remove the following lines when you implement this test.
    55                 $this->markTestIncomplete(
    56                         'This test has not been implemented yet.'
    57                 );
     63                $this->assertSame( array( 'slug' => bbp_get_topic_tag_tax_slug(), 'with_front' => false ), bbp_get_topic_tag_tax_rewrite() );
    5864        }
    5965
    … …  
    6167         * @covers ::bbp_topic_tag_id
    6268         * @covers ::bbp_get_topic_tag_id
    63          * @todo   Implement test_bbp_get_topic_tag_id().
    6469         */
    6570        public function test_bbp_get_topic_tag_id() {
    66                 // Remove the following lines when you implement this test.
    67                 $this->markTestIncomplete(
    68                         'This test has not been implemented yet.'
    69                 );
     71                $term = wp_insert_term( 'Alpha', bbp_get_topic_tag_tax_id(), array( 'slug' => 'alpha' ) );
     72                $this->assertFalse( is_wp_error( $term ) );
     73                $this->assertSame( $term['term_id'], bbp_get_topic_tag_id( 'alpha' ) );
     74                $this->assertSame( 0, bbp_get_topic_tag_id( 'missing-tag' ) );
     75                $this->expectOutputString( (string) $term['term_id'] );
     76                bbp_topic_tag_id( 'alpha' );
    7077        }
    7178
    … …  
    101108         * @covers ::bbp_topic_tag_slug
    102109         * @covers ::bbp_get_topic_tag_slug
    103          * @todo   Implement test_bbp_get_topic_tag_slug().
    104110         */
    105111        public function test_bbp_get_topic_tag_slug() {
    106                 // Remove the following lines when you implement this test.
    107                 $this->markTestIncomplete(
    108                         'This test has not been implemented yet.'
    109                 );
     112                $term = wp_insert_term( 'Alpha', bbp_get_topic_tag_tax_id(), array( 'slug' => 'alpha' ) );
     113                $this->assertFalse( is_wp_error( $term ) );
     114                $this->assertSame( 'alpha', bbp_get_topic_tag_slug( 'alpha' ) );
     115                $this->assertSame( '', bbp_get_topic_tag_slug( 'missing-tag' ) );
     116                $this->expectOutputString( 'alpha' );
     117                bbp_topic_tag_slug( 'alpha' );
    110118        }
    111119
    … …  
    113121         * @covers ::bbp_topic_tag_link
    114122         * @covers ::bbp_get_topic_tag_link
    115          * @todo   Implement test_bbp_get_topic_tag_link().
    116123         */
    117124        public function test_bbp_get_topic_tag_link() {
    118                 // Remove the following lines when you implement this test.
    119                 $this->markTestIncomplete(
    120                         'This test has not been implemented yet.'
    121                 );
     125                $term = wp_insert_term( 'Alpha', bbp_get_topic_tag_tax_id(), array( 'slug' => 'alpha' ) );
     126                $this->assertFalse( is_wp_error( $term ) );
     127                $url = get_term_link( $term['term_id'], bbp_get_topic_tag_tax_id() );
     128                $this->assertSame( $url, bbp_get_topic_tag_link( 'alpha' ) );
     129                $this->assertSame( '', bbp_get_topic_tag_link( 'missing-tag' ) );
     130                $this->expectOutputString( esc_url( $url ) );
     131                bbp_topic_tag_link( 'alpha' );
    122132        }
    123133
Note: See TracChangeset for help on using the changeset viewer.