From 9f70b717e56c8bc816dd5119e2830d668037d5cc Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 26 Apr 2010 14:32:27 +0000 Subject: [PATCH] - Patch #613272 by Kevin Hankens, Dave Reid, yoroy, rgristroph, pcarman: forums not usable out-of-the-box: disabled comments, no forums. --- modules/forum/forum.install | 13 +++++++++++++ modules/forum/forum.module | 4 ++++ modules/forum/forum.test | 18 +++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/forum/forum.install b/modules/forum/forum.install index 7e6de833a8b..65841a4a165 100644 --- a/modules/forum/forum.install +++ b/modules/forum/forum.install @@ -20,6 +20,9 @@ function forum_install() { variable_set('node_options_forum', array('status')); } +/** + * Implements hook_enable(). + */ function forum_enable() { // Create the forum vocabulary if it does not exist. $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0)); @@ -66,6 +69,16 @@ function forum_enable() { field_create_instance($instance); variable_set('forum_nav_vocabulary', $vocabulary->vid); + + // Create a default forum so forum posts can be created. + $edit = array( + 'name' => t('General discussion'), + 'description' => '', + 'parent' => array(0), + 'vid' => $vocabulary->vid, + ); + $term = (object) $edit; + taxonomy_term_save($term); } } diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 10d55b1a353..413903434b6 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -307,6 +307,10 @@ function forum_node_validate($node, $form) { continue; } $term = taxonomy_term_load($item['tid']); + if (!$term) { + form_set_error('taxonomy_forums', t('Select a forum.')); + continue; + } $used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid',0 , 1, array( ':tid' => $term->tid, ':vid' => $term->vid, diff --git a/modules/forum/forum.test b/modules/forum/forum.test index c1076fe9434..2cd4909d813 100644 --- a/modules/forum/forum.test +++ b/modules/forum/forum.test @@ -35,6 +35,11 @@ class ForumTestCase extends DrupalWebTestCase { * Login users, create forum nodes, and test forum functionality through the admin and user interfaces. */ function testForum() { + //Check that the basic forum install creates a default forum topic + $this->drupalGet("/forum"); + // Look for the "General discussion" default forum + $this->assertText(t("General discussion"), "Found the default forum at the /forum listing"); + // Do the admin tests. $this->doAdminTests($this->admin_user); // Generate topics to populate the active forum block. @@ -94,11 +99,22 @@ class ForumTestCase extends DrupalWebTestCase { * Forum nodes should not be created without choosing forum from select list. */ function testAddOrphanTopic() { + // Must remove forum topics to test creating orphan topics. + $vid = variable_get('forum_nav_vocabulary'); + $tree = taxonomy_get_tree($vid); + foreach($tree as $term) { + taxonomy_term_delete($term->tid); + } + + // Create an orphan forum item. $this->drupalLogin($this->admin_user); $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NONE .'][0][value]' => $this->randomName(120)), t('Save')); $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField(); - $this->assertEqual(0, $nid_count, t('A forum node was not created.')); + $this->assertEqual(0, $nid_count, t('A forum node was not created when missing a forum vocabulary.')); + + // Reset the defaults for future tests. + module_enable(array('forum')); } /**