Skip to:
Content

bbPress.org

Changeset 5931


Ignore:
Timestamp:
08/25/2015 11:36:49 PM (6 years ago)
Author:
netweb
Message:

Tests: Add topic and topic reply spam/unspam tests test_bbp_spam_topic(), test_bbp_spam_topic_replies(), test_bbp_unspam_topic(), and test_bbp_unspam_topic_replies()

Props netweb. See #2494.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/topics/functions/status.php

    r5761 r5931  
    7878    /**
    7979     * @covers ::bbp_spam_topic
    80      * @todo   Implement test_bbp_spam_topic().
    8180     */
    8281    public function test_bbp_spam_topic() {
    83         // Remove the following lines when you implement this test.
    84         $this->markTestIncomplete(
    85             'This test has not been implemented yet.'
    86         );
     82        $f = $this->factory->forum->create();
     83
     84        $now = time();
     85        $post_date_topic = date( 'Y-m-d H:i:s', $now - 60 * 60 * 100 );
     86        $post_date_reply = date( 'Y-m-d H:i:s', $now - 60 * 60 * 80 );
     87
     88        $topic_time = '4 days, 4 hours ago';
     89        $reply_time = '3 days, 8 hours ago';
     90
     91        $t = $this->factory->topic->create( array(
     92            'post_parent' => $f,
     93            'post_date' => $post_date_topic,
     94            'topic_meta' => array(
     95                'forum_id' => $f,
     96            ),
     97        ) );
     98        $r = $this->factory->reply->create_many( 2, array(
     99            'post_parent' => $t,
     100            'post_date' => $post_date_reply,
     101            'reply_meta' => array(
     102                'forum_id' => $f,
     103                'topic_id' => $t,
     104            ),
     105        ) );
     106
     107        bbp_spam_topic( $t );
     108
     109        $count = bbp_get_forum_topic_count( $f, false, true );
     110        $this->assertSame( 0, $count );
     111
     112        $count = bbp_get_forum_topic_count_hidden( $f, true );
     113        $this->assertSame( 1, $count );
     114
     115        $count = bbp_get_forum_reply_count( $f, false, true );
     116        $this->assertSame( 0, $count );
     117
     118        $last_topic_id = bbp_get_forum_last_topic_id( $f );
     119        $this->assertSame( $t, $last_topic_id );
     120
     121        $last_reply_id = bbp_get_forum_last_reply_id( $f );
     122        $this->assertSame( $t, $last_reply_id );
     123
     124        $last_active_id = bbp_get_forum_last_active_id( $f );
     125        $this->assertSame( $t, $last_active_id );
     126
     127        $last_active_time = bbp_get_forum_last_active_time( $f );
     128        $this->assertSame( $topic_time, $last_active_time );
     129
     130        $count = bbp_get_topic_reply_count( $t, true, true );
     131        $this->assertSame( 0, $count );
     132
     133        $count = bbp_get_topic_reply_count_hidden( $t, true, true );
     134        $this->assertSame( 2, $count );
     135
     136        // ToDo: Result should be 0 when a topic has no replies
     137    //  $last_reply_id = bbp_get_topic_last_reply_id( $t );
     138    //  $this->assertSame( $t, $last_reply_id );
     139
     140        $last_active_id = bbp_get_topic_last_active_id( $t );
     141        $this->assertSame( $t, $last_active_id );
     142
     143        $last_active_time = bbp_get_topic_last_active_time( $t );
     144        $this->assertSame( $topic_time, $last_active_time );
     145
     146        $topic_spam_status = get_post_status( $t );
     147        $this->assertSame( bbp_get_spam_status_id(), $topic_spam_status );
     148
     149        $topic_meta_pre_spammed_replies = get_post_meta( $t, '_bbp_pre_spammed_replies', true );
     150        $this->assertEquals( array( $r[1], $r[0] ), $topic_meta_pre_spammed_replies );
     151
     152        $topic_spam_meta_status = get_post_meta( $t, '_bbp_spam_meta_status', true );
     153        $this->assertSame( bbp_get_public_status_id(), $topic_spam_meta_status );
    87154    }
    88155
    89156    /**
    90157     * @covers ::bbp_spam_topic_replies
    91      * @todo   Implement test_bbp_spam_topic_replies().
    92158     */
    93159    public function test_bbp_spam_topic_replies() {
    94         // Remove the following lines when you implement this test.
    95         $this->markTestIncomplete(
    96             'This test has not been implemented yet.'
    97         );
     160        $f = $this->factory->forum->create();
     161
     162        $now = time();
     163        $post_date_topic = date( 'Y-m-d H:i:s', $now - 60 * 60 * 100 );
     164        $post_date_reply = date( 'Y-m-d H:i:s', $now - 60 * 60 * 80 );
     165
     166        $topic_time = '4 days, 4 hours ago';
     167        $reply_time = '3 days, 8 hours ago';
     168
     169        $t = $this->factory->topic->create( array(
     170            'post_parent' => $f,
     171            'post_date' => $post_date_topic,
     172            'topic_meta' => array(
     173                'forum_id' => $f,
     174            ),
     175        ) );
     176        $r = $this->factory->reply->create_many( 2, array(
     177            'post_parent' => $t,
     178            'post_date' => $post_date_reply,
     179            'reply_meta' => array(
     180                'forum_id' => $f,
     181                'topic_id' => $t,
     182            ),
     183        ) );
     184
     185        bbp_spam_topic_replies( $t );
     186
     187        $count = bbp_get_forum_reply_count( $f, false, true );
     188        $this->assertSame( 0, $count );
     189
     190        $last_reply_id = bbp_get_forum_last_reply_id( $f );
     191        $this->assertSame( $t, $last_reply_id );
     192
     193        $last_active_id = bbp_get_forum_last_active_id( $f );
     194        $this->assertSame( $t, $last_active_id );
     195
     196        // ToDo: Result should be topic time when a topic has no replies
     197    //  $last_active_time = bbp_get_forum_last_active_time( $f );
     198    //  $this->assertSame( $topic_time, $last_active_time );
     199
     200        $count = bbp_get_topic_reply_count( $t, true, true );
     201        $this->assertSame( 0, $count );
     202
     203        $count = bbp_get_topic_reply_count_hidden( $t, true, true );
     204        $this->assertSame( 2, $count );
     205
     206        // ToDo: Result should be 0 when a topic has no replies
     207    //  $last_reply_id = bbp_get_topic_last_reply_id( $t );
     208    //  $this->assertSame( $t, $last_reply_id );
     209
     210        $last_active_id = bbp_get_topic_last_active_id( $t );
     211        $this->assertSame( $t, $last_active_id );
     212
     213        $last_active_time = bbp_get_topic_last_active_time( $t );
     214        $this->assertSame( $topic_time, $last_active_time );
     215
     216        $topic_meta_pre_spammed_replies = get_post_meta( $t, '_bbp_pre_spammed_replies', true );
     217        $this->assertEquals( array( $r[1], $r[0] ), $topic_meta_pre_spammed_replies );
     218
     219        foreach ( $r as $reply ) {
     220            $reply_status = get_post_status( $reply );
     221            $this->assertSame( bbp_get_trash_status_id(), $reply_status );
     222
     223            $reply_meta_status = get_post_meta( $reply, '_wp_trash_meta_status', true );
     224            $this->assertSame( bbp_get_public_status_id(), $reply_meta_status );
     225        }
    98226    }
    99227
    100228    /**
    101229     * @covers ::bbp_unspam_topic
    102      * @todo   Implement test_bbp_unspam_topic().
    103230     */
    104231    public function test_bbp_unspam_topic() {
    105         // Remove the following lines when you implement this test.
    106         $this->markTestIncomplete(
    107             'This test has not been implemented yet.'
    108         );
     232        $f = $this->factory->forum->create();
     233
     234        $now = time();
     235        $post_date_topic = date( 'Y-m-d H:i:s', $now - 60 * 60 * 100 );
     236        $post_date_reply = date( 'Y-m-d H:i:s', $now - 60 * 60 * 80 );
     237
     238        $topic_time = '4 days, 4 hours ago';
     239        $reply_time = '3 days, 8 hours ago';
     240
     241        $t = $this->factory->topic->create( array(
     242            'post_parent' => $f,
     243            'post_date' => $post_date_topic,
     244            'topic_meta' => array(
     245                'forum_id' => $f,
     246            ),
     247        ) );
     248        $r = $this->factory->reply->create_many( 2, array(
     249            'post_parent' => $t,
     250            'post_date' => $post_date_reply,
     251            'reply_meta' => array(
     252                'forum_id' => $f,
     253                'topic_id' => $t,
     254            ),
     255        ) );
     256
     257        bbp_spam_topic( $t );
     258
     259        bbp_unspam_topic( $t );
     260
     261        $topic_status = get_post_status( $t );
     262        $this->assertSame( bbp_get_public_status_id(), $topic_status );
     263
     264        $this->assertEquals( '', get_post_meta( $t, '_bbp_pre_spammed_replies', true ) );
     265        $this->assertEquals( array(), get_post_meta( $t, '_bbp_pre_spammed_replies', false ) );
     266
     267        $this->assertEquals( '', get_post_meta( $t, '_bbp_spam_meta_status', true ) );
     268        $this->assertEquals( array(), get_post_meta( $t, '_bbp_spam_meta_status', false ) );
     269
     270        $count = bbp_get_forum_topic_count( $f, false, true );
     271        $this->assertSame( 1, $count );
     272
     273        $count = bbp_get_forum_topic_count_hidden( $f, true );
     274        $this->assertSame( 0, $count );
     275
     276        $count = bbp_get_forum_reply_count( $f, false, true );
     277        $this->assertSame( 2, $count );
     278
     279        $last_topic_id = bbp_get_forum_last_topic_id( $f );
     280        $this->assertSame( $t, $last_topic_id );
     281
     282        $last_reply_id = bbp_get_forum_last_reply_id( $f );
     283        $this->assertSame( $r[1], $last_reply_id );
     284
     285        $last_active_id = bbp_get_forum_last_active_id( $f );
     286        $this->assertSame( $r[1], $last_active_id );
     287
     288        $last_active_time = bbp_get_forum_last_active_time( $f );
     289        $this->assertSame( $reply_time, $last_active_time );
     290
     291        $count = bbp_get_topic_reply_count( $t, true, true );
     292        $this->assertSame( 2, $count );
     293
     294        $count = bbp_get_topic_reply_count_hidden( $t, true, true );
     295        $this->assertSame( 0, $count );
     296
     297        $last_reply_id = bbp_get_topic_last_reply_id( $t );
     298        $this->assertSame( $r[1], $last_reply_id );
     299
     300        $last_active_id = bbp_get_topic_last_active_id( $t );
     301        $this->assertSame( $r[1], $last_active_id );
     302
     303        $last_active_time = bbp_get_topic_last_active_time( $t );
     304        $this->assertSame( $reply_time, $last_active_time );
    109305    }
    110306
    111307    /**
    112308     * @covers ::bbp_unspam_topic_replies
    113      * @todo   Implement test_bbp_unspam_topic_replies().
    114309     */
    115310    public function test_bbp_unspam_topic_replies() {
    116         // Remove the following lines when you implement this test.
    117         $this->markTestIncomplete(
    118             'This test has not been implemented yet.'
    119         );
     311        $f = $this->factory->forum->create();
     312
     313        $now = time();
     314        $post_date_topic = date( 'Y-m-d H:i:s', $now - 60 * 60 * 100 );
     315        $post_date_reply = date( 'Y-m-d H:i:s', $now - 60 * 60 * 80 );
     316
     317        $topic_time = '4 days, 4 hours ago';
     318        $reply_time = '3 days, 8 hours ago';
     319
     320        $t = $this->factory->topic->create( array(
     321            'post_parent' => $f,
     322            'post_date' => $post_date_topic,
     323            'topic_meta' => array(
     324                'forum_id' => $f,
     325            ),
     326        ) );
     327        $r = $this->factory->reply->create_many( 2, array(
     328            'post_parent' => $t,
     329            'post_date' => $post_date_reply,
     330            'reply_meta' => array(
     331                'forum_id' => $f,
     332                'topic_id' => $t,
     333            ),
     334        ) );
     335
     336        bbp_spam_topic_replies( $t );
     337
     338        bbp_unspam_topic_replies( $t );
     339
     340        $this->assertEquals( '', get_post_meta( $t, '_bbp_pre_spammed_replies', true ) );
     341        $this->assertEquals( array(), get_post_meta( $t, '_bbp_pre_spammed_replies', false ) );
     342
     343        foreach ( $r as $reply ) {
     344            $reply_status = get_post_status( $reply );
     345            $this->assertSame( bbp_get_public_status_id(), $reply_status );
     346
     347            $this->assertEquals( '', get_post_meta( $reply, '_wp_trash_meta_status', true ) );
     348            $this->assertEquals( array(), get_post_meta( $reply, '_wp_trash_meta_status', false ) );
     349        }
     350
     351        $count = bbp_get_forum_reply_count( $f, false, true );
     352        $this->assertSame( 2, $count );
     353
     354        $last_reply_id = bbp_get_forum_last_reply_id( $f );
     355        $this->assertSame( $r[1], $last_reply_id );
     356
     357        $last_active_id = bbp_get_forum_last_active_id( $f );
     358        $this->assertSame( $r[1], $last_active_id );
     359
     360        $last_active_time = bbp_get_forum_last_active_time( $f );
     361        $this->assertSame( $reply_time, $last_active_time );
     362
     363        $count = bbp_get_topic_reply_count( $t, true, true );
     364        $this->assertSame( 2, $count );
     365
     366        $count = bbp_get_topic_reply_count_hidden( $t, true, true );
     367        $this->assertSame( 0, $count );
     368
     369        $last_reply_id = bbp_get_topic_last_reply_id( $t );
     370        $this->assertSame( $r[1], $last_reply_id );
     371
     372        $last_active_id = bbp_get_topic_last_active_id( $t );
     373        $this->assertSame( $r[1], $last_active_id );
     374
     375        $last_active_time = bbp_get_topic_last_active_time( $t );
     376        $this->assertSame( $reply_time, $last_active_time );
    120377    }
    121378
Note: See TracChangeset for help on using the changeset viewer.