/** * @group canonical * @covers ::bbp_insert_topic */ public function test_bbp_insert_topic() { $f = $this->factory->forum->create(); $now = time(); $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $t = $this->factory->topic->create(array('post_title' => 'Topic 1', 'post_content' => 'Content for Topic 1', '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 topic. $topic = bbp_get_topic($t); remove_all_filters('bbp_get_topic_content'); // Topic post. $this->assertSame('Topic 1', bbp_get_topic_title($t)); $this->assertSame('Content for Topic 1', bbp_get_topic_content($t)); $this->assertSame('publish', bbp_get_topic_status($t)); $this->assertSame($f, wp_get_post_parent_id($t)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?topic=' . $topic->post_name, $topic->guid); // Topic meta. $this->assertSame($f, bbp_get_topic_forum_id($t)); $this->assertSame(1, bbp_get_topic_reply_count($t, true)); $this->assertSame(0, bbp_get_topic_reply_count_hidden($t, true)); $this->assertSame(1, bbp_get_topic_voice_count($t, true)); $this->assertSame($r, bbp_get_topic_last_reply_id($t)); $this->assertSame($r, bbp_get_topic_last_active_id($t)); $this->assertSame('4 days, 4 hours ago', bbp_get_topic_last_active_time($t)); }
/** * @covers ::bbp_topic_reply_count_hidden * @covers ::bbp_get_topic_reply_count_hidden */ public function test_bbp_get_topic_reply_count_hidden() { $f = $this->factory->forum->create(); $int_value = 3; $formatted_value = bbp_number_format($int_value); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create_many($int_value, array('post_parent' => $t, 'post_status' => bbp_get_spam_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_update_topic_reply_count_hidden($t); bbp_spam_reply($r[1]); // Output $this->expectOutputString($formatted_value); bbp_topic_reply_count_hidden($t); // Formatted string $count = bbp_get_topic_reply_count_hidden($t, false); $this->assertSame($formatted_value, $count); // Integer $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame($int_value, $count); }
/** * Output total hidden reply count of a topic (hidden includes trashed and * spammed replies) * * @since 2.0.0 bbPress (r2740) * * @param int $topic_id Optional. Topic id * @param boolean $integer Optional. Whether or not to format the result * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count */ function bbp_topic_reply_count_hidden($topic_id = 0, $integer = false) { echo bbp_get_topic_reply_count_hidden($topic_id, $integer); }
/** * Bump the total hidden reply count of a topic * * @since bbPress (r3825) * * @param int $topic_id Optional. Forum id. * @param int $difference Optional. Default 1 * @uses bbp_get_topic_id() To get the topic id * @uses update_post_meta() To update the topic's reply count meta * @uses apply_filters() Calls 'bbp_bump_topic_reply_count_hidden' with the * reply count, topic id, and difference * @return int Forum hidden reply count */ function bbp_bump_topic_reply_count_hidden($topic_id = 0, $difference = 1) { // Get counts $topic_id = bbp_get_topic_id($topic_id); $reply_count = bbp_get_topic_reply_count_hidden($topic_id, true); $new_count = (int) $reply_count + (int) $difference; // Update this topic id's hidder reply count update_post_meta($topic_id, '_bbp_reply_count_hidden', (int) $new_count); return (int) apply_filters('bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference); }
/** * @covers ::bbp_unspam_topic_replies */ public function test_bbp_unspam_topic_replies() { $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_replies($t); bbp_unspam_topic_replies($t); $this->assertEquals('', get_post_meta($t, '_bbp_pre_spammed_replies', true)); $this->assertEquals(array(), get_post_meta($t, '_bbp_pre_spammed_replies', false)); foreach ($r as $reply) { $reply_status = get_post_status($reply); $this->assertSame(bbp_get_public_status_id(), $reply_status); $this->assertEquals('', get_post_meta($reply, '_wp_trash_meta_status', true)); $this->assertEquals(array(), get_post_meta($reply, '_wp_trash_meta_status', false)); } $count = bbp_get_forum_reply_count($f, false, true); $this->assertSame(2, $count); $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); }
/** * @covers ::bbp_update_topic_reply_count_hidden */ public function test_bbp_update_topic_reply_count_hidden() { // Create a forum $f = $this->factory->forum->create(); // Create a topic $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Start with zero $count = bbp_get_topic_reply_count_hidden($t); $this->assertSame('0', $count); $r = $this->factory->reply->create_many(3, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_update_topic_reply_count_hidden($t); $count = bbp_get_topic_reply_count_hidden($t); $this->assertSame('0', $count); bbp_spam_reply($r[2]); bbp_update_topic_reply_count_hidden($t); $count = bbp_get_topic_reply_count_hidden($t); $this->assertSame('1', $count); bbp_unapprove_reply($r[0]); bbp_update_topic_reply_count_hidden($t); $count = bbp_get_topic_reply_count_hidden($t); $this->assertSame('2', $count); }
/** * @covers ::bbp_admin_repair_topic_hidden_reply_count */ public function test_bbp_admin_repair_topic_hidden_reply_count() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_get_topic_reply_count($t, true); $this->assertSame(1, $count); $r = $this->factory->reply->create_many(3, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_spam_reply($r[0]); bbp_unapprove_reply($r[2]); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(2, $count); // Delete the topic _bbp_reply_count_hidden meta key. $this->assertTrue(delete_post_meta_by_key('_bbp_reply_count_hidden')); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(0, $count); // Repair the topic hidden reply count meta. bbp_admin_repair_topic_hidden_reply_count(); bbp_clean_post_cache($t); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(2, $count); }
/** * @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)); }
/** * Bump the total hidden reply count of a topic * * @since 2.1.0 bbPress (r3825) * * @param int $topic_id Optional. Topic id. * @param int $difference Optional. Default 1 * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic_reply_count_hidden To get the topic's hidden reply count * @uses update_post_meta() To update the topic's reply count meta * @uses apply_filters() Calls 'bbp_bump_topic_reply_count_hidden' with the * reply count, topic id, and difference * @return int Topic hidden reply count */ function bbp_bump_topic_reply_count_hidden($topic_id = 0, $difference = 1) { // Bail if no bump if (empty($difference)) { return false; } // Get counts $topic_id = bbp_get_topic_id($topic_id); $reply_count = bbp_get_topic_reply_count_hidden($topic_id, true); $difference = (int) $difference; $new_count = (int) ($reply_count + $difference); // Update this topic id's hidden reply count update_post_meta($topic_id, '_bbp_reply_count_hidden', $new_count); return (int) apply_filters('bbp_bump_topic_reply_count_hidden', $new_count, $topic_id, $difference); }
/** * Output total hidden reply count of a topic (hidden includes trashed and * spammed replies) * * @since bbPress (r2740) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count */ function bbp_topic_reply_count_hidden($topic_id = 0) { echo bbp_get_topic_reply_count_hidden($topic_id); }