Skip to:
Content

bbPress.org

Changeset 7815


Ignore:
Timestamp:
10/04/2026 05:04:54 PM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover reply toggle and threading.

Exercise spam and trash round trips, redirect and filter arguments, and threaded reply settings and profile behavior.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/replies/functions/reply.php

    r7812 r7815  
    462462
    463463        /**
     464         * @covers ::bbp_toggle_reply
     465         */
     466        public function test_bbp_toggle_reply() {
     467                $topic_id    = $this->factory->topic->create();
     468                $reply_id    = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     469                $old_request = $_REQUEST;
     470                $seen        = array();
     471                $record      = function ( $retval, $parsed, $original ) use ( &$seen ) {
     472                        $seen[] = array( $retval, $parsed, $original );
     473                        return $retval;
     474                };
     475                $args = array( 'id' => $reply_id, 'action' => 'bbp_toggle_reply_spam' );
     476
     477                add_filter( 'bbp_toggle_reply', $record, 10, 3 );
     478
     479                try {
     480                        $_REQUEST['_wpnonce'] = wp_create_nonce( 'spam-' . bbp_get_reply_post_type() . '_' . $reply_id );
     481                        $spam = bbp_toggle_reply( $args );
     482                        $this->assertSame( $reply_id, $spam['status'] );
     483                        $this->assertTrue( $spam['view_all'] );
     484                        $this->assertSame( bbp_get_spam_status_id(), get_post_status( $reply_id ) );
     485                        $this->assertSame( bbp_add_view_all( bbp_get_reply_url( $reply_id ), true ), $spam['redirect_to'] );
     486
     487                        $unspam = bbp_toggle_reply( $args );
     488                        $this->assertSame( $reply_id, $unspam['status'] );
     489                        $this->assertFalse( $unspam['view_all'] );
     490                        $this->assertSame( bbp_get_public_status_id(), get_post_status( $reply_id ) );
     491                        $this->assertCount( 2, $seen );
     492                        $this->assertSame( $args, $seen[0][2] );
     493                        $this->assertSame( $reply_id, $seen[0][1]['id'] );
     494
     495                        $args = array( 'id' => $reply_id, 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'trash' );
     496                        $_REQUEST['_wpnonce'] = wp_create_nonce( 'trash-' . bbp_get_reply_post_type() . '_' . $reply_id );
     497                        $trash = bbp_toggle_reply( $args );
     498                        $this->assertSame( $reply_id, $trash['status']->ID );
     499                        $this->assertTrue( $trash['view_all'] );
     500                        $this->assertSame( 'trash', get_post_status( $reply_id ) );
     501
     502                        $args['sub_action'] = 'untrash';
     503                        $_REQUEST['_wpnonce'] = wp_create_nonce( 'untrash-' . bbp_get_reply_post_type() . '_' . $reply_id );
     504                        $untrash = bbp_toggle_reply( $args );
     505                        $this->assertSame( $reply_id, $untrash['status']->ID );
     506                        $this->assertFalse( $untrash['view_all'] );
     507                        $this->assertSame( bbp_get_public_status_id(), get_post_status( $reply_id ) );
     508                } finally {
     509                        remove_filter( 'bbp_toggle_reply', $record, 10 );
     510                        $_REQUEST = $old_request;
     511                }
     512        }
     513
     514        /**
    464515         * @covers ::bbp_delete_reply
    465516         */
    … …  
    701752                $this->assertSame( $other_id, bbp_validate_reply_to( $other_id ) );
    702753        }
     754
     755        /**
     756         * @covers ::bbp_thread_replies
     757         */
     758        public function test_bbp_thread_replies() {
     759                $old_allow = get_option( '_bbp_allow_threaded_replies' );
     760                $old_depth = get_option( '_bbp_thread_replies_depth' );
     761                $seen      = array();
     762                $record    = function ( $retval, $depth, $allow ) use ( &$seen ) {
     763                        $seen[] = array( $retval, $depth, $allow );
     764                        return $retval;
     765                };
     766
     767                add_filter( 'bbp_thread_replies', $record, 10, 3 );
     768
     769                try {
     770                        update_option( '_bbp_allow_threaded_replies', 0 );
     771                        update_option( '_bbp_thread_replies_depth', 3 );
     772                        $this->assertFalse( bbp_thread_replies() );
     773
     774                        update_option( '_bbp_allow_threaded_replies', 1 );
     775                        update_option( '_bbp_thread_replies_depth', 1 );
     776                        $this->assertFalse( bbp_thread_replies() );
     777
     778                        update_option( '_bbp_thread_replies_depth', 3 );
     779                        $this->assertTrue( bbp_thread_replies() );
     780
     781                        add_filter( 'bbp_is_single_user_replies', '__return_true' );
     782                        try {
     783                                $this->assertFalse( bbp_thread_replies() );
     784                        } finally {
     785                                remove_filter( 'bbp_is_single_user_replies', '__return_true' );
     786                        }
     787
     788                        $this->assertSame( array( false, 3, false ), $seen[0] );
     789                        $this->assertSame( array( false, 1, true ), $seen[1] );
     790                        $this->assertSame( array( true, 3, true ), $seen[2] );
     791                        $this->assertSame( array( false, 3, true ), $seen[3] );
     792                } finally {
     793                        remove_filter( 'bbp_thread_replies', $record, 10 );
     794                        update_option( '_bbp_allow_threaded_replies', $old_allow );
     795                        update_option( '_bbp_thread_replies_depth', $old_depth );
     796                }
     797        }
    703798}
Note: See TracChangeset for help on using the changeset viewer.