private function ForumBlockTest::createForumTopics

Creates a forum topic.

Return value

The title of the newly generated topic.

2 calls to ForumBlockTest::createForumTopics()
ForumBlockTest::testActiveForumTopicsBlock in drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php
ForumBlockTest::testNewForumTopicsBlock in drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php
Tests disabling and re-enabling the Forum module.

File

drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php, line 172
Definition of Drupal\forum\Tests\ForumBlockTest.

Class

ForumBlockTest
Provides automated tests for the Forum blocks.

Namespace

Drupal\forum\Tests

Code

private function createForumTopics($count = 5) {
  $topics = array();
  $timestamp = time() - 24 * 60 * 60;
  for ($index = 0; $index < $count; $index++) {

    // Generate a random subject/body.
    $title = $this
      ->randomName(20);
    $body = $this
      ->randomName(200);
    $langcode = LANGUAGE_NOT_SPECIFIED;
    $edit = array(
      'title' => $title,
      "body[{$langcode}][0][value]" => $body,
      // Forum posts are ordered by timestamp, so force a unique timestamp by
      // adding the index.
      'date' => date('c', $timestamp + $index),
    );

    // Create the forum topic, preselecting the forum ID via a URL parameter.
    $this
      ->drupalPost('node/add/forum/1', $edit, t('Save'));
    $topics[] = $title;
  }
  return $topics;
}