function ForumTest::createForum

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.

Return value

The created taxonomy term data.

2 calls to ForumTest::createForum()
ForumTest::doAdminTests in drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php
Runs admin tests on the admin user.
ForumTest::testForumWithNewPost in drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php
Tests a forum with a new post displays properly.

File

drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php, line 384
Tests for forum.module.

Class

ForumTest
Provides automated tests for the Forum module.

Namespace

Drupal\forum\Tests

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' => config('forum.settings')
      ->get('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;
}