workflow.test.inc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /**
  3. * @file
  4. * Contains test functions.
  5. */
  6. /**
  7. * Test functions.
  8. *
  9. * To test caches, load same object twice in a page (see d.o. issue #1572466).
  10. */
  11. function _workflow_test_entity_workflow_crud() {
  12. $ws = workflow_load_multiple();
  13. $count1 = count($ws);
  14. $workflow = workflow_create('test' . REQUEST_TIME);
  15. $workflow->save();
  16. // Test cache: $w3 must be OK, too.
  17. $w2 = workflow_load($workflow->wid);
  18. $w3 = workflow_load($workflow->wid);
  19. if ($w2 != $w3) {
  20. // error.
  21. }
  22. // Test Cache: number of workflows must be OK.
  23. $ws = workflow_load_multiple();
  24. $count2 = count($ws);
  25. $workflow->delete();
  26. $ws = workflow_load_multiple();
  27. $count3 = count($ws);
  28. if ($count1 === $count3 && ($count2 - $count1) == 1) {
  29. drupal_set_message(t('workflow->create/save/delete OK'));
  30. }
  31. else {
  32. drupal_set_message(t('workflow->create/save/delete: error'));
  33. }
  34. $workflow = workflow_create('test' . REQUEST_TIME);
  35. $s1 = $workflow->createState('first');
  36. $s2 = $workflow->createState('second');
  37. $s3 = $workflow->createState('third');
  38. $s1->save();
  39. $s2->save();
  40. $s2->save();
  41. $s3->save();
  42. }
  43. function _workflow_test_entity1() {
  44. $workflow = NULL;
  45. // Create a workflow.
  46. dpm('--- Create Workflow ---');
  47. dpm($workflow, '--- test workflow_create() pre');
  48. $workflow = workflow_create('test' . REQUEST_TIME);
  49. dpm($workflow, '--- test workflow_create() pre_save');
  50. $workflow->save();
  51. dpm($workflow, '--- test workflow_create() post_save');
  52. // Create States for the workflow.
  53. dpm('--- Create States ---');
  54. dpm($workflow->getStates(TRUE), '--- test getStates() pre');
  55. dpm($workflow, '--- test getStates() pre');
  56. $s1 = $workflow->createState('first');
  57. dpm($workflow->getStates(TRUE), '--- test getStates() post s1');
  58. dpm($workflow, '--- test getStates() post s1');
  59. $s2 = $workflow->createState('second');
  60. $s3 = $workflow->createState('third');
  61. // $s1->save();
  62. // $s2->save();
  63. // $s3->save();
  64. dpm($workflow->getStates(TRUE), '--- test getStates() post');
  65. dpm($workflow, '--- test getStates() post');
  66. dpm($s3->getWorkflow(), '--- test getStates() post');
  67. // Create Transitions for the workflow.
  68. dpm('--- Create Transitions ---');
  69. dpm('--- Create Transition s1->s2 ---');
  70. dpm($workflow->getTransitions(), '--- test getTransitions() pre');
  71. $roles = array(-1, 5);
  72. $t1 = $workflow->createTransition($s1->sid, $s2->sid);
  73. $t1->label = 'transitions t1';
  74. $t1->roles = $roles;
  75. // The transition was initially saved in createState,
  76. // but without roles and name.
  77. $t1->save();
  78. dpm($t1, '-- test show new Transition');
  79. dpm($workflow->getTransitions(), '-- test getTransitions() post 1');
  80. dpm('--- Create Transition s1->s2 ---');
  81. dpm($workflow->getTransitions(), '--- test getTransitions() pre');
  82. $roles = array(-1, 6);
  83. $t2 = $workflow->createTransition($s2->sid, $s3->sid);
  84. $t2->label = 'transitions t2';
  85. $t2->roles = $roles;
  86. // The transition was initially saved in createState,
  87. // but without roles and name.
  88. $t2->save();
  89. dpm($t2, '-- test show new Transition');
  90. dpm($workflow->getTransitions(), '-- test getTransitions() post 2');
  91. dpm('--- Show resulting Workflow ---');
  92. dpm($workflow);
  93. dpm('todo: Test if workflow, states and transitions are properly shown in Admin UI.');
  94. dpm('--- Show resulting Workflow after workflow_load---');
  95. // Refresh the workflow, and show again.
  96. $workflow2 = workflow_load($workflow->wid);
  97. dpm($workflow2);
  98. // dpm($t->uri());
  99. // dpm($t->label());
  100. // Remove the workflow and its components.
  101. dpm('--- Delete resulting Workflow ---');
  102. $workflow->delete();
  103. dpm($workflow);
  104. dpm('todo: Test if workflow, states and transitions are properly deleted.');
  105. }
  106. function _workflow_test_entity2() {
  107. $w = workflow_load('test');
  108. dpm($w);
  109. dpm($w->getTransitions());
  110. return;
  111. $ts = entity_load('WorkflowConfigTransition', array(6));
  112. $t = reset($ts);
  113. $t->roles += array(3 => 3);
  114. entity_save('WorkflowConfigTransition', $t);
  115. }
  116. function _workflow_test_entity3() {
  117. $workflow = workflow_load_single(1);
  118. dpm($workflow->getStates());
  119. dpm($workflow->loadTransitions());
  120. // $t1 = $workflow->createTransition($s1->sid, $s2->sid);
  121. // $t1->save();
  122. // dpm($t1);
  123. // $t2 = $workflow->createTransition('third', 'second');
  124. // $t2->save();
  125. // dpm($t2);
  126. // dpm($t->uri());
  127. // dpm($t->label());
  128. // $workflow->delete();
  129. // $ts = entity_load('WorkflowConfigTransition', array(6));
  130. // $t = reset($ts);
  131. // $t->roles += array(3 => 3);
  132. // entity_save('WorkflowConfigTransition', $t);
  133. }
  134. function _workflow_test_entity_allowable() {
  135. global $user;
  136. $workflow = workflow_create('workflow_test_' . REQUEST_TIME);
  137. $workflow->save();
  138. $s1 = $workflow->createState('to be opened');
  139. $s2 = $workflow->createState('open');
  140. $s3 = $workflow->createState('closed');
  141. $s1->save();
  142. $s2->save();
  143. $s3->save();
  144. $roles = array(1, 2); // anon, auth user.
  145. $t1 = $t = $workflow->createTransition(WORKFLOW_CREATION_STATE_NAME, 'to be opened');
  146. $t->roles = $roles;
  147. $t->save();
  148. $t2 = $t = $workflow->createTransition('to be opened', 'open');
  149. $t->roles = $roles;
  150. $t->save();
  151. $t3 = $t = $workflow->createTransition('open', 'closed');
  152. $t->roles = $roles;
  153. DPM($t3);
  154. $t->save();
  155. DPM($t3);
  156. $t4 = $t = $workflow->createTransition('closed', 'open');
  157. $t->roles = $roles;
  158. $t->save();
  159. dpm($s2->getOptions('', NULL, '', $user, FALSE));
  160. // returns TRUE if the role is allowed to do the transition.
  161. $rc = $t3->isAllowed($role = 2);
  162. dpm($t3);
  163. dpm('this result must be TRUE: ' . (int) $rc);
  164. $rc = $t3->isAllowed($role = 3);
  165. dpm('this result must be FALSE: ' . (int) $rc);
  166. $rc = $workflow->GetTransitionsBySid($s3->sid);
  167. dpm($rc, 'allowed transitions from ' . $s3->label());
  168. $ts = $workflow->getTransitions();
  169. dpm($ts);
  170. $ts = $workflow->getTransitionsBySid($s3->sid);
  171. dpm($ts);
  172. $workflow->delete();
  173. }
  174. function _workflow_test_metadata() {
  175. // Find the first, arbitrary workflow.
  176. $workflows = workflow_load_multiple();
  177. $workflow = reset($workflows);
  178. dpm($workflow);
  179. // Add a Workflow wrapper;
  180. $wrapper = $workflow_wrapper = entity_metadata_wrapper('Workflow', $workflow);
  181. dpm(t('---- Workflow: showing objects ---'));
  182. dpm($wrapper);
  183. // Get properties of the Workflow.
  184. dpm(t('---- Workflow: showing getters ---'));
  185. dpm($wrapper->wid->label() . ' => ' . $wrapper->wid->value() );
  186. dpm($wrapper->name->label() . ' => ' . $wrapper->name->value() );
  187. dpm($wrapper->label->label() . ' => ' . $wrapper->label->value() );
  188. dpm($wrapper->status->value() );
  189. dpm($wrapper->tab_roles->value() );
  190. //dpm($wrapper->states->value() );
  191. dpm($wrapper->states->optionsList() );
  192. //dpm($wrapper->transitions->value() );
  193. dpm($wrapper->options->optionsList() );
  194. // Set properties of the Workflow.
  195. //dpm($wrapper->label->set('ssdfdss') );
  196. // ...
  197. // Get properties of States.
  198. dpm(t('---- start of WorkflowState getters ---'));
  199. $states = $workflow->getStates();
  200. $state = reset($states);
  201. $state_wrapper = entity_metadata_wrapper('WorkflowState', $state);
  202. dpm($states);
  203. dpm( $state_wrapper->sid->value() );
  204. dpm( $state_wrapper->wid->value() );
  205. dpm( $state_wrapper->weight->value() );
  206. //dpm( $state_wrapper->state->value() );
  207. dpm( $state_wrapper->status->value() );
  208. //dpm( $wrapper->author->mail->value() );
  209. //dpm( $wrapper->title->value(array('sanitize' => TRUE)) );
  210. // Get the transitions.
  211. dpm(t('---- start of WorkflowConfigTransition getters ---'));
  212. $transitions = $state->getTransitions();
  213. dpm($transitions);
  214. $options = $state->getOptions('', NULL, '', NULL);
  215. dpm($options);
  216. $transition = reset($transitions);
  217. dpm($transition);
  218. $transition_wrapper = entity_metadata_wrapper('WorkflowConfigTransition', $transition);
  219. dpm( $transition_wrapper );
  220. //dpm( $transition_wrapper->old_sid->value() );
  221. dpm( $transition_wrapper->old_state->value() );
  222. dpm( $transition_wrapper->old_state->value()->sid );
  223. }
  224. /**
  225. * Test all tokens
  226. */
  227. function _workflow_test_tokens($entity_id = 76, $entity_type = 'node', $field_name = NULL) {
  228. global $user;
  229. // $entity_id = 76;
  230. if ($entity_id) {
  231. $node = entity_load_single($entity_type, $entity_id);
  232. }
  233. else {
  234. // Create a node.
  235. $node = new stdClass();
  236. $node->title = "A new Node " . REQUEST_TIME;
  237. $node->type = "WorkfowField";
  238. node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  239. $node->language = LANGUAGE_NONE; // Or for example 'en' if locale is enabled.
  240. $node->uid = $user->uid;
  241. $node->status = 1; //(1 or 0): published or not
  242. $node->promote = 0; //(1 or 0): promoted to front page
  243. $node->comment = 1; // 0 = comments disabled, 1 = read only, 2 = read/write
  244. // // Term reference (taxonomy) field
  245. $node->field_workflow[$node->language][]['value'] = 1;
  246. // // Entity reference field
  247. // $node->field_customer_nid[$node->language][] = array(
  248. // 'target_id' => $form_state['values']['entity id'],
  249. // 'target_type' => 'node',
  250. // );
  251. // 'node' is default,
  252. // Other possible values are "user" and "taxonomy_term".
  253. $node = node_submit($node); // Prepare node for saving
  254. node_save($node);
  255. }
  256. $t_greetings = "
  257. Hello [current-user:name]!
  258. <br/>node type + id + title = [node:content-type] + [node:nid] + [node:title]
  259. ";
  260. $t_node_all = '
  261. <br /> Workflow last transition = [node:last-transition] Last workflow state transition of content.
  262. <br /> Comment comment = [node:last-transition:comment] Workflow executed transition "comment" property.
  263. <br /> Created Medium format = [node:last-transition:created:medium] A date in "medium" format. (Fri, 05/30/2014 - 10:59)
  264. <br /> Created Raw timestamp = [node:last-transition:created:raw] A date in UNIX timestamp format (1401440380)
  265. <br /> Created Seconds-since = [node:last-transition:created:seconds] A date in "seconds ago" format (604800). Use it for easy scheduling workflow transitions.
  266. <br /> Delta = [node:last-transition:delta] Workflow executed transition "delta" property.
  267. <br /> Entity_type = [node:last-transition:entity-type] Workflow executed transition "entity_type" property.
  268. <br /> Field_name = [node:last-transition:field-name] Workflow executed transition "field_name" property.
  269. <br /> label = [node:last-transition:label] Workflow executed transition "label" property.
  270. <br /> Language = [node:last-transition:language] Workflow executed transition "language" property.
  271. <br /> New state = [node:last-transition:new-state] The new state.
  272. <br /> Original workflow state = [node:last-transition:new-state:original] The original workflow state data if the workflow state is being updated or saved.
  273. <br /> State ID = [node:last-transition:new-state:sid] The State ID.
  274. <br /> State label = [node:last-transition:new-state:label] The state label.
  275. <br /> Status = [node:last-transition:new-state:status] Workflow state "status" property.
  276. <br /> Sysid = [node:last-transition:new-state:sysid] Workflow state "sysid" property.
  277. <br /> URL = [node:last-transition:new-state:url] The URL of the workflow state.
  278. <br /> Weight = [node:last-transition:new-state:weight] Workflow state "weight" property.
  279. <br /> Wid = [node:last-transition:new-state:wid] Workflow state "wid" property.
  280. <br /> Nid = [node:last-transition:nid] Workflow executed transition "nid" property.
  281. <br /> Old_sid = [node:last-transition:old-sid] Workflow executed transition "old_sid" property.
  282. <br /> Revision_id = [node:last-transition:revision-id] Workflow executed transition "revision_id" property.
  283. <br /> Sid = [node:last-transition:sid] Workflow executed transition "sid" property.
  284. <br /> Stamp = [node:last-transition:stamp] Workflow executed transition "stamp" property.
  285. <br /> Uid = [node:last-transition:uid] Workflow executed transition "uid" property.
  286. <br /> Old state = [node:last-transition:old-state] The old state.
  287. <br /> Original workflow state = [node:last-transition:old-state:original] The original workflow state data if the workflow state is being updated or saved.
  288. <br /> State ID = [node:last-transition:old-state:sid] The State ID.
  289. <br /> State label = [node:last-transition:old-state:label] The state label.
  290. <br /> Status = [node:last-transition:old-state:status] Workflow state "status" property.
  291. <br /> Sysid = [node:last-transition:old-state:sysid] Workflow state "sysid" property.
  292. <br /> URL = [node:last-transition:old-state:url] The URL of the workflow state.
  293. <br /> Weight = [node:last-transition:old-state:weight] Workflow state "weight" property.
  294. <br /> Wid = [node:last-transition:old-state:wid] Workflow state "wid" property.
  295. <br /> User = [node:last-transition:user] The user that executed the transition.
  296. <br /> Created = [node:last-transition:user:created] The date the user account was created.
  297. <br /> Default theme = [node:last-transition:user:theme] The user"s default theme.
  298. <br /> Edit URL = [node:last-transition:user:edit-url] The URL of the account edit page.
  299. <br /> Email = [node:last-transition:user:mail] The email address of the user account.
  300. <br /> Last access = [node:last-transition:user:last-access] The date the user last accessed the site.
  301. <br /> Last login = [node:last-transition:user:last-login] The date the user last logged in to the site.
  302. <br /> Name = [node:last-transition:user:name] The login name of the user account.
  303. <br /> Original user = [node:last-transition:user:original] The original user data if the user is being updated or saved.
  304. <br /> Picture = [node:last-transition:user:picture] The picture of the user.
  305. <br /> Roles = [node:last-transition:user:roles] The user roles associated with the user account.
  306. <br /> Status = [node:last-transition:user:status] Whether the user is active or blocked.
  307. <br /> URL = [node:last-transition:user:url] The URL of the account profile page.
  308. <br /> User ID = [node:last-transition:user:uid] The unique ID of the user account.
  309. <br /> Workflow = [node:last-transition:Workflow] Workflow the state belongs to.
  310. <br /> Workflow ID = [node:last-transition:Workflow:wid] The ID used to identify this workflow internally.
  311. <br /> Module = [node:last-transition:Workflow:module] Workflow "module" property.
  312. <br /> Options = [node:last-transition:Workflow:options] Workflow "options" property.
  313. <br /> Original workflow = [node:last-transition:Workflow:original] The original workflow data if the workflow is being updated or saved.
  314. <br /> States of this Workflow = [node:last-transition:Workflow:states] States of this Workflow
  315. <br /> Status = [node:last-transition:Workflow:status] Workflow "status" property.
  316. <br /> Tab_roles = [node:last-transition:Workflow:tab-roles] Workflow "tab_roles" property.
  317. <br /> Transitions of this Workflow = [node:last-transition:Workflow:transitions] Transitions of this Workflow
  318. <br /> URL = [node:last-transition:Workflow:url] The URL of the workflow.
  319. <br /> Workflow ID = [node:last-transition:Workflow:wid] The unique ID of the workflow applied to this node.
  320. <br /> Workflow label = [node:last-transition:Workflow:label] The workflow applied to this node.
  321. <br /> Workflow executed transition ID = [node:last-transition:hid] The unique ID of the workflow executed transition.
  322. ';
  323. // This text is to test only a few tokens, for better inspection.
  324. $t_node_sub = '
  325. <br /> User = [node:last-transition:user] The user that executed the transition.
  326. <br /> label = [node:last-transition:label] Workflow executed transition "label" property.
  327. ';
  328. // todo : test old-state
  329. $data = array();
  330. $data['node'] = $node;
  331. $data['entity'] = $node;
  332. $data['entity_type'] = 'node';
  333. // Display the tokenized text.
  334. dpm($node);
  335. dpm(token_replace( $t_greetings, $data));
  336. dpm(token_replace( $t_node_all, $data));
  337. // dpm(token_replace( $t_node_sub, $data));
  338. }
  339. function _workflow_test_tokens_term($entity_id = '2', $entity_type = 'taxonomy_term', $field_name = NULL) {
  340. $token_type = 'term';
  341. global $user;
  342. if ($entity_id) {
  343. $node = entity_load_single($entity_type, $entity_id);
  344. }
  345. else {
  346. // Create a term.
  347. }
  348. $t_greetings = "
  349. Hello [current-user:name]!
  350. <br/>node type + id + title = [term:content-type] + [term:tid] + [term:title]
  351. ";
  352. $t_node_all = '
  353. <br /> Workflow last transition = [term:last-transition] Last workflow state transition of content.
  354. <br /> Comment comment = [term:last-transition:comment] Workflow executed transition "comment" property.
  355. <br /> Created = [term:last-transition:created] The date the transition was created.
  356. <br /> Created Medium format = [term:last-transition:created:medium] A date in "medium" format. (Fri, 05/30/2014 - 10:59)
  357. <br /> Created Raw timestamp = [term:last-transition:created:raw] A date in UNIX timestamp format (1401440380)
  358. <br /> Created Seconds-since = [term:last-transition:created:seconds] A date in "seconds ago" format (604800). Use it for easy scheduling workflow transitions.
  359. <br /> Delta = [term:last-transition:delta] Workflow executed transition "delta" property.
  360. <br /> Entity_type = [term:last-transition:entity-type] Workflow executed transition "entity_type" property.
  361. <br /> Field_name = [term:last-transition:field-name] Workflow executed transition "field_name" property.
  362. <br /> label = [term:last-transition:label] Workflow executed transition "label" property.
  363. <br /> Language = [term:last-transition:language] Workflow executed transition "language" property.
  364. <br /> New state = [term:last-transition:new-state] The new state.
  365. <br /> Original workflow state = [term:last-transition:new-state:original] The original workflow state data if the workflow state is being updated or saved.
  366. <br /> State ID = [term:last-transition:new-state:sid] The State ID.
  367. <br /> State label = [term:last-transition:new-state:label] The state label.
  368. <br /> Status = [term:last-transition:new-state:status] Workflow state "status" property.
  369. <br /> Sysid = [term:last-transition:new-state:sysid] Workflow state "sysid" property.
  370. <br /> URL = [term:last-transition:new-state:url] The URL of the workflow state.
  371. <br /> Weight = [term:last-transition:new-state:weight] Workflow state "weight" property.
  372. <br /> Wid = [term:last-transition:new-state:wid] Workflow state "wid" property.
  373. <br /> Nid = [term:last-transition:nid] Workflow executed transition "nid" property.
  374. <br /> Old_sid = [term:last-transition:old-sid] Workflow executed transition "old_sid" property.
  375. <br /> Revision_id = [term:last-transition:revision-id] Workflow executed transition "revision_id" property.
  376. <br /> Sid = [term:last-transition:sid] Workflow executed transition "sid" property.
  377. <br /> Stamp = [term:last-transition:stamp] Workflow executed transition "stamp" property.
  378. <br /> Uid = [term:last-transition:uid] Workflow executed transition "uid" property.
  379. <br /> Old state = [term:last-transition:old-state] The old state.
  380. <br /> Original workflow state = [term:last-transition:old-state:original] The original workflow state data if the workflow state is being updated or saved.
  381. <br /> State ID = [term:last-transition:old-state:sid] The State ID.
  382. <br /> State label = [term:last-transition:old-state:label] The state label.
  383. <br /> Status = [term:last-transition:old-state:status] Workflow state "status" property.
  384. <br /> Sysid = [term:last-transition:old-state:sysid] Workflow state "sysid" property.
  385. <br /> URL = [term:last-transition:old-state:url] The URL of the workflow state.
  386. <br /> Weight = [term:last-transition:old-state:weight] Workflow state "weight" property.
  387. <br /> Wid = [term:last-transition:old-state:wid] Workflow state "wid" property.
  388. <br /> User = [term:last-transition:user] The user that executed the transition.
  389. <br /> Created = [term:last-transition:user:created] The date the user account was created.
  390. <br /> Default theme = [term:last-transition:user:theme] The user"s default theme.
  391. <br /> Edit URL = [term:last-transition:user:edit-url] The URL of the account edit page.
  392. <br /> Email = [term:last-transition:user:mail] The email address of the user account.
  393. <br /> Last access = [term:last-transition:user:last-access] The date the user last accessed the site.
  394. <br /> Last login = [term:last-transition:user:last-login] The date the user last logged in to the site.
  395. <br /> Name = [term:last-transition:user:name] The login name of the user account.
  396. <br /> Original user = [term:last-transition:user:original] The original user data if the user is being updated or saved.
  397. <br /> Picture = [term:last-transition:user:picture] The picture of the user.
  398. <br /> Roles = [term:last-transition:user:roles] The user roles associated with the user account.
  399. <br /> Status = [term:last-transition:user:status] Whether the user is active or blocked.
  400. <br /> URL = [term:last-transition:user:url] The URL of the account profile page.
  401. <br /> User ID = [term:last-transition:user:uid] The unique ID of the user account.
  402. <br /> Workflow = [term:last-transition:Workflow] Workflow the state belongs to.
  403. <br /> Workflow ID = [term:last-transition:Workflow:wid] The ID used to identify this workflow internally.
  404. <br /> Module = [term:last-transition:Workflow:module] Workflow "module" property.
  405. <br /> Options = [term:last-transition:Workflow:options] Workflow "options" property.
  406. <br /> Original workflow = [term:last-transition:Workflow:original] The original workflow data if the workflow is being updated or saved.
  407. <br /> States of this Workflow = [term:last-transition:Workflow:states] States of this Workflow
  408. <br /> Status = [term:last-transition:Workflow:status] Workflow "status" property.
  409. <br /> Tab_roles = [term:last-transition:Workflow:tab-roles] Workflow "tab_roles" property.
  410. <br /> Transitions of this Workflow = [term:last-transition:Workflow:transitions] Transitions of this Workflow
  411. <br /> URL = [term:last-transition:Workflow:url] The URL of the workflow.
  412. <br /> Workflow ID = [term:last-transition:Workflow:wid] The unique ID of the workflow applied to this node.
  413. <br /> Workflow label = [term:last-transition:Workflow:label] The workflow applied to this node.
  414. <br /> Workflow executed transition ID = [term:last-transition:hid] The unique ID of the workflow executed transition.
  415. ';
  416. // This text is to test only a few tokens, for better inspection.
  417. $t_node_sub = '
  418. <br /> Workflow = [term:last-transition:Workflow] Workflow the state belongs to.
  419. ';
  420. $data = array();
  421. // $data['node'] = $node;
  422. $data['term'] = $node;
  423. $data['entity'] = $node;
  424. $data['entity_type'] = $entity_type;
  425. $data['token_type'] = $token_type;
  426. $options['sanitize'] = FALSE;
  427. $options['clear'] = TRUE;
  428. $options['language'] = NULL;
  429. //dpm($node);
  430. //dpm($data);
  431. // Display the tokenized text.
  432. // dpm(token_replace($t_greetings, $data));
  433. dpm(token_replace($t_node_all, $data, $options));
  434. }
  435. /**
  436. * Test, taken from CommentTokenReplaceTestCase::testCommentTokenReplacement
  437. */
  438. /*
  439. function WorkflowCommentTokenReplacement() {
  440. global $language;
  441. $url_options = array(
  442. 'absolute' => TRUE,
  443. 'language' => $language,
  444. );
  445. $this->drupalLogin($this->admin_user);
  446. // Set comment variables.
  447. $this->setCommentSubject(TRUE);
  448. // Create a node and a comment.
  449. $node = $this->drupalCreateNode(array('type' => 'article'));
  450. $parent_comment = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
  451. // Post a reply to the comment.
  452. $this->drupalGet('comment/reply/' . $node->nid . '/' . $parent_comment->id);
  453. $child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
  454. $comment = comment_load($child_comment->id);
  455. $comment->homepage = 'http://example.org/';
  456. // Add HTML to ensure that sanitation of some fields tested directly.
  457. $comment->subject = '<blink>Blinking Comment</blink>';
  458. $instance = field_info_instance('comment', 'body', 'comment_body');
  459. // Generate and test sanitized tokens.
  460. $tests = array();
  461. $tests['[comment:cid]'] = $comment->cid;
  462. $tests['[comment:hostname]'] = check_plain($comment->hostname);
  463. $tests['[comment:name]'] = filter_xss($comment->name);
  464. $tests['[comment:mail]'] = check_plain($this->admin_user->mail);
  465. $tests['[comment:homepage]'] = check_url($comment->homepage);
  466. $tests['[comment:title]'] = filter_xss($comment->subject);
  467. $tests['[comment:body]'] = _text_sanitize($instance, LANGUAGE_NONE, $comment->comment_body[LANGUAGE_NONE][0], 'value');
  468. $tests['[comment:url]'] = url('comment/' . $comment->cid, $url_options + array('fragment' => 'comment-' . $comment->cid));
  469. $tests['[comment:edit-url]'] = url('comment/' . $comment->cid . '/edit', $url_options);
  470. $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created, 2, $language->language);
  471. $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed, 2, $language->language);
  472. $tests['[comment:parent:cid]'] = $comment->pid;
  473. $tests['[comment:parent:title]'] = check_plain($parent_comment->subject);
  474. $tests['[comment:node:nid]'] = $comment->nid;
  475. $tests['[comment:node:title]'] = check_plain($node->title);
  476. $tests['[comment:author:uid]'] = $comment->uid;
  477. $tests['[comment:author:name]'] = check_plain($this->admin_user->name);
  478. // Test to make sure that we generated something for each token.
  479. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
  480. foreach ($tests as $input => $expected) {
  481. $output = token_replace($input, array('comment' => $comment), array('language' => $language));
  482. $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input)));
  483. }
  484. // Generate and test unsanitized tokens.
  485. $tests['[comment:hostname]'] = $comment->hostname;
  486. $tests['[comment:name]'] = $comment->name;
  487. $tests['[comment:mail]'] = $this->admin_user->mail;
  488. $tests['[comment:homepage]'] = $comment->homepage;
  489. $tests['[comment:title]'] = $comment->subject;
  490. $tests['[comment:body]'] = $comment->comment_body[LANGUAGE_NONE][0]['value'];
  491. $tests['[comment:parent:title]'] = $parent_comment->subject;
  492. $tests['[comment:node:title]'] = $node->title;
  493. $tests['[comment:author:name]'] = $this->admin_user->name;
  494. foreach ($tests as $input => $expected) {
  495. $output = token_replace($input, array('comment' => $comment), array('language' => $language, 'sanitize' => FALSE));
  496. $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
  497. }
  498. // Load node so comment_count gets computed.
  499. $node = node_load($node->nid);
  500. // Generate comment tokens for the node (it has 2 comments, both new).
  501. $tests = array();
  502. $tests['[node:comment-count]'] = 2;
  503. $tests['[node:comment-count-new]'] = 2;
  504. foreach ($tests as $input => $expected) {
  505. $output = token_replace($input, array('node' => $node), array('language' => $language));
  506. $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
  507. }
  508. }
  509. */