You are here

function AddTopicToForum::testMoveTopicWithCopyToForum in SimpleTest 6

File

tests/forum_module.test, line 308

Class

AddTopicToForum

Code

function testMoveTopicWithCopyToForum() {

  // Attempt to create a forum
  $web_user = $this
    ->drupalCreateUserRolePerm(array(
    'access administration pages',
    'administer forums',
    'create forum topics',
    'edit any forum topic',
  ));
  $this
    ->drupalLoginUser($web_user);
  $forum1 = $this
    ->createForum();
  $forum2 = $this
    ->createForum();

  // 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 has created the topic
  $this
    ->drupalPost('node/add/forum/' . $forum1['tid'], $edit, 'Save');
  $type = t('Forum topic');
  $this
    ->assertWantedRaw(t('@type %term has been created.', array(
    '%term' => $title,
    '@type' => $type,
  )), t('New forum topic has been created'));
  $this
    ->assertNoUnwantedRaw(t('The item %term is only a container for forums.', array(
    '%term' => $forum1['name'],
  )), t('No error message shown'));

  // Then find the new topic and edit it to move it
  $new_topic = node_load(array(
    'title' => $title,
  ), null, true);
  $vid = variable_get('forum_nav_vocabulary', '');
  $edit = array(
    'title' => $title,
    'taxonomy[' . $vid . ']' => $forum2['tid'],
    'body' => $description,
  );

  // Double check that the page says it has updated the topic
  // Also, double check that the new forum name is there and not the old
  $this
    ->drupalPost('node/' . $new_topic->nid . '/edit', $edit, 'Save');
  $type = t('Forum topic');
  $this
    ->assertWantedRaw(t('@type %term has been updated.', array(
    '%term' => $title,
    '@type' => $type,
  )), t('Topic has been moved'));
  $this
    ->assertWantedRaw($forum2['name'], t('New forum name is present'));
  $this
    ->assertNoUnwantedRaw($forum1['name'], t('Old forum name is not present'));

  // Delete the topic
  node_delete($new_topic->nid);

  // Delete the forums we created
  if (!empty($forum1)) {
    taxonomy_del_term($forum1['tid']);
  }
  if (!empty($forum2)) {
    taxonomy_del_term($forum2['tid']);
  }
}