Creates a forum container or a forum.

Parameters

$type: The forum type (forum container or forum).

$parent: The forum parent. This defaults to 0, indicating a root forum. another forum).

Return value

The created taxonomy term data.

1 call to ForumTestCase::createForum()
ForumTestCase::doAdminTests in modules/forum/forum.test
Runs admin tests on the admin user.

File

modules/forum/forum.test, line 411
Tests for forum.module.

Class

ForumTestCase
Provides automated tests for the Forum module.

Code

function createForum($type, $parent = 0) {

  // Generate a random name/description.
  $name = $this
    ->randomName(10);
  $description = $this
    ->randomName(100);
  $edit = array(
    'name' => $name,
    'description' => $description,
    'parent[0]' => $parent,
    'weight' => '0',
  );

  // Create forum.
  $this
    ->drupalPost('admin/structure/forum/add/' . $type, $edit, t('Save'));
  $this
    ->assertResponse(200);
  $type = $type == 'container' ? 'forum container' : 'forum';
  $this
    ->assertRaw(t('Created new @type %term.', array(
    '%term' => $name,
    '@type' => t($type),
  )), format_string('@type was created', array(
    '@type' => ucfirst($type),
  )));

  // Verify forum.
  $term = db_query("SELECT * FROM {taxonomy_term_data} t WHERE t.vid = :vid AND t.name = :name AND t.description = :desc", array(
    ':vid' => variable_get('forum_nav_vocabulary', ''),
    ':name' => $name,
    ':desc' => $description,
  ))
    ->fetchAssoc();
  $this
    ->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');

  // Verify forum hierarchy.
  $tid = $term['tid'];
  $parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(
    ':tid' => $tid,
  ))
    ->fetchField();
  $this
    ->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
  return $term;
}