ForumTestCase::createForum

7 forum.test ForumTestCase::createForum($type, $parent = 0)
8 forum.test ForumTestCase::createForum($type, $parent = 0)

Create a forum container or a forum.

Parameters

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

$parent: Forum parent (default = 0 = a root forum; >0 = a forum container or another forum).

Return value

taxonomy_term_data created.

File

modules/forum/forum.test, line 321
Tests for 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))), t(ucfirst($type) . ' was created'));

  // 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;
}
Login or register to post comments