Exemplo n.º 1
0
 /**
  * @group canonical
  * @covers ::bbp_insert_forum
  */
 public function test_bbp_insert_forum()
 {
     $f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1'));
     $now = time();
     $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Get the forum.
     $forum = bbp_get_forum($f);
     // Forum post.
     $this->assertSame('Forum 1', bbp_get_forum_title($f));
     $this->assertSame('Content of Forum 1', bbp_get_forum_content($f));
     $this->assertSame('open', bbp_get_forum_status($f));
     $this->assertSame('forum', bbp_get_forum_type($f));
     $this->assertTrue(bbp_is_forum_public($f));
     $this->assertSame(0, bbp_get_forum_parent_id($f));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $forum->post_name, $forum->guid);
     // Forum meta.
     $this->assertSame(0, bbp_get_forum_subforum_count($f, true));
     $this->assertSame(1, bbp_get_forum_topic_count($f, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($f, true, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true));
     $this->assertSame(1, bbp_get_forum_reply_count($f, false, true));
     $this->assertSame(1, bbp_get_forum_reply_count($f, true, true));
     $this->assertSame(2, bbp_get_forum_post_count($f, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($f, true, true));
     $this->assertSame($t, bbp_get_forum_last_topic_id($f));
     $this->assertSame($r, bbp_get_forum_last_reply_id($f));
     $this->assertSame($r, bbp_get_forum_last_active_id($f));
     $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f));
 }
Exemplo n.º 2
0
/**
 * Bump the total hidden topic count of a forum
 *
 * @since bbPress (r3825)
 *
 * @param int $forum_id Optional. Forum id.
 * @param int $difference Optional. Default 1
 * @uses bbp_get_forum_id() To get the forum id
 * @uses update_post_meta() To update the forum's topic count meta
 * @uses apply_filters() Calls 'bbp_bump_forum_topic_count_hidden' with the
 *                        topic count, forum id, and difference
 * @return int Forum hidden topic count
 */
function bbp_bump_forum_topic_count_hidden($forum_id = 0, $difference = 1)
{
    // Get some counts
    $forum_id = bbp_get_forum_id($forum_id);
    $topic_count = bbp_get_forum_topic_count_hidden($forum_id, true);
    $new_count = (int) $topic_count + (int) $difference;
    // Update this forum id
    update_post_meta($forum_id, '_bbp_topic_count_hidden', (int) $new_count);
    return (int) apply_filters('bbp_bump_forum_topic_count_hidden', (int) $new_count, $forum_id, (int) $difference);
}
Exemplo n.º 3
0
/**
 * Output total hidden topic count of a forum (hidden includes trashed and
 * spammed topics)
 *
 * @since bbPress (r2883)
 *
 * @param int $forum_id Optional. Topic id
 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
 */
function bbp_forum_topic_count_hidden($forum_id = 0)
{
    echo bbp_get_forum_topic_count_hidden($forum_id);
}
Exemplo n.º 4
0
/**
 * Output total hidden topic count of a forum (hidden includes trashed and
 * spammed topics)
 *
 * @since bbPress (r2883)
 *
 * @param int $forum_id Optional. Topic id
 * @param boolean $integer Optional. Whether or not to format the result
 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
 */
