context.test 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
  3. public static function getInfo() {
  4. return array(
  5. 'name' => 'Keywords substitution',
  6. 'description' => 'Verify that keywords are properly replaced with data.',
  7. 'group' => 'Chaos Tools Suite',
  8. );
  9. }
  10. public function setUp() {
  11. parent::setUp('ctools');
  12. ctools_include('context');
  13. }
  14. public function testKeywordsSubstitution() {
  15. // Create node context for substitution.
  16. $node = $this->drupalCreateNode();
  17. $context = ctools_context_create('node', $node);
  18. $contexts = array('argument_1' => $context);
  19. // Run tests on some edge cases.
  20. $checks = array(
  21. '%node:changed:raw:' => array(
  22. "{$node->changed}:",
  23. t('Multi-level token has been replaced. Colon left untouched.'),
  24. ),
  25. '%node:title' => array(
  26. "{$node->title}",
  27. t('Keyword and converter have been replaced.'),
  28. ),
  29. '%%node:title' => array(
  30. "%node:title",
  31. t('Keyword after escaped percent sign left untouched.'),
  32. ),
  33. '%node:title%node:nid' => array(
  34. "{$node->title}{$node->nid}",
  35. t('Multiple substitutions have been replaced.'),
  36. ),
  37. '%node:title:' => array(
  38. "{$node->title}:",
  39. t('Colon after keyword and converter left untouched.'),
  40. ),
  41. '%node:title%%' => array(
  42. "{$node->title}%",
  43. t('Escaped percent sign after keyword and converter left untouched.'),
  44. ),
  45. '%%%node:title' => array(
  46. "%{$node->title}",
  47. t('Keyword after escaped and unescaped percent sign has been replaced.'),
  48. ),
  49. );
  50. foreach ($checks as $string => $expectations) {
  51. list($expected_result, $message) = $expectations;
  52. $actual_result = ctools_context_keyword_substitute($string, array(), $contexts);
  53. $this->assertEqual($actual_result, $expected_result, $message);
  54. }
  55. }
  56. }