Skip to:
Content

bbPress.org


Ignore:
Timestamp:
08/15/2015 08:59:51 AM (5 years ago)
Author:
netweb
Message:

Tools: Include pending replies in the count when running the "Count pending, spammed, & trashed replies in each topic" repair tool

This changeset ensures that pending replies are included in the topic meta _bbp_reply_count_hidden count after running the repair tool bbp_admin_repair_topic_hidden_reply_count(), includes unit tests.

Props netweb. Fixes #2849

File:
1 edited

Legend:

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

    r5831 r5916  
    167167    /**
    168168     * @covers ::bbp_admin_repair_topic_hidden_reply_count
    169      * @todo   Implement test_bbp_admin_repair_topic_hidden_reply_count().
    170169     */
    171170    public function test_bbp_admin_repair_topic_hidden_reply_count() {
    172         // Remove the following lines when you implement this test.
    173         $this->markTestIncomplete(
    174             'This test has not been implemented yet.'
    175         );
     171
     172        $f = $this->factory->forum->create();
     173
     174        $t = $this->factory->topic->create( array(
     175            'post_parent' => $f,
     176            'topic_meta' => array(
     177                'forum_id' => $f,
     178            ),
     179        ) );
     180
     181        $r = $this->factory->reply->create( array(
     182            'post_parent' => $t,
     183            'reply_meta' => array(
     184                'forum_id' => $f,
     185                'topic_id' => $t,
     186            ),
     187        ) );
     188
     189        $count = bbp_get_topic_reply_count( $t, true );
     190        $this->assertSame( 1, $count );
     191
     192        $r = $this->factory->reply->create_many( 3, array(
     193            'post_parent' => $t,
     194            'reply_meta' => array(
     195                'forum_id' => $f,
     196                'topic_id' => $t,
     197            ),
     198        ) );
     199
     200        bbp_spam_reply( $r[0] );
     201        bbp_unapprove_reply( $r[2] );
     202
     203        $count = bbp_get_topic_reply_count_hidden( $t, true );
     204        $this->assertSame( 2, $count );
     205
     206        // Delete the topic _bbp_reply_count_hidden meta key.
     207        $this->assertTrue( delete_post_meta_by_key( '_bbp_reply_count_hidden' ) );
     208
     209        $count = bbp_get_topic_reply_count_hidden( $t, true );
     210        $this->assertSame( 0, $count );
     211
     212        // Repair the topic hidden reply count meta.
     213        bbp_admin_repair_topic_hidden_reply_count();
     214
     215        bbp_clean_post_cache( $t );
     216
     217        $count = bbp_get_topic_reply_count_hidden( $t, true );
     218        $this->assertSame( 2, $count );
    176219    }
    177220
Note: See TracChangeset for help on using the changeset viewer.