You are here

public function StateFlowWebTestCase::testRevisionCheckbox in State Machine 7.3

Test the make new revision checkbox.

File

modules/state_flow/tests/state_flow.test, line 673
state_flow.test

Class

StateFlowWebTestCase
Unit tests for the StateFlow revision state machine.

Code

public function testRevisionCheckbox() {

  // Make a new node.
  $edit = array();
  $new_title = $this
    ->randomName(8);
  $edit['title'] = $new_title;
  $edit['event'] = 'keep in draft';
  $edit['revision'] = TRUE;
  $edit['event_comment'] = $this
    ->randomName(8);
  $this
    ->drupalPost("node/add/page", $edit, t('Save'));

  // Make a revision of the first node.
  $edit = array();
  $new_title = $this
    ->randomName(8);
  $edit['title'] = $new_title;
  $edit['event'] = 'publish';
  $edit['revision'] = TRUE;
  $edit['event_comment'] = $this
    ->randomName(8);
  $this
    ->drupalPost("node/1/edit", $edit, t('Save'));

  // Then change the state of the node without making a revision.
  $edit = array();
  $new_title = $this
    ->randomName(8);
  $edit['title'] = $new_title;
  $edit['event'] = 'unpublish';
  $edit['revision'] = FALSE;
  $edit['event_comment'] = $this
    ->randomName(8);
  $this
    ->drupalPost("node/1/edit", $edit, t('Save'));

  // Check to make sure that there are 3 database records for the 3 state
  // changes.
  $state_flow_history = db_select('state_flow_history', 'sfh')
    ->fields('sfh')
    ->condition('entity_id', 1)
    ->condition('entity_type', 'node')
    ->execute()
    ->fetchAll();
  $this
    ->assertEqual(count($state_flow_history), 3, t('There are 3 changes to the revision state.'));

  // Check to make sure there are 2 database records for the 2 revisions of
  // the node.
  $state_flow_history = db_select('state_flow_states', 'sfs')
    ->fields('sfs')
    ->condition('entity_id', 1)
    ->condition('entity_type', 'node')
    ->execute()
    ->fetchAll();
  $this
    ->assertEqual(count($state_flow_history), 2, t('There are 2 revisions.'));
}