Skip to:
Content

bbPress.org

Changeset 6007


Ignore:
Timestamp:
04/19/2016 07:19:11 AM (9 years ago)
Author:
netweb
Message:

Tests: Add recount forum replies repair tool test test_bbp_admin_repair_forum_reply_count()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/admin/tools.php

    r5968 r6007  
    243243    /**
    244244     * @covers ::bbp_admin_repair_forum_reply_count
    245      * @todo   Implement test_bbp_admin_repair_forum_reply_count().
    246245     */
    247246    public function test_bbp_admin_repair_forum_reply_count() {
    248         // Remove the following lines when you implement this test.
    249         $this->markTestIncomplete(
    250             'This test has not been implemented yet.'
    251         );
     247        $c = $this->factory->forum->create( array(
     248            'forum_meta' => array(
     249                'forum_type' => 'category',
     250                'status'     => 'open',
     251            ),
     252        ) );
     253
     254        $f = $this->factory->forum->create( array(
     255            'post_parent' => $c,
     256            'forum_meta' => array(
     257                'forum_id'   => $c,
     258                'forum_type' => 'forum',
     259                'status'     => 'open',
     260            ),
     261        ) );
     262
     263        $t = $this->factory->topic->create( array(
     264            'post_parent' => $f,
     265            'topic_meta' => array(
     266                'forum_id' => $f,
     267            ),
     268        ) );
     269
     270        $r = $this->factory->reply->create( array(
     271            'post_parent' => $t,
     272            'reply_meta' => array(
     273                'forum_id' => $f,
     274                'topic_id' => $t,
     275            ),
     276        ) );
     277
     278        $count = bbp_get_forum_reply_count( $f, true, true );
     279        $this->assertSame( 1, $count );
     280
     281        $r = $this->factory->reply->create_many( 3, array(
     282            'post_parent' => $t,
     283            'reply_meta' => array(
     284                'forum_id' => $f,
     285                'topic_id' => $t,
     286            ),
     287        ) );
     288
     289        bbp_update_forum_reply_count( $c );
     290        bbp_update_forum_reply_count( $f );
     291
     292        // Category reply count.
     293        $count = bbp_get_forum_reply_count( $c, false, true );
     294        $this->assertSame( 0, $count );
     295
     296        // Category total reply count.
     297        $count = bbp_get_forum_reply_count( $c, true, true );
     298        $this->assertSame( 4, $count );
     299
     300        // Forum reply count.
     301        $count = bbp_get_forum_reply_count( $f, false, true );
     302        $this->assertSame( 4, $count );
     303
     304        // Forum total reply count.
     305        $count = bbp_get_forum_reply_count( $f, true, true );
     306        $this->assertSame( 4, $count );
     307
     308        bbp_spam_reply( $r[0] );
     309        bbp_unapprove_reply( $r[2] );
     310
     311        // Category reply count.
     312        $count = bbp_get_forum_reply_count( $c, false, true );
     313        $this->assertSame( 0, $count );
     314
     315        // Category total reply count.
     316        $count = bbp_get_forum_reply_count( $c, true, true );
     317        $this->assertSame( 2, $count );
     318
     319        // Forum reply count.
     320        $count = bbp_get_forum_reply_count( $f, false, true );
     321        $this->assertSame( 2, $count );
     322
     323        // Forum total reply count.
     324        $count = bbp_get_forum_reply_count( $f, true, true );
     325        $this->assertSame( 2, $count );
     326
     327        // Delete the category _bbp_total_reply_count meta key.
     328        $this->assertTrue( delete_post_meta_by_key( '_bbp_total_reply_count' ) );
     329
     330        // Delete the forum _bbp_reply_count meta key.
     331        $this->assertTrue( delete_post_meta_by_key( '_bbp_reply_count' ) );
     332
     333        // Category reply count.
     334        $count = bbp_get_forum_reply_count( $c, false, true );
     335        $this->assertSame( 0, $count );
     336
     337        // Category total reply count.
     338        $count = bbp_get_forum_reply_count( $c, true, true );
     339        $this->assertSame( 0, $count );
     340
     341        // Forum reply count.
     342        $count = bbp_get_forum_reply_count( $f, false, true );
     343        $this->assertSame( 0, $count );
     344
     345        // Forum total reply count.
     346        $count = bbp_get_forum_reply_count( $f, true, true );
     347        $this->assertSame( 0, $count );
     348
     349        // Repair the forum reply count meta.
     350        bbp_admin_repair_forum_reply_count();
     351
     352        // Category reply count.
     353        $count = bbp_get_forum_reply_count( $c, false, true );
     354        $this->assertSame( 0, $count );
     355
     356        // Category total reply count.
     357        $count = bbp_get_forum_reply_count( $c, true, true );
     358        $this->assertSame( 2, $count );
     359
     360        // Forum reply count.
     361        $count = bbp_get_forum_reply_count( $f, false, true );
     362        $this->assertSame( 2, $count );
     363
     364        // Forum total reply count.
     365        $count = bbp_get_forum_reply_count( $f, true, true );
     366        $this->assertSame( 2, $count );
    252367    }
    253368
Note: See TracChangeset for help on using the changeset viewer.