You are here

function AddTopicToForum::testAddTopicToContainer in SimpleTest 6

File

tests/forum_module.test, line 214

Class

AddTopicToForum

Code

function testAddTopicToContainer() {

  // Attempt to create a forum container
  $web_user = $this
    ->drupalCreateUserRolePerm(array(
    'access administration pages',
    'administer forums',
    'create forum topics',
  ));
  $this
    ->drupalLoginUser($web_user);

  // Create the container
  $container = $this
    ->createForumContainer();

  // Now, we try to create the topic in the forum
  // Generate a random subject/body
  $title = $this
    ->randomName(20);
  $description = $this
    ->randomName(200);
  $edit = array(
    'title' => $title,
    'body' => $description,
  );

  // Double check that the page says it hasn't created the topic
  $this
    ->drupalPost('node/add/forum/' . $container['tid'], $edit, 'Save');
  $type = t('Forum topic');
  $this
    ->assertNoUnwantedRaw(t('@type %term has been created.', array(
    '%term' => $title,
    '@type' => $type,
  )), t('No "new forum has been created" message'));
  $this
    ->assertWantedRaw(t('The item %term is only a container for forums.', array(
    '%term' => $container['name'],
  )), t('Error message shown'));

  // Then make sure the node does not exist
  $new_topic = node_load(array(
    'title' => $title,
  ), null, true);
  $this
    ->assertTrue(empty($new_topic), t('There is no new topic'));

  // Delete the forum container we created
  if (!empty($container)) {
    taxonomy_del_term($container['tid']);
  }
}