You are here

state_flow.test in State Machine 7.2

File

modules/state_flow/tests/state_flow.test
View source
<?php

/**
 * @file
 * state_flow.test
 */

/**
 * Unit tests for the StateFlow revision state machine.
 */
class StateFlowUnitTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'StateFlow basic tests',
      'description' => 'Perform basic unit tests on the StateFlow revision state machine.',
      'group' => 'State Machine',
    );
  }
  function setup() {
    parent::setup('state_machine', 'state_flow');
  }

  /**
   *
   */
  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.'));
  }

}

Classes

Namesort descending Description
StateFlowUnitTest Unit tests for the StateFlow revision state machine.