You are here

function _workflow_test_entity1 in Workflow 7.2

File

./workflow.test.inc, line 52
Contains test functions.

Code

function _workflow_test_entity1() {
  $workflow = NULL;

  // Create a workflow.
  dpm('--- Create Workflow ---');
  dpm($workflow, '--- test workflow_create() pre');
  $workflow = workflow_create('test' . REQUEST_TIME);
  dpm($workflow, '--- test workflow_create() pre_save');
  $workflow
    ->save();
  dpm($workflow, '--- test workflow_create() post_save');

  // Create States for the workflow.
  dpm('--- Create States ---');
  dpm($workflow
    ->getStates(TRUE), '--- test getStates() pre');
  dpm($workflow, '--- test getStates() pre');
  $s1 = $workflow
    ->createState('first');
  dpm($workflow
    ->getStates(TRUE), '--- test getStates() post s1');
  dpm($workflow, '--- test getStates() post s1');
  $s2 = $workflow
    ->createState('second');
  $s3 = $workflow
    ->createState('third');

  //  $s1->save();
  //  $s2->save();
  //  $s3->save();
  dpm($workflow
    ->getStates(TRUE), '--- test getStates() post');
  dpm($workflow, '--- test getStates() post');
  dpm($s3
    ->getWorkflow(), '--- test getStates() post');

  // Create Transitions for the workflow.
  dpm('--- Create Transitions ---');
  dpm('--- Create Transition s1->s2 ---');
  dpm($workflow
    ->getTransitions(), '--- test getTransitions() pre');
  $roles = array(
    -1,
    5,
  );
  $t1 = $workflow
    ->createTransition($s1->sid, $s2->sid);
  $t1->label = 'transitions t1';
  $t1->roles = $roles;

  // The transition was initially saved in createState,
  // but without roles and name.
  $t1
    ->save();
  dpm($t1, '-- test show new Transition');
  dpm($workflow
    ->getTransitions(), '-- test getTransitions() post 1');
  dpm('--- Create Transition s1->s2 ---');
  dpm($workflow
    ->getTransitions(), '--- test getTransitions() pre');
  $roles = array(
    -1,
    6,
  );
  $t2 = $workflow
    ->createTransition($s2->sid, $s3->sid);
  $t2->label = 'transitions t2';
  $t2->roles = $roles;

  // The transition was initially saved in createState,
  // but without roles and name.
  $t2
    ->save();
  dpm($t2, '-- test show new Transition');
  dpm($workflow
    ->getTransitions(), '-- test getTransitions() post 2');
  dpm('--- Show resulting Workflow ---');
  dpm($workflow);
  dpm('todo: Test if workflow, states and transitions are properly shown in Admin UI.');
  dpm('--- Show resulting Workflow after workflow_load---');

  // Refresh the workflow, and show again.
  $workflow2 = workflow_load($workflow->wid);
  dpm($workflow2);

  //  dpm($t->uri());
  //  dpm($t->label());
  // Remove the workflow and its components.
  dpm('--- Delete resulting Workflow ---');
  $workflow
    ->delete();
  dpm($workflow);
  dpm('todo: Test if workflow, states and transitions are properly deleted.');
}