Skip to:
Content

bbPress.org

Changeset 7790


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

Tests: Cover topic tag function behavior.

Replace five incomplete stubs with checks for tag preservation, restoration, names, and rejected management requests. Record redirecting paths for integration coverage.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

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

    r5757 r7790  
    1414        /**
    1515         * @covers ::bbp_edit_topic_tag_handler
    16          * @todo   Implement test_bbp_edit_topic_tag_handler().
     16         * @todo   Cover successful edits in an integration test because bbp_redirect() exits.
    1717         */
    1818        public function test_bbp_edit_topic_tag_handler() {
    19                 // Remove the following lines when you implement this test.
    20                 $this->markTestIncomplete(
    21                         'This test has not been implemented yet.'
    22                 );
     19                $old_post    = $_POST;
     20                $old_request = $_REQUEST;
     21                $term        = wp_insert_term( 'Original', bbp_get_topic_tag_tax_id() );
     22                $this->assertFalse( is_wp_error( $term ) );
     23
     24                try {
     25                        unset( $_POST['tag-id'] );
     26                        $this->assertNull( bbp_edit_topic_tag_handler( 'bbp-update-topic-tag' ) );
     27
     28                        $_POST['tag-id'] = $term['term_id'];
     29                        $this->assertNull( bbp_edit_topic_tag_handler( 'unsupported' ) );
     30
     31                        $_REQUEST['_wpnonce'] = 'invalid';
     32                        $this->assertNull( bbp_edit_topic_tag_handler( 'bbp-update-topic-tag' ) );
     33                        $this->assertSame( 'bbp_manage_topic_tag_update_nonce', bbpress()->errors->get_error_code() );
     34                        bbpress()->errors->remove( 'bbp_manage_topic_tag_update_nonce' );
     35
     36                        $this->assertNull( bbp_edit_topic_tag_handler( 'bbp-merge-topic-tag' ) );
     37                        $this->assertSame( 'bbp_manage_topic_tag_merge_nonce', bbpress()->errors->get_error_code() );
     38                        bbpress()->errors->remove( 'bbp_manage_topic_tag_merge_nonce' );
     39
     40                        $this->assertNull( bbp_edit_topic_tag_handler( 'bbp-delete-topic-tag' ) );
     41                        $this->assertSame( 'bbp_manage_topic_tag_delete_nonce', bbpress()->errors->get_error_code() );
     42                        $this->assertSame( 'Original', get_term( $term['term_id'], bbp_get_topic_tag_tax_id() )->name );
     43                } finally {
     44                        bbpress()->errors->remove( 'bbp_manage_topic_tag_update_nonce' );
     45                        bbpress()->errors->remove( 'bbp_manage_topic_tag_merge_nonce' );
     46                        bbpress()->errors->remove( 'bbp_manage_topic_tag_delete_nonce' );
     47                        $_POST = $old_post;
     48                        $_REQUEST = $old_request;
     49                }
    2350        }
    2451
    2552        /**
    2653         * @covers ::bbp_spam_topic_tags
    27          * @todo   Implement test_bbp_spam_topic_tags().
    2854         */
    2955        public function test_bbp_spam_topic_tags() {
    30                 // Remove the following lines when you implement this test.
    31                 $this->markTestIncomplete(
    32                         'This test has not been implemented yet.'
    33                 );
     56                $topic_id = $this->factory->topic->create();
     57                $taxonomy = bbp_get_topic_tag_tax_id();
     58                wp_set_object_terms( $topic_id, array( 'alpha', 'beta' ), $taxonomy );
     59
     60                $this->assertSame( array( $taxonomy => '' ), bbp_spam_topic_tags( $topic_id ) );
     61                $this->assertSame( array( 'alpha', 'beta' ), get_post_meta( $topic_id, '_bbp_spam_topic_tags', true ) );
     62
     63                $empty_topic_id = $this->factory->topic->create();
     64                $this->assertSame( array( $taxonomy => '' ), bbp_spam_topic_tags( $empty_topic_id ) );
     65                $this->assertFalse( metadata_exists( 'post', $empty_topic_id, '_bbp_spam_topic_tags' ) );
    3466        }
    3567
    3668        /**
    3769         * @covers ::bbp_unspam_topic_tags
    38          * @todo   Implement test_bbp_unspam_topic_tags().
    3970         */
    4071        public function test_bbp_unspam_topic_tags() {
    41                 // Remove the following lines when you implement this test.
    42                 $this->markTestIncomplete(
    43                         'This test has not been implemented yet.'
    44                 );
     72                $topic_id = $this->factory->topic->create();
     73                $taxonomy = bbp_get_topic_tag_tax_id();
     74                update_post_meta( $topic_id, '_bbp_spam_topic_tags', array( 'alpha', 'beta' ) );
     75
     76                $this->assertSame( array( $taxonomy => array( 'alpha', 'beta' ) ), bbp_unspam_topic_tags( $topic_id ) );
     77                $this->assertFalse( metadata_exists( 'post', $topic_id, '_bbp_spam_topic_tags' ) );
     78                $this->assertSame( array( $taxonomy => '' ), bbp_unspam_topic_tags( $topic_id ) );
    4579        }
    4680
    4781        /**
    4882         * @covers ::bbp_get_topic_tag_names
    49          * @todo   Implement test_bbp_get_topic_tag_names().
    5083         */
    5184        public function test_bbp_get_topic_tag_names() {
    52                 // Remove the following lines when you implement this test.
    53                 $this->markTestIncomplete(
    54                         'This test has not been implemented yet.'
    55                 );
     85                $topic_id = $this->factory->topic->create();
     86                $this->assertSame( '', bbp_get_topic_tag_names( $topic_id ) );
     87                wp_set_object_terms( $topic_id, array( 'alpha', 'beta' ), bbp_get_topic_tag_tax_id() );
     88                $this->assertSame( 'alpha, beta', bbp_get_topic_tag_names( $topic_id ) );
     89                $this->assertSame( 'alpha | beta', bbp_get_topic_tag_names( $topic_id, ' | ' ) );
    5690        }
    5791
    5892        /**
    5993         * @covers ::bbp_check_topic_tag_edit
    60          * @todo   Implement test_bbp_check_topic_tag_edit().
     94         * @todo   Cover denied edits in an integration test because bbp_redirect() exits.
    6195         */
    6296        public function test_bbp_check_topic_tag_edit() {
    63                 // Remove the following lines when you implement this test.
    64                 $this->markTestIncomplete(
    65                         'This test has not been implemented yet.'
    66                 );
     97                $this->assertNull( bbp_check_topic_tag_edit() );
    6798        }
    6899}
Note: See TracChangeset for help on using the changeset viewer.