You are here

function WorkbenchModerationModerateTabTestCase::testModerateTab in Workbench Moderation 7

Same name and namespace in other branches
  1. 7.3 tests/workbench_moderation.test \WorkbenchModerationModerateTabTestCase::testModerateTab()

File

tests/workbench_moderation.test, line 73
Tests for workbench_moderation.module.

Class

WorkbenchModerationModerateTabTestCase

Code

function testModerateTab() {
  $is_moderated = workbench_moderation_node_type_moderated($this->content_type);
  $this
    ->assertTrue($is_moderated, t('The content type is moderated.'));

  // Create a new node and make sure it is unpublished.
  $body_name = 'body[' . LANGUAGE_NONE . '][0]';
  $edit = array(
    'title' => $this
      ->randomName(),
    "{$body_name}[value]" => $this
      ->randomString(128),
    "{$body_name}[format]" => filter_default_format(),
  );
  $this
    ->drupalPost("node/add/{$this->content_type}", $edit, t('Save'));

  // Get the new node.
  $node = $this
    ->drupalGetNodeByTitle($edit['title']);
  $this
    ->assertFalse($node->status, t('New node is unpublished'));
  $this
    ->assertTrue(isset($node->workbench_moderation), t('Workbench moderation information is present on the node object'));
  $this
    ->assertFalse(isset($node->workbench_moderation['published']), t('Workbench moderation has no published revision'));

  // Make sure the "Moderate" tab is accessible.
  $this
    ->drupalGet("node/{$node->nid}/moderation");

  // Attempt to change the moderation state without a token in the link.
  $this
    ->drupalGet("node/{$node->nid}/moderation/{$node->vid}/change-state/needs_review");
  $this
    ->assertResponse(403);

  // Run the same state change with a valid token, which should succeed.
  $this
    ->drupalGet("node/{$node->nid}/moderation/{$node->vid}/change-state/needs_review", array(
    'query' => array(
      'token' => $this
        ->drupalGetToken("{$node->nid}:{$node->vid}:needs_review"),
    ),
  ));
  $this
    ->assertResponse(200);
  $node = node_load($node->nid, NULL, TRUE);
  $this
    ->assertEqual($node->workbench_moderation['current']->state, 'needs_review', 'Node state changed to Needs Review via callback.');

  // Publish the node via the moderation form.
  $moderate = array(
    'state' => workbench_moderation_state_published(),
  );
  $this
    ->drupalPost("node/{$node->nid}/moderation", $moderate, t('Apply'));
  $node = node_load($node->nid, NULL, TRUE);
  $this
    ->assertTrue(isset($node->workbench_moderation['published']), t('Workbench moderation has a published revision'));

  // Create a new draft.
  $new_title = $this
    ->randomName(10) . '_revision1';
  $edit = array(
    'title' => $new_title,
  );
  $this
    ->drupalPost("node/{$node->nid}/edit", $edit, t('Save'));

  // Load the published and draft revisions.
  $published = node_load($node->nid, NULL, TRUE);
  $draft = clone $published;
  $draft = workbench_moderation_node_current_load($draft);
  $this
    ->assertEqual($published->vid, $published->workbench_moderation['published']->vid, t('Published revision is loaded by default'));
  $this
    ->assertTrue($published->status, t('Published revision has status = 1'));
  $this
    ->assertNotEqual($published->vid, $draft->vid, t('Draft revision is different from the published revision'));
}