function bbp_forum_topic_count_hidden($forum_id = 0, $integer = false)
{
    echo bbp_get_forum_topic_count_hidden($forum_id, $integer);
}
Exemplo n.º 5
0
 /**
  * @group canonical
  * @covers ::bbp_create_initial_content
  */
 public function test_bbp_create_initial_content()
 {
     $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open')));
     bbp_create_initial_content(array('forum_parent' => $category_id));
     $forum_id = bbp_forum_query_subforum_ids($category_id);
     $forum_id = (int) $forum_id[0];
     $topic_id = bbp_get_forum_last_topic_id($forum_id);
     $reply_id = bbp_get_forum_last_reply_id($forum_id);
     // Forum post
     $this->assertSame('General', bbp_get_forum_title($forum_id));
     $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id));
     $this->assertSame('open', bbp_get_forum_status($forum_id));
     $this->assertTrue(bbp_is_forum_public($forum_id));
     $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id));
     // Topic post
     $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame('Hello World!', bbp_get_topic_title($topic_id));
     remove_all_filters('bbp_get_topic_content');
     $topic_content = "I am the first topic in your new forums.";
     $this->assertSame($topic_content, bbp_get_topic_content($topic_id));
     $this->assertSame('publish', bbp_get_topic_status($topic_id));
     $this->assertTrue(bbp_is_topic_published($topic_id));
     // Reply post
     $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id));
     $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id));
     remove_all_filters('bbp_get_reply_content');
     $reply_content = "Oh, and this is what a reply looks like.";
     $this->assertSame($reply_content, bbp_get_reply_content($reply_id));
     $this->assertSame('publish', bbp_get_reply_status($reply_id));
     $this->assertTrue(bbp_is_reply_published($reply_id));
     // Category meta
     $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true));
     $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true));
     $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true));
     $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id));
     $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id));
     // Forum meta
     $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true));
     $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true));
     $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true));
     $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id));
     $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id));
     // Topic meta
     $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id));
     $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id));
     // Reply Meta
     $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id));
     $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
 }
