#652372 by matason, ksenzee, naxoc, jpmckinney, sun: Don't allow users to add forum topics when no forums exist.

merge-requests/26/head
Angie Byron 2010-04-14 15:51:21 +00:00
parent 28fb603ae3
commit 0ad37ad057
3 changed files with 19 additions and 1 deletions

View File

@ -58,6 +58,7 @@ function forum_enable() {
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'forum',
'required' => TRUE,
'widget' => array(
'type' => 'options_select',
),

View File

@ -299,7 +299,13 @@ function forum_node_validate($node, $form) {
if (!empty($node->taxonomy_forums[$langcode])) {
// Extract the node's proper topic ID.
$containers = variable_get('forum_containers', array());
foreach ($node->taxonomy_forums[$langcode] as $item) {
foreach ($node->taxonomy_forums[$langcode] as $delta => $item) {
// If no term was selected (e.g. when no terms exist yet), remove the
// item.
if (empty($item['tid'])) {
unset($node->taxonomy_forums[$langcode][$delta]);
continue;
}
$term = taxonomy_term_load($item['tid']);
$used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid',0 , 1, array(
':tid' => $term->tid,

View File

@ -90,6 +90,17 @@ class ForumTestCase extends DrupalWebTestCase {
$this->assertResponse(200);
}
/**
* Forum nodes should not be created without choosing forum from select list.
*/
function testAddOrphanTopic() {
$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.'));
}
/**
* Run admin tests on the admin user.
*