public function test_notify_topic() { $bbpnns = bbPress_Notify_NoSpam::bootstrap(); // Spam, returns -1 bbp_spam_topic($this->topic_id); $status = $bbpnns->notify_new_topic($this->topic_id, $this->forum_id); $this->assertEquals(-1, $status, 'Spam topic returns -1'); // Non-spam, empty recipients returns -2 bbp_unspam_topic($this->topic_id); delete_option('bbpress_notify_newtopic_recipients'); $status = $bbpnns->notify_new_topic($this->topic_id, $this->forum_id); $this->assertEquals(-2, $status, 'Empty Recipients -2'); update_option('bbpress_notify_newtopic_email_body', '[topic-content]'); // Non-spam, non-empty recipents $recipients = array('administrator', 'subscriber'); update_option('bbpress_notify_newtopic_recipients', $recipients); $arry = $bbpnns->notify_new_topic($this->topic_id, $this->forum_id); $this->assertTrue(is_array($arry), 'Good notify returns array in test mode'); list($recipients, $body) = $arry; $reg_body = str_replace('[topic-url]', '[^ ,]+', $this->topic_body_clean); $reg_body = str_replace('[topic-author]', 'admin', $reg_body); $reg_body = str_replace('[topic-forum]', 'test-forum', $reg_body); $this->assertRegexp("/{$reg_body}/", $body, 'Topic body munged correctly'); // Force skip add_filter('bbpnns_skip_topic_notification', '__return_true'); $status = $bbpnns->notify_new_topic($this->topic_id, $this->forum_id); $this->assertEquals(-3, $status, 'Force skip -3'); }
/** * Handles the front end opening/closing, spamming/unspamming, * sticking/unsticking and trashing/untrashing/deleting of topics * * @since bbPress (r2727) * * @param string $action The requested action to compare this function to * @uses bbp_get_topic() To get the topic * @uses current_user_can() To check if the user is capable of editing or * deleting the topic * @uses bbp_get_topic_post_type() To get the topic post type * @uses check_ajax_referer() To verify the nonce and check the referer * @uses bbp_is_topic_open() To check if the topic is open * @uses bbp_close_topic() To close the topic * @uses bbp_open_topic() To open the topic * @uses bbp_is_topic_sticky() To check if the topic is a sticky * @uses bbp_unstick_topic() To unstick the topic * @uses bbp_stick_topic() To stick the topic * @uses bbp_is_topic_spam() To check if the topic is marked as spam * @uses bbp_spam_topic() To make the topic as spam * @uses bbp_unspam_topic() To unmark the topic as spam * @uses wp_trash_post() To trash the topic * @uses wp_untrash_post() To untrash the topic * @uses wp_delete_post() To delete the topic * @uses do_action() Calls 'bbp_toggle_topic_handler' with success, post data * and action * @uses bbp_get_forum_permalink() To get the forum link * @uses bbp_get_topic_permalink() To get the topic link * @uses wp_safe_redirect() To redirect to the topic * @uses bbPress::errors:add() To log the error messages */ function bbp_toggle_topic_handler($action = '') { // Bail if required GET actions aren't passed if (empty($_GET['topic_id'])) { return; } // Setup possible get actions $possible_actions = array('bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_trash'); // Bail if actions aren't meant for this function if (!in_array($action, $possible_actions)) { return; } $failure = ''; // Empty failure string $view_all = false; // Assume not viewing all $topic_id = (int) $_GET['topic_id']; // What's the topic id? $success = false; // Flag $post_data = array('ID' => $topic_id); // Prelim array $redirect = ''; // Empty redirect URL // Make sure topic exists $topic = bbp_get_topic($topic_id); if (empty($topic)) { return; } // What is the user doing here? if (!current_user_can('edit_topic', $topic->ID) || 'bbp_toggle_topic_trash' === $action && !current_user_can('delete_topic', $topic->ID)) { bbp_add_error('bbp_toggle_topic_permission', __('<strong>ERROR:</strong> You do not have the permission to do that.', 'bbpress')); return; } // What action are we trying to perform? switch ($action) { // Toggle open/close case 'bbp_toggle_topic_close': check_ajax_referer('close-topic_' . $topic_id); $is_open = bbp_is_topic_open($topic_id); $success = true === $is_open ? bbp_close_topic($topic_id) : bbp_open_topic($topic_id); $failure = true === $is_open ? __('<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress'); break; // Toggle sticky/super-sticky/unstick // Toggle sticky/super-sticky/unstick case 'bbp_toggle_topic_stick': check_ajax_referer('stick-topic_' . $topic_id); $is_sticky = bbp_is_topic_sticky($topic_id); $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false; $success = true === $is_sticky ? bbp_unstick_topic($topic_id) : bbp_stick_topic($topic_id, $is_super); $failure = true === $is_sticky ? __('<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress'); break; // Toggle spam // Toggle spam case 'bbp_toggle_topic_spam': check_ajax_referer('spam-topic_' . $topic_id); $is_spam = bbp_is_topic_spam($topic_id); $success = true === $is_spam ? bbp_unspam_topic($topic_id) : bbp_spam_topic($topic_id); $failure = true === $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress'); $view_all = !$is_spam; break; // Toggle trash // Toggle trash case 'bbp_toggle_topic_trash': $sub_action = !empty($_GET['sub_action']) && in_array($_GET['sub_action'], array('trash', 'untrash', 'delete')) ? $_GET['sub_action'] : false; if (empty($sub_action)) { break; } switch ($sub_action) { case 'trash': check_ajax_referer('trash-' . bbp_get_topic_post_type() . '_' . $topic_id); $view_all = true; $success = wp_trash_post($topic_id); $failure = __('<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress'); break; case 'untrash': check_ajax_referer('untrash-' . bbp_get_topic_post_type() . '_' . $topic_id); $success = wp_untrash_post($topic_id); $failure = __('<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress'); break; case 'delete': check_ajax_referer('delete-' . bbp_get_topic_post_type() . '_' . $topic_id); $success = wp_delete_post($topic_id); $failure = __('<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress'); break; } break; } // Do additional topic toggle actions do_action('bbp_toggle_topic_handler', $success, $post_data, $action); // No errors if (false !== $success && !is_wp_error($success)) { // Redirect back to the topic's forum if (isset($sub_action) && 'delete' === $sub_action) { $redirect = bbp_get_forum_permalink($success->post_parent); // Redirect back to the topic } else { // Get the redirect detination $permalink = bbp_get_topic_permalink($topic_id); $redirect = bbp_add_view_all($permalink, $view_all); } wp_safe_redirect($redirect); // For good measure exit; // Handle errors } else { bbp_add_error('bbp_toggle_topic', $failure); } }
/** * Mark a users topics and replies as spam when the user is marked as spam * * @since bbPress (r3405) * * @global WPDB $wpdb * @param int $user_id Optional. User ID to unspam. Defaults to displayed user. * * @uses bbp_is_single_user() * @uses bbp_is_user_home() * @uses bbp_get_displayed_user_id() * @uses bbp_is_user_keymaster() * @uses get_blogs_of_user() * @uses bbp_get_topic_post_type() * @uses bbp_get_reply_post_type() * @uses switch_to_blog() * @uses get_post_type() * @uses bbp_unspam_topic() * @uses bbp_unspam_reply() * @uses restore_current_blog() * * @return If no user ID passed */ function bbp_make_ham_user($user_id = 0) { // Use displayed user if it's not yourself if (empty($user_id) && bbp_is_single_user() && !bbp_is_user_home()) { $user_id = bbp_get_displayed_user_id(); } // Bail if no user ID if (empty($user_id)) { return false; } // Bail if user ID is keymaster if (bbp_is_user_keymaster($user_id)) { return false; } // Arm the torpedos global $wpdb; // Get the blog IDs of the user to mark as spam $blogs = get_blogs_of_user($user_id, true); // If user has no blogs, they are a guest on this site if (empty($blogs)) { $blogs[$wpdb->blogid] = array(); } // Make array of post types to mark as spam $post_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type()); $post_types = "'" . implode("', '", $post_types) . "'"; // Loop through blogs and remove their posts foreach ((array) array_keys($blogs) as $blog_id) { // Switch to the blog ID switch_to_blog($blog_id); // Get topics and replies $posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id())); // Loop through posts and spam them if (!empty($posts)) { foreach ($posts as $post_id) { // The routines for topics ang replies are different, so use the // correct one based on the post type switch (get_post_type($post_id)) { case bbp_get_topic_post_type(): bbp_unspam_topic($post_id); break; case bbp_get_reply_post_type(): bbp_unspam_reply($post_id); break; } } } // Switch back to current blog restore_current_blog(); } // Success return true; }
/** * Toggle topic * * Handles the admin-side opening/closing, sticking/unsticking and * spamming/unspamming of topics * * @since 2.0.0 bbPress (r2727) * * @uses bbp_get_topic() To get the topic * @uses current_user_can() To check if the user is capable of editing * the topic * @uses wp_die() To die if the user isn't capable or the post wasn't * found * @uses check_admin_referer() To verify the nonce and check referer * @uses bbp_is_topic_open() To check if the topic is open * @uses bbp_close_topic() To close the topic * @uses bbp_open_topic() To open the topic * @uses bbp_is_topic_sticky() To check if the topic is a sticky or * super sticky * @uses bbp_unstick_topic() To unstick the topic * @uses bbp_stick_topic() To stick the topic * @uses bbp_is_topic_spam() To check if the topic is marked as spam * @uses bbp_unspam_topic() To unmark the topic as spam * @uses bbp_spam_topic() To mark the topic as spam * @uses do_action() Calls 'bbp_toggle_topic_admin' with success, post * data, action and message * @uses add_query_arg() To add custom args to the url * @uses bbp_redirect() Redirect the page to custom url */ public function toggle_topic() { if ($this->bail()) { return; } // Only proceed if GET is a topic toggle action if (bbp_is_get_request() && !empty($_GET['action']) && in_array($_GET['action'], array('bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_approve')) && !empty($_GET['topic_id'])) { $action = $_GET['action']; // What action is taking place? $topic_id = (int) $_GET['topic_id']; // What's the topic id? $success = false; // Flag $post_data = array('ID' => $topic_id); // Prelim array $topic = bbp_get_topic($topic_id); // Verify the topic id // Bail if topic is missing if (empty($topic)) { wp_die(__('The topic was not found!', 'bbpress')); } // What is the user doing here? if (!current_user_can('moderate', $topic->ID)) { wp_die(__('You do not have the permission to do that!', 'bbpress')); } switch ($action) { case 'bbp_toggle_topic_approve': check_admin_referer('approve-topic_' . $topic_id); $is_approve = bbp_is_topic_pending($topic_id); $message = true === $is_approve ? 'approved' : 'unapproved'; $success = true === $is_approve ? bbp_approve_topic($topic_id) : bbp_unapprove_topic($topic_id); break; case 'bbp_toggle_topic_close': check_admin_referer('close-topic_' . $topic_id); $is_open = bbp_is_topic_open($topic_id); $message = true === $is_open ? 'closed' : 'opened'; $success = true === $is_open ? bbp_close_topic($topic_id) : bbp_open_topic($topic_id); break; case 'bbp_toggle_topic_stick': check_admin_referer('stick-topic_' . $topic_id); $is_sticky = bbp_is_topic_sticky($topic_id); $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false; $message = true === $is_sticky ? 'unstuck' : 'stuck'; $message = true === $is_super ? 'super_sticky' : $message; $success = true === $is_sticky ? bbp_unstick_topic($topic_id) : bbp_stick_topic($topic_id, $is_super); break; case 'bbp_toggle_topic_spam': check_admin_referer('spam-topic_' . $topic_id); $is_spam = bbp_is_topic_spam($topic_id); $message = true === $is_spam ? 'unspammed' : 'spammed'; $success = true === $is_spam ? bbp_unspam_topic($topic_id) : bbp_spam_topic($topic_id); break; } $message = array('bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID); if (false === $success || is_wp_error($success)) { $message['failed'] = '1'; } // Do additional topic toggle actions (admin side) do_action('bbp_toggle_topic_admin', $success, $post_data, $action, $message); // Redirect back to the topic $redirect = add_query_arg($message, remove_query_arg(array('action', 'topic_id'))); bbp_redirect($redirect); } }
/** * @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); }
/** * Do the actual topic toggling * * This function is used by `bbp_toggle_topic_handler()` to do the actual heavy * lifting when it comes to toggling topic. It only really makes sense to call * within that context, so if you need to call this function directly, make sure * you're also doing what the handler does too. * * @since 2.6.0 bbPress (r6133) * @access private * * @param array $args */ function bbp_toggle_topic($args = array()) { // Parse the arguments $r = bbp_parse_args($args, array('id' => 0, 'action' => '', 'sub_action' => '', 'data' => array())); // Build the nonce suffix $nonce_suffix = bbp_get_topic_post_type() . '_' . (int) $r['id']; // Default return values $retval = array('status' => 0, 'message' => '', 'redirect_to' => bbp_get_topic_permalink($r['id'], bbp_get_redirect_to()), 'view_all' => false); // What action are we trying to perform? switch ($r['action']) { // Toggle approve/unapprove case 'bbp_toggle_topic_approve': check_ajax_referer("approve-{$nonce_suffix}"); $is_pending = bbp_is_topic_pending($r['id']); $retval['view_all'] = !$is_pending; // Toggle $retval['status'] = true === $is_pending ? bbp_approve_topic($r['id']) : bbp_unapprove_topic($r['id']); // Feedback $retval['message'] = true === $is_pending ? __('<strong>ERROR</strong>: There was a problem approving the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem unapproving the topic.', 'bbpress'); break; // Toggle open/close // Toggle open/close case 'bbp_toggle_topic_close': check_ajax_referer("close-{$nonce_suffix}"); $is_open = bbp_is_topic_open($r['id']); // Toggle $retval['status'] = true === $is_open ? bbp_close_topic($r['id']) : bbp_open_topic($r['id']); // Feedback $retval['message'] = true === $is_open ? __('<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress'); break; // Toggle sticky/super-sticky/unstick // Toggle sticky/super-sticky/unstick case 'bbp_toggle_topic_stick': check_ajax_referer("stick-{$nonce_suffix}"); $is_sticky = bbp_is_topic_sticky($r['id']); $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false; // Toggle $retval['status'] = true === $is_sticky ? bbp_unstick_topic($r['id']) : bbp_stick_topic($r['id'], $is_super); // Feedback $retval['message'] = true === $is_sticky ? __('<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress'); break; // Toggle spam // Toggle spam case 'bbp_toggle_topic_spam': check_ajax_referer("spam-{$nonce_suffix}"); $is_spam = bbp_is_topic_spam($r['id']); $retval['view_all'] = !$is_spam; // Toggle $retval['status'] = true === $is_spam ? bbp_unspam_topic($r['id']) : bbp_spam_topic($r['id']); // Feedback $retval['message'] = true === $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress'); break; // Toggle trash // Toggle trash case 'bbp_toggle_topic_trash': switch ($r['sub_action']) { case 'trash': check_ajax_referer("trash-{$nonce_suffix}"); $retval['view_all'] = true; $retval['status'] = wp_trash_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress'); break; case 'untrash': check_ajax_referer("untrash-{$nonce_suffix}"); $retval['status'] = wp_untrash_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress'); break; case 'delete': check_ajax_referer("delete-{$nonce_suffix}"); $retval['status'] = wp_delete_post($r['id']); $retval['message'] = __('<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress'); break; } break; } // Maybe redirect back to the topic's forum if (isset($r['sub_action']) && 'delete' === $r['sub_action']) { $retval['redirect_to'] = bbp_get_forum_permalink($retval['status']->post_parent); } // Add view all if needed if (!empty($retval['view_all'])) { $retval['redirect_to'] = bbp_add_view_all($retval['redirect_to'], true); } // Filter & return return apply_filters('bbp_toggle_topic', $retval, $r, $args); }
/** * @covers ::bbp_get_forum_freshness_link */ public function test_bbp_get_forum_freshness_link_with_unpublished_replies() { if (is_multisite()) { $this->markTestSkipped('Skipping URL tests in multiste for now.'); } $now = time(); $post_date_t1 = date('Y-m-d H:i:s', $now - 60 * 60 * 18); // 18 hours ago $post_date_t2 = date('Y-m-d H:i:s', $now - 60 * 60 * 16); // 16 hours ago $post_date_t3 = date('Y-m-d H:i:s', $now - 60 * 60 * 14); // 14 hours ago $post_date_t4 = date('Y-m-d H:i:s', $now - 60 * 60 * 12); // 12 hours ago $post_date_t5 = date('Y-m-d H:i:s', $now - 60 * 60 * 10); // 1o hours ago $f = $this->factory->forum->create(); $link = bbp_get_forum_freshness_link($f); $this->assertSame('No Topics', $link); $t1 = $this->factory->topic->create(array('post_title' => 'Topic 1', 'post_parent' => $f, 'post_date' => $post_date_t1, 'topic_meta' => array('forum_id' => $f))); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link); $t2 = $this->factory->topic->create(array('post_title' => 'Topic 2', 'post_parent' => $f, 'post_date' => $post_date_t2, 'topic_meta' => array('forum_id' => $f))); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-2" title="Topic 2">16 hours ago</a>', $link); bbp_spam_topic($t2); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link); $t3 = $this->factory->topic->create(array('post_title' => 'Topic 3', 'post_parent' => $f, 'post_date' => $post_date_t3, 'topic_meta' => array('forum_id' => $f))); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-3" title="Topic 3">14 hours ago</a>', $link); // Todo: Use bbp_trash_topic() and not wp_trash_post() wp_trash_post($t3); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link); $t4 = $this->factory->topic->create(array('post_title' => 'Topic 4', 'post_parent' => $f, 'post_date' => $post_date_t4, 'topic_meta' => array('forum_id' => $f))); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-4" title="Topic 4">12 hours ago</a>', $link); bbp_unapprove_topic($t4); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link); bbp_unspam_topic($t2); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-2" title="Topic 2">16 hours ago</a>', $link); // Todo: Use bbp_untrash_topic() and not wp_untrash_post() wp_untrash_post($t3); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-3" title="Topic 3">14 hours ago</a>', $link); bbp_approve_topic($t4); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-4" title="Topic 4">12 hours ago</a>', $link); $t5 = $this->factory->topic->create(array('post_title' => 'Topic 5', 'post_parent' => $f, 'post_date' => $post_date_t5, 'topic_meta' => array('forum_id' => $f))); $link = bbp_get_forum_freshness_link($f); $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-5" title="Topic 5">10 hours ago</a>', $link); }
/** * Generic function to test the forum counts on a spammed/unspammed topic */ public function test_bbp_forum_spammed_unspammed_topic_counts() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r1 = $this->factory->reply->create_many(2, array('post_parent' => $t[1], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t[1]))); $r2 = $this->factory->reply->create_many(2, array('post_parent' => $t[2], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t[2]))); $count = bbp_update_forum_topic_count($f); $this->assertSame(3, $count); $count = bbp_update_forum_topic_count_hidden($f); $this->assertSame(0, $count); $count = bbp_update_forum_reply_count($f); $this->assertSame(4, $count); bbp_spam_topic($t[2]); $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(2, $count); $count = bbp_get_forum_topic_count_hidden($f, true, true); $this->assertSame(1, $count); $count = bbp_get_forum_reply_count($f, true, true); $this->assertSame(2, $count); bbp_unspam_topic($t[2]); $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(3, $count); $count = bbp_get_forum_topic_count_hidden($f, true, true); $this->assertSame(0, $count); $count = bbp_get_forum_reply_count($f, true, true); $this->assertSame(4, $count); }