Exemplo n.º 6
0
 /**
  * @covers ::bbp_unspam_topic
  */
 public function test_bbp_unspam_topic()
 {
     $f = $this->factory->forum->create();
     $now = time();
     $post_date_topic = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $post_date_reply = date('Y-m-d H:i:s', $now - 60 * 60 * 80);
     $topic_time = '4 days, 4 hours ago';
     $reply_time = '3 days, 8 hours ago';
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date_topic, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create_many(2, array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_spam_topic($t);
     bbp_unspam_topic($t);
     $topic_status = get_post_status($t);
     $this->assertSame(bbp_get_public_status_id(), $topic_status);
     $this->assertEquals('', get_post_meta($t, '_bbp_pre_spammed_replies', true));
     $this->assertEquals(array(), get_post_meta($t, '_bbp_pre_spammed_replies', false));
     $this->assertEquals('', get_post_meta($t, '_bbp_spam_meta_status', true));
     $this->assertEquals(array(), get_post_meta($t, '_bbp_spam_meta_status', false));
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(1, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(0, $count);
     $count = bbp_get_forum_reply_count($f, false, true);
     $this->assertSame(2, $count);
     $last_topic_id = bbp_get_forum_last_topic_id($f);
     $this->assertSame($t, $last_topic_id);
     $last_reply_id = bbp_get_forum_last_reply_id($f);
     $this->assertSame($r[1], $last_reply_id);
     $last_active_id = bbp_get_forum_last_active_id($f);
     $this->assertSame($r[1], $last_active_id);
     $last_active_time = bbp_get_forum_last_active_time($f);
     $this->assertSame($reply_time, $last_active_time);
     $count = bbp_get_topic_reply_count($t, true, true);
     $this->assertSame(2, $count);
     $count = bbp_get_topic_reply_count_hidden($t, true, true);
     $this->assertSame(0, $count);
     $last_reply_id = bbp_get_topic_last_reply_id($t);
     $this->assertSame($r[1], $last_reply_id);
     $last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r[1], $last_active_id);
     $last_active_time = bbp_get_topic_last_active_time($t);
     $this->assertSame($reply_time, $last_active_time);
 }
Exemplo n.º 7
0
 /**
  * @covers ::bbp_admin_repair_forum_topic_count
  */
 public function test_bbp_admin_repair_forum_topic_count()
 {
     $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category', 'status' => 'open')));
     $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open')));
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(1, $count);
     $t = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     bbp_update_forum_topic_count($c);
     bbp_update_forum_topic_count($f);
     // Category topic count.
     $count = bbp_get_forum_topic_count($c, false, true);
     $this->assertSame(0, $count);
     // Category total topic count.
     $count = bbp_get_forum_topic_count($c, true, true);
     $this->assertSame(4, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Forum topic count.
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(4, $count);
     // Forum total topic count.
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(4, $count);
     // Forum topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(0, $count);
     bbp_spam_topic($t[0]);
     bbp_unapprove_topic($t[2]);
     // Category topic count.
     $count = bbp_get_forum_topic_count($c, false, true);
     $this->assertSame(0, $count);
     // Category total topic count.
     $count = bbp_get_forum_topic_count($c, true, true);
     $this->assertSame(2, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Forum topic count.
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(2, $count);
     // Forum total topic count.
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(2, $count);
     // Forum topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(2, $count);
     // Delete the _bbp_total_topic_count meta key.
     $this->assertTrue(delete_post_meta_by_key('_bbp_topic_count_hidden'));
     // Delete the _bbp_total_topic_count meta key.
     $this->assertTrue(delete_post_meta_by_key('_bbp_total_topic_count'));
     // Delete the  _bbp_topic_count meta key.
     $this->assertTrue(delete_post_meta_by_key('_bbp_topic_count'));
     // Category topic count.
     $count = bbp_get_forum_topic_count($c, false, true);
     $this->assertSame(0, $count);
     // Category total topic count.
     $count = bbp_get_forum_topic_count($c, true, true);
     $this->assertSame(0, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Forum topic count.
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(0, $count);
     // Forum total topic count.
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(0, $count);
     // Forum topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(0, $count);
     // Repair the forum topic count meta.
     bbp_admin_repair_forum_topic_count();
     // Category topic count.
     $count = bbp_get_forum_topic_count($c, false, true);
     $this->assertSame(0, $count);
     // Category total topic count.
     $count = bbp_get_forum_topic_count($c, true, true);
     $this->assertSame(2, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Forum topic count.
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(2, $count);
     // Forum total topic count.
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(2, $count);
     // Forum topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(2, $count);
 }
Exemplo n.º 8
0
 /**
  * @covers ::bbp_forum_topic_count_hidden
  * @covers ::bbp_get_forum_topic_count_hidden
  */
 public function test_bbp_get_forum_topic_count_hidden()
 {
     $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category')));
     $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c)));
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->topic->create_many($int_value, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id()));
     bbp_update_forum_topic_count_hidden($c);
     bbp_update_forum_topic_count_hidden($f);
     // Forum output.
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->expectOutputString($formatted_value);
     bbp_forum_topic_count_hidden($f);
     // Forum formatted string.
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->assertSame($formatted_value, $count);
     // Forum integer.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame($int_value, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Category total topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
 }
Exemplo n.º 9
0
/**
 * Bump the total hidden topic count of a forum
 *
 * @since 2.1.0 bbPress (r3825)
 *
 * @param int $forum_id Optional. Forum id.
 * @param int $difference Optional. Default 1
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_get_forum_topic_count_hidden To get the forum's hidden topic count
 * @uses update_post_meta() To update the forum's topic count meta
 * @uses apply_filters() Calls 'bbp_bump_forum_topic_count_hidden' with the
 *                        topic count, forum id, and difference
 * @return int Forum hidden topic count
 */
function bbp_bump_forum_topic_count_hidden($forum_id = 0, $difference = 1)
{
    // Bail if no bump
    if (empty($difference)) {
        return false;
    }
    // Get some counts
    $forum_id = bbp_get_forum_id($forum_id);
    $topic_count = bbp_get_forum_topic_count_hidden($forum_id, true);
    $difference = (int) $difference;
    $new_count = (int) ($topic_count + $difference);
    // Update this forum id
    update_post_meta($forum_id, '_bbp_topic_count_hidden', $new_count);
    return (int) apply_filters('bbp_bump_forum_topic_count_hidden', $new_count, $forum_id, $difference);
}
Exemplo n.º 10
0
 /**
  * @covers ::bbp_update_forum_topic_count_hidden
  */
 public function test_bbp_update_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(0, $count);
     $t = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(0, $count);
     bbp_spam_topic($t[2]);
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(1, $count);
     bbp_unapprove_topic($t[0]);
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(2, $count);
 }
Exemplo n.º 11
0
 /**
  * @covers ::bbp_forum_topic_count_hidden
  * @covers ::bbp_get_forum_topic_count_hidden
  */
 public function test_bbp_get_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->topic->create_many($int_value, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id()));
     bbp_update_forum_topic_count_hidden($f);
     // Output
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->expectOutputString($formatted_value);
     bbp_forum_topic_count_hidden($f);
     // Formatted string
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame($int_value, $count);
 }