Skip to:
Content

bbPress.org

Changeset 7788


Ignore:
Timestamp:
10/04/2026 08:24:05 AM (3 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover engagement handler rejection paths.

Replace three incomplete stubs with checks for missing objects, unsupported actions, invalid nonces, and unchanged engagement state. Record the redirecting success path for integration coverage.

In trunk, for 2.7.

See #3695.

Location:
trunk/tests/phpunit/testcases/users/functions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/users/functions/favorites.php

    r6110 r7788  
    166166        /**
    167167         * @covers ::bbp_favorites_handler
    168          * @todo   Implement test_bbp_favorites_handler().
     168         * @todo   Cover successful toggles in an integration test because bbp_redirect() exits.
    169169         */
    170170        public function test_bbp_favorites_handler() {
    171                 // Remove the following lines when you implement this test.
    172                 $this->markTestIncomplete(
    173                         'This test has not been implemented yet.'
    174                 );
     171                $old_get     = $_GET;
     172                $old_request = $_REQUEST;
     173                $old_user    = get_current_user_id();
     174                $user_id     = $this->factory->user->create( array( 'role' => 'administrator' ) );
     175                $forum_id    = $this->factory->forum->create();
     176                $topic_id    = $this->factory->topic->create( array(
     177                        'post_parent' => $forum_id,
     178                        'topic_meta'  => array( 'forum_id' => $forum_id ),
     179                ) );
     180
     181                bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
     182                $this->set_current_user( $user_id );
     183
     184                try {
     185                        unset( $_GET['object_id'] );
     186                        $this->assertFalse( bbp_favorites_handler( 'bbp_favorite_add' ) );
     187
     188                        $_GET['object_id'] = $topic_id;
     189                        $this->assertFalse( bbp_favorites_handler( 'unsupported' ) );
     190
     191                        $_REQUEST['_wpnonce'] = 'invalid';
     192                        $this->assertFalse( bbp_favorites_handler( 'bbp_favorite_add' ) );
     193                        $this->assertSame( 'bbp_favorite_nonce', bbpress()->errors->get_error_code() );
     194                        $this->assertFalse( bbp_is_user_favorite( $user_id, $topic_id ) );
     195                } finally {
     196                        bbpress()->errors->remove( 'bbp_favorite_nonce' );
     197                        $_GET = $old_get;
     198                        $_REQUEST = $old_request;
     199                        $this->set_current_user( $old_user );
     200                }
    175201        }
    176202}
  • trunk/tests/phpunit/testcases/users/functions/subscriptions.php

    r6110 r7788  
    358358        /**
    359359         * @covers ::bbp_forum_subscriptions_handler
    360          * @todo   Implement test_bbp_forum_subscriptions_handler().
     360         * @todo   Cover successful toggles in an integration test because bbp_redirect() exits.
    361361         */
    362362        public function test_bbp_forum_subscriptions_handler() {
    363                 // Remove the following lines when you implement this test.
    364                 $this->markTestIncomplete(
    365                         'This test has not been implemented yet.'
    366                 );
     363                $old_get     = $_GET;
     364                $old_request = $_REQUEST;
     365                $old_user    = get_current_user_id();
     366                $user_id     = $this->factory->user->create( array( 'role' => 'administrator' ) );
     367                $forum_id    = $this->factory->forum->create();
     368
     369                bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
     370                $this->set_current_user( $user_id );
     371
     372                try {
     373                        $_GET['object_id'] = $forum_id;
     374                        $_REQUEST['_wpnonce'] = 'invalid';
     375                        $this->assertFalse( bbp_forum_subscriptions_handler( 'bbp_subscribe' ) );
     376                        $this->assertSame( 'bbp_subscription_object_id', bbpress()->errors->get_error_code() );
     377                        $this->assertFalse( bbp_is_user_subscribed_to_forum( $user_id, $forum_id ) );
     378                } finally {
     379                        bbpress()->errors->remove( 'bbp_subscription_object_id' );
     380                        $_GET = $old_get;
     381                        $_REQUEST = $old_request;
     382                        $this->set_current_user( $old_user );
     383                }
    367384        }
    368385
    369386        /**
    370387         * @covers ::bbp_subscriptions_handler
    371          * @todo   Implement test_bbp_subscriptions_handler().
     388         * @todo   Cover successful toggles in an integration test because bbp_redirect() exits.
    372389         */
    373390        public function test_bbp_subscriptions_handler() {
    374                 // Remove the following lines when you implement this test.
    375                 $this->markTestIncomplete(
    376                         'This test has not been implemented yet.'
    377                 );
     391                $old_get     = $_GET;
     392                $old_request = $_REQUEST;
     393                $old_user    = get_current_user_id();
     394                $user_id     = $this->factory->user->create( array( 'role' => 'administrator' ) );
     395                $forum_id    = $this->factory->forum->create();
     396                $topic_id    = $this->factory->topic->create( array(
     397                        'post_parent' => $forum_id,
     398                        'topic_meta'  => array( 'forum_id' => $forum_id ),
     399                ) );
     400
     401                bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
     402                $this->set_current_user( $user_id );
     403
     404                try {
     405                        unset( $_GET['object_id'] );
     406                        $this->assertFalse( bbp_subscriptions_handler( 'bbp_subscribe' ) );
     407
     408                        $_GET['object_id'] = $topic_id;
     409                        $this->assertFalse( bbp_subscriptions_handler( 'unsupported' ) );
     410
     411                        $_REQUEST['_wpnonce'] = 'invalid';
     412                        $this->assertFalse( bbp_subscriptions_handler( 'bbp_subscribe' ) );
     413                        $this->assertSame( 'bbp_subscription_object_id', bbpress()->errors->get_error_code() );
     414                        $this->assertFalse( bbp_is_user_subscribed_to_topic( $user_id, $topic_id ) );
     415                } finally {
     416                        bbpress()->errors->remove( 'bbp_subscription_object_id' );
     417                        $_GET = $old_get;
     418                        $_REQUEST = $old_request;
     419                        $this->set_current_user( $old_user );
     420                }
    378421        }
    379422}
Note: See TracChangeset for help on using the changeset viewer.