Skip to:
Content

bbPress.org

Changeset 7778


Ignore:
Timestamp:
10/04/2026 07:26:39 AM (6 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover topic and reply status templates.

Replace fifteen incomplete status-template tests with assertions for sticky, public, moderation, and anonymous behavior. Add coverage for the public-status helpers missing from the original stubs.

In trunk, for 2.7.

See #3695.

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

Legend:

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

    r7353 r7778  
    2828         * @covers ::bbp_reply_status
    2929         * @covers ::bbp_get_reply_status
    30          * @todo   Implement test_bbp_get_reply_status().
    3130         */
    3231        public function test_bbp_get_reply_status() {
    33                 // Remove the following lines when you implement this test.
    34                 $this->markTestIncomplete(
    35                         'This test has not been implemented yet.'
    36                 );
    37 
     32                $topic_id = $this->factory->topic->create();
     33                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     34
     35                $this->assertSame( bbp_get_public_status_id(), bbp_get_reply_status( $reply_id ) );
     36                wp_update_post( array( 'ID' => $reply_id, 'post_status' => bbp_get_pending_status_id() ) );
     37                $this->assertSame( bbp_get_pending_status_id(), bbp_get_reply_status( $reply_id ) );
     38                $this->expectOutputString( bbp_get_pending_status_id() );
     39                bbp_reply_status( $reply_id );
     40        }
     41
     42        /**
     43         * @covers ::bbp_is_reply_public
     44         */
     45        public function test_bbp_is_reply_public() {
     46                $topic_id = $this->factory->topic->create();
     47                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     48
     49                $this->assertTrue( bbp_is_reply_public( $reply_id ) );
     50                wp_update_post( array( 'ID' => $reply_id, 'post_status' => bbp_get_pending_status_id() ) );
     51                $this->assertFalse( bbp_is_reply_public( $reply_id ) );
    3852        }
    3953
    … …  
    115129        /**
    116130         * @covers ::bbp_is_reply_trash
    117          * @todo   Implement test_bbp_is_reply_trash().
    118131         */
    119132        public function test_bbp_is_reply_trash() {
    120                 // Remove the following lines when you implement this test.
    121                 $this->markTestIncomplete(
    122                         'This test has not been implemented yet.'
    123                 );
     133                $topic_id = $this->factory->topic->create();
     134                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     135
     136                $this->assertFalse( bbp_is_reply_trash( $reply_id ) );
     137                wp_trash_post( $reply_id );
     138                $this->assertTrue( bbp_is_reply_trash( $reply_id ) );
    124139        }
    125140
    … …  
    203218        /**
    204219         * @covers ::bbp_is_reply_anonymous
    205          * @todo   Implement test_bbp_is_reply_anonymous().
    206220         */
    207221        public function test_bbp_is_reply_anonymous() {
    208                 // Remove the following lines when you implement this test.
    209                 $this->markTestIncomplete(
    210                         'This test has not been implemented yet.'
    211                 );
     222                $user_id  = $this->factory->user->create();
     223                $topic_id = $this->factory->topic->create();
     224                $reply_id = $this->factory->reply->create( array(
     225                        'post_author' => $user_id,
     226                        'post_parent' => $topic_id,
     227                ) );
     228
     229                $this->assertFalse( bbp_is_reply_anonymous( $reply_id ) );
     230                update_post_meta( $reply_id, '_bbp_anonymous_name', 'Guest' );
     231                $this->assertTrue( bbp_is_reply_anonymous( $reply_id ) );
     232                delete_post_meta( $reply_id, '_bbp_anonymous_name' );
     233                update_post_meta( $reply_id, '_bbp_anonymous_email', 'guest@example.org' );
     234                $this->assertTrue( bbp_is_reply_anonymous( $reply_id ) );
     235                delete_post_meta( $reply_id, '_bbp_anonymous_email' );
     236                wp_update_post( array( 'ID' => $reply_id, 'post_author' => 0 ) );
     237                $this->assertTrue( bbp_is_reply_anonymous( $reply_id ) );
    212238        }
    213239}
  • trunk/tests/phpunit/testcases/topics/template/status.php

    r5749 r7778  
    1212        /**
    1313         * @covers ::bbp_is_topic_sticky
    14          * @todo   Implement test_bbp_is_topic_sticky().
    1514         */
    1615        public function test_bbp_is_topic_sticky() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                $forum_id = $this->factory->forum->create();
     17                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     18
     19                $this->assertFalse( bbp_is_topic_sticky( $topic_id ) );
     20                $this->assertTrue( bbp_stick_topic( $topic_id ) );
     21                $this->assertTrue( bbp_is_topic_sticky( $topic_id ) );
     22                $this->assertTrue( bbp_is_topic_sticky( $topic_id, false ) );
    2123        }
    2224
    2325        /**
    2426         * @covers ::bbp_is_topic_super_sticky
    25          * @todo   Implement test_bbp_is_topic_super_sticky().
    2627         */
    2728        public function test_bbp_is_topic_super_sticky() {
    28                 // Remove the following lines when you implement this test.
    29                 $this->markTestIncomplete(
    30                         'This test has not been implemented yet.'
    31                 );
     29                $forum_id = $this->factory->forum->create();
     30                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     31
     32                $this->assertFalse( bbp_is_topic_super_sticky( $topic_id ) );
     33                $this->assertTrue( bbp_stick_topic( $topic_id, true ) );
     34                $this->assertTrue( bbp_is_topic_super_sticky( $topic_id ) );
     35                $this->assertTrue( bbp_is_topic_sticky( $topic_id ) );
     36                $this->assertFalse( bbp_is_topic_sticky( $topic_id, false ) );
    3237        }
    3338
    3439        /**
    3540         * @covers ::bbp_topic_status
    36          * @todo   Implement test_bbp_topic_status().
    3741         */
    3842        public function test_bbp_topic_status() {
    39                 // Remove the following lines when you implement this test.
    40                 $this->markTestIncomplete(
    41                         'This test has not been implemented yet.'
    42                 );
     43                $topic_id = $this->factory->topic->create();
     44
     45                $this->expectOutputString( bbp_get_public_status_id() );
     46                bbp_topic_status( $topic_id );
    4347        }
    4448
    4549        /**
    4650         * @covers ::bbp_get_topic_status
    47          * @todo   Implement test_bbp_get_topic_status().
    4851         */
    4952        public function test_bbp_get_topic_status() {
    50                 // Remove the following lines when you implement this test.
    51                 $this->markTestIncomplete(
    52                         'This test has not been implemented yet.'
    53                 );
     53                $topic_id = $this->factory->topic->create();
     54
     55                $this->assertSame( bbp_get_public_status_id(), bbp_get_topic_status( $topic_id ) );
     56                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_closed_status_id() ) );
     57                $this->assertSame( bbp_get_closed_status_id(), bbp_get_topic_status( $topic_id ) );
    5458        }
    5559
    5660        /**
    5761         * @covers ::bbp_is_topic_closed
    58          * @todo   Implement test_bbp_is_topic_closed().
    5962         */
    6063        public function test_bbp_is_topic_closed() {
    61                 // Remove the following lines when you implement this test.
    62                 $this->markTestIncomplete(
    63                         'This test has not been implemented yet.'
    64                 );
     64                $topic_id = $this->factory->topic->create();
     65
     66                $this->assertFalse( bbp_is_topic_closed( $topic_id ) );
     67                bbp_close_topic( $topic_id );
     68                $this->assertTrue( bbp_is_topic_closed( $topic_id ) );
    6569        }
    6670
    6771        /**
    6872         * @covers ::bbp_is_topic_open
    69          * @todo   Implement test_bbp_is_topic_open().
    7073         */
    7174        public function test_bbp_is_topic_open() {
    72                 // Remove the following lines when you implement this test.
    73                 $this->markTestIncomplete(
    74                         'This test has not been implemented yet.'
    75                 );
     75                $topic_id = $this->factory->topic->create();
     76
     77                $this->assertTrue( bbp_is_topic_open( $topic_id ) );
     78                bbp_close_topic( $topic_id );
     79                $this->assertFalse( bbp_is_topic_open( $topic_id ) );
     80                bbp_open_topic( $topic_id );
     81                $this->assertTrue( bbp_is_topic_open( $topic_id ) );
     82                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_pending_status_id() ) );
     83                $this->assertTrue( bbp_is_topic_open( $topic_id ) );
     84        }
     85
     86        /**
     87         * @covers ::bbp_is_topic_public
     88         */
     89        public function test_bbp_is_topic_public() {
     90                $topic_id = $this->factory->topic->create();
     91
     92                $this->assertTrue( bbp_is_topic_public( $topic_id ) );
     93                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_closed_status_id() ) );
     94                $this->assertTrue( bbp_is_topic_public( $topic_id ) );
     95                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_pending_status_id() ) );
     96                $this->assertFalse( bbp_is_topic_public( $topic_id ) );
    7697        }
    7798
    7899        /**
    79100         * @covers ::bbp_is_topic_published
    80          * @todo   Implement test_bbp_is_topic_published().
    81101         */
    82102        public function test_bbp_is_topic_published() {
    83                 // Remove the following lines when you implement this test.
    84                 $this->markTestIncomplete(
    85                         'This test has not been implemented yet.'
    86                 );
     103                $topic_id = $this->factory->topic->create();
     104
     105                $this->assertTrue( bbp_is_topic_published( $topic_id ) );
     106                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_pending_status_id() ) );
     107                $this->assertFalse( bbp_is_topic_published( $topic_id ) );
    87108        }
    88109
    89110        /**
    90111         * @covers ::bbp_is_topic_spam
    91          * @todo   Implement test_bbp_is_topic_spam().
    92112         */
    93113        public function test_bbp_is_topic_spam() {
    94                 // Remove the following lines when you implement this test.
    95                 $this->markTestIncomplete(
    96                         'This test has not been implemented yet.'
    97                 );
     114                $topic_id = $this->factory->topic->create();
     115
     116                $this->assertFalse( bbp_is_topic_spam( $topic_id ) );
     117                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_spam_status_id() ) );
     118                $this->assertTrue( bbp_is_topic_spam( $topic_id ) );
    98119        }
    99120
    100121        /**
    101122         * @covers ::bbp_is_topic_trash
    102          * @todo   Implement test_bbp_is_topic_trash().
    103123         */
    104124        public function test_bbp_is_topic_trash() {
    105                 // Remove the following lines when you implement this test.
    106                 $this->markTestIncomplete(
    107                         'This test has not been implemented yet.'
    108                 );
     125                $topic_id = $this->factory->topic->create();
     126
     127                $this->assertFalse( bbp_is_topic_trash( $topic_id ) );
     128                wp_trash_post( $topic_id );
     129                $this->assertTrue( bbp_is_topic_trash( $topic_id ) );
    109130        }
    110131
    111132        /**
    112133         * @covers ::bbp_is_topic_pending
    113          * @todo   Implement test_bbp_is_topic_pending().
    114134         */
    115135        public function test_bbp_is_topic_pending() {
    116                 // Remove the following lines when you implement this test.
    117                 $this->markTestIncomplete(
    118                         'This test has not been implemented yet.'
    119                 );
     136                $topic_id = $this->factory->topic->create();
     137
     138                $this->assertFalse( bbp_is_topic_pending( $topic_id ) );
     139                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_pending_status_id() ) );
     140                $this->assertTrue( bbp_is_topic_pending( $topic_id ) );
    120141        }
    121142
    122143        /**
    123144         * @covers ::bbp_is_topic_private
    124          * @todo   Implement test_bbp_is_topic_private().
    125145         */
    126146        public function test_bbp_is_topic_private() {
    127                 // Remove the following lines when you implement this test.
    128                 $this->markTestIncomplete(
    129                         'This test has not been implemented yet.'
    130                 );
     147                $topic_id = $this->factory->topic->create();
     148
     149                $this->assertFalse( bbp_is_topic_private( $topic_id ) );
     150                wp_update_post( array( 'ID' => $topic_id, 'post_status' => bbp_get_private_status_id() ) );
     151                $this->assertTrue( bbp_is_topic_private( $topic_id ) );
    131152        }
    132153
    133154        /**
    134155         * @covers ::bbp_is_topic_anonymous
    135          * @todo   Implement test_bbp_is_topic_anonymous().
    136156         */
    137157        public function test_bbp_is_topic_anonymous() {
    138                 // Remove the following lines when you implement this test.
    139                 $this->markTestIncomplete(
    140                         'This test has not been implemented yet.'
    141                 );
     158                $user_id  = $this->factory->user->create();
     159                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     160
     161                $this->assertFalse( bbp_is_topic_anonymous( $topic_id ) );
     162                update_post_meta( $topic_id, '_bbp_anonymous_name', 'Guest' );
     163                $this->assertTrue( bbp_is_topic_anonymous( $topic_id ) );
     164                delete_post_meta( $topic_id, '_bbp_anonymous_name' );
     165                update_post_meta( $topic_id, '_bbp_anonymous_email', 'guest@example.org' );
     166                $this->assertTrue( bbp_is_topic_anonymous( $topic_id ) );
     167                delete_post_meta( $topic_id, '_bbp_anonymous_email' );
     168                wp_update_post( array( 'ID' => $topic_id, 'post_author' => 0 ) );
     169                $this->assertTrue( bbp_is_topic_anonymous( $topic_id ) );
    142170        }
    143171}
Note: See TracChangeset for help on using the changeset viewer.