You are here

function StateFlowUnitTest::testStateFlowStateMachine in State Machine 6

Same name and namespace in other branches
  1. 7 modules/state_flow/tests/state_flow.test \StateFlowUnitTest::testStateFlowStateMachine()
  2. 7.2 modules/state_flow/tests/state_flow.test \StateFlowUnitTest::testStateFlowStateMachine()

File

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

Class

StateFlowUnitTest
Unit tests for the StateFlow revision state machine.

Code

function testStateFlowStateMachine() {
  $node = $this
    ->drupalCreateNode();
  $machine = state_flow_load_state_machine($node);

  //make sure first (default) state is draft
  $this
    ->assertEqual($machine
    ->get_current_state(), 'draft', t('New nodes should default to the "draft" state.'));

  //publish node by firing event
  $machine
    ->fire_event('publish');
  $this
    ->assertEqual($machine
    ->get_current_state(), 'published', t('State should be "published" after firing the "publish" event.'));

  //choose edit link

  //make sure revision checkbox is checked
  $this
    ->drupalGet("node/{$node->nid}/edit");
  $this
    ->assertFieldChecked('edit-revision', t('Revision checkbox should be checked after editing a "published" node.'));

  //edit node (new title)

  //submit node, confirm creation

  //insure new title is updated, but not currently visible
  $old_title = $node->title;
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $this
    ->drupalPost("node/{$node->nid}/edit", $edit, t('Save'));
  $this
    ->assertTitle($old_title, t('Node title should stay the original despite the update.'));
  $this
    ->assertText(t('Program program @title has been updated.', array(
    '@title' => $edit['title'],
  )), t('The new node title should be saved.'));

  //check state of second revision

  //should be draft
  $this
    ->assertEqual($machine
    ->get_current_state(), 'draft', t('Updated published nodes should default to the "draft" state for their latest revision.'));

  //publish second revision

  //insure first revision is not active

  //check new title is now public
  $machine
    ->fire_event('publish');
  $this
    ->assertEqual($machine
    ->get_current_state(), 'published', t('State should be "published" after firing the "publish" event.'));
  $this
    ->assertTitle($edit['title'], t('Node title should be updated to second revision, now published.'));
}