token_example.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @file
  4. * Test cases for Testing the token example module.
  5. */
  6. /**
  7. * Functional tests for the Token Example module.
  8. *
  9. * @ingroup token_example
  10. */
  11. class TokenExampleTestCase extends DrupalWebTestCase {
  12. protected $webUser;
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static function getInfo() {
  17. return array(
  18. 'name' => 'Token example functionality',
  19. 'description' => 'Verify the token example interface.',
  20. 'group' => 'Examples',
  21. );
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function setUp() {
  27. parent::setUp('token_example');
  28. $this->webUser = $this->drupalCreateUser();
  29. $this->drupalLogin($this->webUser);
  30. }
  31. /**
  32. * Test interface.
  33. */
  34. public function testInterface() {
  35. $filtered_id = db_query("SELECT format FROM {filter_format} WHERE name = 'Filtered HTML'")->fetchField();
  36. $default_format_id = filter_default_format($this->webUser);
  37. $this->drupalGet('examples/token');
  38. $this->assertNoFieldByName('node');
  39. $this->assertNoFieldByName('user');
  40. $edit = array(
  41. 'text' => 'User [current-user:name] is trying the token example!',
  42. );
  43. $this->drupalPost(NULL, $edit, t('Submit'));
  44. $this->assertText('User ' . $this->webUser->name . ' is trying the token example!');
  45. // Create a node and then make the 'Plain text' text format the default.
  46. $node = $this->drupalCreateNode(array('title' => 'Example node', 'status' => NODE_PUBLISHED));
  47. db_update('filter_format')
  48. ->fields(array('weight' => -10))
  49. ->condition('name', 'Plain text')
  50. ->execute();
  51. $this->drupalGet('examples/token');
  52. $edit = array(
  53. 'text' => 'Would you like to view the [node:type-name] [node:title] with text format [node:body-format] (ID [node:body-format:id])?',
  54. 'node' => $node->nid,
  55. );
  56. $this->drupalPost(NULL, $edit, t('Submit'));
  57. $this->assertText('Would you like to view the Basic page Example node with text format Filtered HTML (ID ' . $filtered_id . ')?');
  58. $edit = array(
  59. 'text' => 'Your default text format is [default-format:name] (ID [default-format:id]).',
  60. );
  61. $this->drupalPost(NULL, $edit, t('Submit'));
  62. $this->assertText('Your default text format is Filtered HTML (ID ' . $default_format_id . ')');
  63. }
  64. }