Skip to:
Content

bbPress.org

Changeset 7787


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

Tests: Cover parent queries and anonymous counts.

Replace two incomplete stubs with checks for parent include and exclude filters, WordPress-native behavior, and anonymous topic and reply counts.

In trunk, for 2.7.

See #3695.

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

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/common/query.php

    r6849 r7787  
    1010class BBP_Tests_Common_Functions_Query extends BBP_UnitTestCase {
    1111
    12         /**
     12        /**
    1313         * @covers ::bbp_query_post_parent__in
    14          * @todo   Implement test_bbp_query_post_parent__in().
    1514         */
    1615        public function test_bbp_query_post_parent__in() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                global $wp;
     17
     18                $old_query_vars = $wp->private_query_vars;
     19                $wp->private_query_vars = array_diff( $old_query_vars, array( 'post_parent__in' ) );
     20                $query = (object) array( 'query_vars' => array( 'post_parent' => '', 'post_parent__in' => array( '12', '34' ), 'post_parent__not_in' => array() ) );
     21
     22                try {
     23                        $this->assertSame( 'base', bbp_query_post_parent__in( 'base' ) );
     24                        $this->assertSame( 'base AND ' . bbp_db()->posts . '.post_parent IN (12,34)', bbp_query_post_parent__in( 'base', $query ) );
     25
     26                        $query->query_vars['post_parent__in'] = array();
     27                        $query->query_vars['post_parent__not_in'] = array( '56', '78' );
     28                        $this->assertSame( 'base AND ' . bbp_db()->posts . '.post_parent NOT IN (56,78)', bbp_query_post_parent__in( 'base', $query ) );
     29
     30                        $query->query_vars['post_parent'] = 12;
     31                        $this->assertSame( 'base', bbp_query_post_parent__in( 'base', $query ) );
     32
     33                        $wp->private_query_vars = $old_query_vars;
     34                        $wp->private_query_vars[] = 'post_parent__in';
     35                        $query->query_vars['post_parent'] = '';
     36                        $this->assertSame( 'base', bbp_query_post_parent__in( 'base', $query ) );
     37                } finally {
     38                        $wp->private_query_vars = $old_query_vars;
     39                }
    2140        }
    2241
  • trunk/tests/phpunit/testcases/topics/functions/counts.php

    r7467 r7787  
    695695        /**
    696696         * @covers ::bbp_update_topic_anonymous_reply_count
    697          * @todo   Implement test_bbp_update_topic_anonymous_reply_count().
    698697         */
    699698        public function test_bbp_update_topic_anonymous_reply_count() {
    700                 // Remove the following lines when you implement this test.
    701                 $this->markTestIncomplete(
    702                         'This test has not been implemented yet.'
    703                 );
     699                $user_id  = $this->factory->user->create();
     700                $forum_id = $this->factory->forum->create();
     701                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id, 'post_author' => $user_id ) );
     702                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0 ) );
     703                $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     704                $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0, 'post_status' => bbp_get_spam_status_id() ) );
     705
     706                $this->assertSame( 1, bbp_update_topic_anonymous_reply_count( $topic_id ) );
     707                $this->assertSame( '1', get_post_meta( $topic_id, '_bbp_anonymous_reply_count', true ) );
     708                $this->assertSame( 1, bbp_update_topic_anonymous_reply_count( $reply_id ) );
     709
     710                wp_update_post( array( 'ID' => $topic_id, 'post_author' => 0 ) );
     711                $this->assertSame( 2, bbp_update_topic_anonymous_reply_count( $topic_id ) );
     712                $this->assertSame( '2', get_post_meta( $topic_id, '_bbp_anonymous_reply_count', true ) );
    704713        }
    705714}
Note: See TracChangeset for help on using the changeset viewer.