WorkflowUnitTest.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Contains workflow\lib\entity\WorkflowUnitTest.
  5. */
  6. /**
  7. * Tests for the Workflow classes.
  8. */
  9. class WorkflowExampleTestCase extends DrupalWebTestCase {
  10. protected $workflow;
  11. public static function getInfo() {
  12. return array(
  13. 'name' => 'Workflow',
  14. 'description' => 'Ensure that the Workflow API works as expected.',
  15. 'group' => 'Workflow',
  16. );
  17. }
  18. public function setUp() {
  19. parent::setUp('workflow'); // Enable any modules required for the test.
  20. }
  21. /**
  22. * Creates a simpletest_example node using the node form.
  23. */
  24. public function testWorkflow() {
  25. // $workflows = workflow_load_multiple();
  26. // dpm($workflows, "These are the current Workflows in the system.");
  27. $wid = 1;
  28. $workflow = workflow_load_single($wid);
  29. $this->assertEqual($workflow->wid, $wid, t('The wid of the Workflow should be the same as we decided.'));
  30. $workflow = new Workflow($wid);
  31. $this->assertEqual($workflow->wid, $wid, t('The wid of the Workflow should be the same as we decided.'));
  32. // $creation_state = $workflow->getCreationState();
  33. // $this->assertEqual($creation_state, 1, t('The creation_state of wid 1 has value 1.'));
  34. }
  35. /*
  36. function testWorkflowState($sid = 2, $wid = 1) {
  37. $this->testId = '2';
  38. $wf_state = $workflow->createState('State 2');
  39. dpm($wf_state, 'This is state ' . $sid . ' of workflow ' . $wid);
  40. $workflow = $wf_state->getWorkflow();
  41. dpm($workflow, 'This is the workflow of sid ' . $sid);
  42. return;
  43. $this->machine->fire_event('goto2');
  44. $this->assertEqual($this->machine->get_current_state(), 'step2', t('Current state should change when a valid event is fired.'));
  45. $this->machine->fire_event('goto2');
  46. $this->assertEqual($this->machine->get_current_state(), 'step2', t('Event should not execute if current state is not valid for the specified event.'));
  47. $this->machine->fire_event('reset');
  48. $this->assertEqual($this->machine->get_current_state(), 'step1', t('Event should allow transitions from multiple origins.'));
  49. $current = $this->machine->get_current_state();
  50. $this->machine->fire_event('dont_do_it');
  51. $this->assertEqual($current, $this->machine->get_current_state(), t('State should not change when guard function returns FALSE.'));
  52. $this->machine->fire_event('reset');
  53. $this->machine->reset_logs();
  54. $this->machine->fire_event('goto2_with_logs');
  55. $this->assertEqual($this->machine->logs[0], 'guard', t('The guard condition should be the first callback executed.'));
  56. $this->assertEqual($this->machine->logs[1], 'before_transition', t('The before_transition callback should be the second callback executed.'));
  57. $this->assertEqual($this->machine->logs[2], 'on_exit', t('The on_exit callback should be the third callback executed.'));
  58. $this->assertEqual($this->machine->logs[3], 'on_enter', t('The on_enter callback should be the fourth callback executed.'));
  59. $this->assertEqual($this->machine->logs[4], 'after_transition', t('The after_transition callback should be the fifth callback executed.'));
  60. $this->machine->fire_event('reset');
  61. $events = $this->machine->get_available_events();
  62. $this->assertTrue(in_array('goto2', $events), t('The machine should return a list of available events.'));
  63. $this->assertTrue(in_array('goto3', $events), t('The machine should return a list of available events.'));
  64. }
  65. */
  66. }