protected function ForumBlockTest::createForumTopics

Creates a forum topic.

Return value

string The title of the newly generated topic.

2 calls to ForumBlockTest::createForumTopics()

File

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

Class

ForumBlockTest
Provides automated tests for the Forum blocks.

Namespace

Drupal\forum\Tests

Code

protected function createForumTopics($count = 5) {
  $topics = array();
  $date = new DrupalDateTime();
  $date
    ->modify('-24 hours');
  for ($index = 0; $index < $count; $index++) {

    // Generate a random subject/body.
    $title = $this
      ->randomName(20);
    $body = $this
      ->randomName(200);

    // Forum posts are ordered by timestamp, so force a unique timestamp by
    // changing the date.
    $date
      ->modify('+1 minute');
    $langcode = Language::LANGCODE_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]' => $date
        ->format('Y-m-d'),
      'date[time]' => $date
        ->format('H:i:s'),
    );

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