Skip to:
Content

bbPress.org

Changeset 7793


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

Tests: Cover reply action links and pagination.

Replace the remaining reply-link template stubs with assertions for action URLs, custom text, moderation status transitions, threaded reply cancellation, pagination, and output wrappers.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/replies/template/links.php

    r7448 r7793  
    1010class BBP_Tests_Replies_Template_Links extends BBP_UnitTestCase {
    1111
     12        private function with_keymaster_reply( $callback ) {
     13                $old_user = get_current_user_id();
     14                $user_id  = $this->factory->user->create( array( 'role' => 'administrator' ) );
     15                $forum_id = $this->factory->forum->create();
     16                $topic_id = $this->factory->topic->create( array(
     17                        'post_parent' => $forum_id,
     18                        'topic_meta'  => array( 'forum_id' => $forum_id ),
     19                ) );
     20                $reply_id = $this->factory->reply->create( array(
     21                        'post_parent' => $topic_id,
     22                        'reply_meta'  => array( 'forum_id' => $forum_id, 'topic_id' => $topic_id ),
     23                ) );
     24                bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
     25                $this->set_current_user( $user_id );
     26
     27                try {
     28                        $callback( $reply_id, $topic_id, $forum_id, $user_id );
     29                } finally {
     30                        $this->set_current_user( $old_user );
     31                }
     32        }
     33
    1234        /**
    1335         * @covers ::bbp_reply_to_link
    1436         * @covers ::bbp_get_reply_to_link
    15          * @todo   Implement test_bbp_get_reply_to_link().
    1637         */
    1738        public function test_bbp_get_reply_to_link() {
    18                 // Remove the following lines when you implement this test.
    19                 $this->markTestIncomplete(
    20                         'This test has not been implemented yet.'
    21                 );
     39                $this->with_keymaster_reply( function ( $reply_id ) {
     40                        $args = array( 'id' => $reply_id, 'reply_text' => 'Answer', 'link_before' => '<span>', 'link_after' => '</span>' );
     41                        $link = bbp_get_reply_to_link( $args );
     42                        $this->assertStringStartsWith( '<span><a role="button"', $link );
     43                        $this->assertStringContainsString( 'bbp_reply_to=' . $reply_id, $link );
     44                        $this->assertStringContainsString( 'class="bbp-reply-to-link"', $link );
     45                        $this->assertStringContainsString( '>Answer</a></span>', $link );
     46                        $this->expectOutputString( $link );
     47                        bbp_reply_to_link( $args );
     48                } );
    2249        }
    2350
    … …  
    2552         * @covers ::bbp_cancel_reply_to_link
    2653         * @covers ::bbp_get_cancel_reply_to_link
    27          * @todo   Implement test_bbp_get_cancel_reply_to_link().
    2854         */
    2955        public function test_bbp_get_cancel_reply_to_link() {
    30                 // Remove the following lines when you implement this test.
    31                 $this->markTestIncomplete(
    32                         'This test has not been implemented yet.'
    33                 );
     56                $this->assertNull( bbp_get_cancel_reply_to_link() );
     57                $old_reply_to = isset( $_GET['bbp_reply_to'] ) ? $_GET['bbp_reply_to'] : null;
     58                add_filter( 'bbp_thread_replies', '__return_true' );
     59
     60                try {
     61                        unset( $_GET['bbp_reply_to'] );
     62                        $this->assertStringContainsString( 'style="display:none;"', bbp_get_cancel_reply_to_link() );
     63                        $_GET['bbp_reply_to'] = '42';
     64                        $link = bbp_get_cancel_reply_to_link( 'Stop' );
     65                        $this->assertStringContainsString( '#post-42', $link );
     66                        $this->assertStringContainsString( '>Stop</a>', $link );
     67                        $this->assertStringNotContainsString( 'display:none', $link );
     68                        $this->expectOutputString( $link );
     69                        bbp_cancel_reply_to_link( 'Stop' );
     70                } finally {
     71                        remove_filter( 'bbp_thread_replies', '__return_true' );
     72                        if ( null === $old_reply_to ) {
     73                                unset( $_GET['bbp_reply_to'] );
     74                        } else {
     75                                $_GET['bbp_reply_to'] = $old_reply_to;
     76                        }
     77                }
    3478        }
    3579
    … …  
    58102         * @covers ::bbp_reply_edit_link
    59103         * @covers ::bbp_get_reply_edit_link
    60          * @todo   Implement test_bbp_get_reply_edit_link().
    61104         */
    62105        public function test_bbp_get_reply_edit_link() {
    63                 // Remove the following lines when you implement this test.
    64                 $this->markTestIncomplete(
    65                         'This test has not been implemented yet.'
    66                 );
     106                $this->with_keymaster_reply( function ( $reply_id ) {
     107                        $args = array( 'id' => $reply_id, 'edit_text' => 'Modify', 'link_before' => '<span>', 'link_after' => '</span>' );
     108                        $link = bbp_get_reply_edit_link( $args );
     109                        $this->assertStringContainsString( 'class="bbp-reply-edit-link"', $link );
     110                        $this->assertStringContainsString( esc_url( bbp_get_reply_edit_url( $reply_id ) ), $link );
     111                        $this->assertStringContainsString( '>Modify</a></span>', $link );
     112                        $this->expectOutputString( $link );
     113                        bbp_reply_edit_link( $args );
     114                } );
    67115        }
    68116
    … …  
    70118         * @covers ::bbp_reply_edit_url
    71119         * @covers ::bbp_get_reply_edit_url
    72          * @todo   Implement test_bbp_get_reply_edit_url().
    73120         */
    74121        public function test_bbp_get_reply_edit_url() {
    75                 // Remove the following lines when you implement this test.
    76                 $this->markTestIncomplete(
    77                         'This test has not been implemented yet.'
    78                 );
     122                $this->assertNull( bbp_get_reply_edit_url( PHP_INT_MAX ) );
     123                $this->with_keymaster_reply( function ( $reply_id ) {
     124                        $url = bbp_get_reply_edit_url( $reply_id );
     125                        $this->assertNotEmpty( $url );
     126                        $this->assertStringContainsString( bbp_get_edit_rewrite_id(), $url );
     127                        $this->expectOutputString( esc_url( $url ) );
     128                        bbp_reply_edit_url( $reply_id );
     129                } );
    79130        }
    80131
    … …  
    82133         * @covers ::bbp_reply_trash_link
    83134         * @covers ::bbp_get_reply_trash_link
    84          * @todo   Implement test_bbp_get_reply_trash_link().
    85135         */
    86136        public function test_bbp_get_reply_trash_link() {
    87                 // Remove the following lines when you implement this test.
    88                 $this->markTestIncomplete(
    89                         'This test has not been implemented yet.'
    90                 );
     137                $this->with_keymaster_reply( function ( $reply_id ) {
     138                        $args = array( 'id' => $reply_id, 'trash_text' => 'Discard', 'restore_text' => 'Recover', 'delete_text' => 'Erase' );
     139                        $link = bbp_get_reply_trash_link( $args );
     140                        $this->assertStringContainsString( 'bbp-reply-trash-link', $link );
     141                        $this->assertStringContainsString( '>Discard</a>', $link );
     142                        wp_trash_post( $reply_id );
     143                        $link = bbp_get_reply_trash_link( $args );
     144                        $this->assertStringContainsString( 'bbp-reply-restore-link', $link );
     145                        $this->assertStringContainsString( 'bbp-reply-delete-link', $link );
     146                        $this->assertStringContainsString( '>Recover</a>', $link );
     147                        $this->assertStringContainsString( '>Erase</a>', $link );
     148                        $this->expectOutputString( $link );
     149                        bbp_reply_trash_link( $args );
     150                } );
    91151        }
    92152
    … …  
    94154         * @covers ::bbp_reply_spam_link
    95155         * @covers ::bbp_get_reply_spam_link
    96          * @todo   Implement test_bbp_get_reply_spam_link().
    97156         */
    98157        public function test_bbp_get_reply_spam_link() {
    99                 // Remove the following lines when you implement this test.
    100                 $this->markTestIncomplete(
    101                         'This test has not been implemented yet.'
    102                 );
     158                $this->with_keymaster_reply( function ( $reply_id ) {
     159                        $args = array( 'id' => $reply_id, 'spam_text' => 'Flag', 'unspam_text' => 'Clear' );
     160                        $link = bbp_get_reply_spam_link( $args );
     161                        $this->assertStringContainsString( 'bbp-reply-spam-link', $link );
     162                        $this->assertStringContainsString( '>Flag</a>', $link );
     163                        bbp_spam_reply( $reply_id );
     164                        $link = bbp_get_reply_spam_link( $args );
     165                        $this->assertStringContainsString( '>Clear</a>', $link );
     166                        $this->expectOutputString( $link );
     167                        bbp_reply_spam_link( $args );
     168                } );
    103169        }
    104170
    … …  
    106172         * @covers ::bbp_reply_move_link
    107173         * @covers ::bbp_get_reply_move_link
    108          * @todo   Implement test_bbp_get_reply_move_link().
    109174         */
    110175        public function test_bbp_get_reply_move_link() {
    111                 // Remove the following lines when you implement this test.
    112                 $this->markTestIncomplete(
    113                         'This test has not been implemented yet.'
    114                 );
     176                $this->with_keymaster_reply( function ( $reply_id ) {
     177                        $args = array( 'id' => $reply_id, 'split_text' => 'Relocate' );
     178                        $link = bbp_get_reply_move_link( $args );
     179                        $this->assertStringContainsString( 'bbp-reply-move-link', $link );
     180                        $this->assertStringContainsString( 'action=move', $link );
     181                        $this->assertStringContainsString( '>Relocate</a>', $link );
     182                        $this->expectOutputString( $link );
     183                        bbp_reply_move_link( $args );
     184                } );
    115185        }
    116186
    … …  
    118188         * @covers ::bbp_topic_split_link
    119189         * @covers ::bbp_get_topic_split_link
    120          * @todo   Implement test_bbp_get_topic_split_link().
    121190         */
    122191        public function test_bbp_get_topic_split_link() {
    123                 // Remove the following lines when you implement this test.
    124                 $this->markTestIncomplete(
    125                         'This test has not been implemented yet.'
    126                 );
     192                $this->with_keymaster_reply( function ( $reply_id ) {
     193                        $args = array( 'id' => $reply_id, 'split_text' => 'Divide' );
     194                        $link = bbp_get_topic_split_link( $args );
     195                        $this->assertStringContainsString( 'bbp-topic-split-link', $link );
     196                        $this->assertStringContainsString( 'action=split', $link );
     197                        $this->assertStringContainsString( '>Divide</a>', $link );
     198                        $this->expectOutputString( $link );
     199                        bbp_topic_split_link( $args );
     200                } );
    127201        }
    128202
    … …  
    130204         * @covers ::bbp_reply_approve_link
    131205         * @covers ::bbp_get_reply_approve_link
    132          * @todo   Implement test_bbp_get_reply_approve_link().
    133206         */
    134207        public function test_bbp_get_reply_approve_link() {
    135                 // Remove the following lines when you implement this test.
    136                 $this->markTestIncomplete(
    137                         'This test has not been implemented yet.'
    138                 );
     208                $this->with_keymaster_reply( function ( $reply_id ) {
     209                        $args = array( 'id' => $reply_id, 'approve_text' => 'Accept', 'unapprove_text' => 'Hold' );
     210                        $link = bbp_get_reply_approve_link( $args );
     211                        $this->assertStringContainsString( 'bbp-reply-approve-link', $link );
     212                        $this->assertStringContainsString( '>Hold</a>', $link );
     213                        bbp_unapprove_reply( $reply_id );
     214                        $link = bbp_get_reply_approve_link( $args );
     215                        $this->assertStringContainsString( '>Accept</a>', $link );
     216                        $this->expectOutputString( $link );
     217                        bbp_reply_approve_link( $args );
     218                } );
    139219        }
    140220
    … …  
    142222         * @covers ::bbp_topic_pagination_links
    143223         * @covers ::bbp_get_topic_pagination_links
    144          * @todo   Implement test_bbp_get_topic_pagination_links().
    145224         */
    146225        public function test_bbp_get_topic_pagination_links() {
    147                 // Remove the following lines when you implement this test.
    148                 $this->markTestIncomplete(
    149                         'This test has not been implemented yet.'
    150                 );
     226                $old_query = bbpress()->reply_query;
     227                bbpress()->reply_query = (object) array();
     228
     229                try {
     230                        $this->assertFalse( bbp_get_topic_pagination_links() );
     231                        bbpress()->reply_query->pagination_links = '<a href="?paged=2">2</a>';
     232                        $this->assertSame( '<a href="?paged=2">2</a>', bbp_get_topic_pagination_links() );
     233                        $this->expectOutputString( '<a href="?paged=2">2</a>' );
     234                        bbp_topic_pagination_links();
     235                } finally {
     236                        bbpress()->reply_query = $old_query;
     237                }
    151238        }
    152239}
Note: See TracChangeset for help on using the changeset viewer.