/** * @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)); }
/** * Return the forum type dropdown * * @since bbPress (r3563) * * @param int $forum_id The forum id to use * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses bbp_get_forum_type() To get the forum type * @uses apply_filters() * @return string HTML select list for selecting forum type */ function bbp_get_form_forum_type_dropdown($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $forum_attr = apply_filters('bbp_forum_types', array('forum' => __('Forum', 'bbpress'), 'category' => __('Category', 'bbpress'))); $type_output = '<select name="bbp_forum_type" id="bbp_forum_type_select">' . "\n"; foreach ($forum_attr as $value => $label) { $type_output .= "\t" . '<option value="' . $value . '"' . selected(bbp_get_forum_type($forum_id), $value, false) . '>' . esc_html($label) . '</option>' . "\n"; } $type_output .= '</select>'; return apply_filters('bbp_get_form_forum_type_dropdown', $type_output, $forum_id, $forum_attr); }
/** * Return the forum type dropdown * * @since bbPress (r3563) * * @param int $forum_id The forum id to use * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses bbp_get_forum_type() To get the forum type * @uses apply_filters() * @return string HTML select list for selecting forum type */ function bbp_get_form_forum_type_dropdown($args = '') { // Backpat for handling passing of a forum ID as integer if (is_int($args)) { $forum_id = (int) $args; $args = array(); } else { $forum_id = 0; } // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_forum_type', 'tab' => bbp_get_tab_index(), 'forum_id' => $forum_id, 'selected' => false), 'forum_type_select'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = $_POST[$r['select_id']]; // No Post value was passed } else { // Edit topic if (bbp_is_forum_edit()) { $r['forum_id'] = bbp_get_forum_id($r['forum_id']); $r['selected'] = bbp_get_forum_type($r['forum_id']); // New topic } else { $r['selected'] = bbp_get_public_status_id(); } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select"<?php echo $tab; ?> > <?php foreach (bbp_get_forum_types() as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_forum_type_dropdown', ob_get_clean(), $r); }
/** * @covers ::bbp_forum_type * @covers ::bbp_get_forum_type */ public function test_bbp_get_forum_type() { $f = $this->factory->forum->create(); $forum = bbp_get_forum_type($f); $this->assertSame('forum', $forum); }