filter_example.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Test case for Testing the filter example module.
  5. *
  6. * This file contains the test cases to check if module is performing as
  7. * expected.
  8. */
  9. /**
  10. * Functional tests for the Filter Example module.
  11. *
  12. * @ingroup filter_example
  13. */
  14. class FilterExampleTestCase extends DrupalWebTestCase {
  15. protected $webUser;
  16. protected $filteredHtml;
  17. protected $fullHtml;
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function getInfo() {
  22. return array(
  23. 'name' => 'Filter example functionality',
  24. 'description' => 'Verify that content is processed by example filter.',
  25. 'group' => 'Examples',
  26. );
  27. }
  28. /**
  29. * Enable modules and create user with specific permissions.
  30. */
  31. public function setUp() {
  32. parent::setUp('filter_example');
  33. // Load the used input formats.
  34. $this->filteredHtml = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchObject();
  35. $this->fullHtml = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
  36. // Create user.
  37. $this->webUser = $this->drupalCreateUser(array(
  38. 'administer filters',
  39. filter_permission_name($this->filteredHtml),
  40. filter_permission_name($this->fullHtml),
  41. 'bypass node access',
  42. ));
  43. }
  44. /**
  45. * Functional test of the foo filter.
  46. *
  47. * Login user, create an example node, and test blog functionality through
  48. * the admin and user interfaces.
  49. */
  50. public function testFilterExampleBasic() {
  51. // Login the admin user.
  52. $this->drupalLogin($this->webUser);
  53. // Enable both filters in format id 1 (default format).
  54. $edit = array(
  55. 'filters[filter_time][status]' => TRUE,
  56. 'filters[filter_foo][status]' => TRUE,
  57. );
  58. $this->drupalPost('admin/config/content/formats/' . $this->filteredHtml->format, $edit, t('Save configuration'));
  59. // Create a content type to test the filters (with default format).
  60. $content_type = $this->drupalCreateContentType();
  61. // Create a test node.
  62. $langcode = LANGUAGE_NONE;
  63. $edit = array(
  64. "title" => $this->randomName(),
  65. "body[$langcode][0][value]" => 'What foo is it? it is <time />',
  66. );
  67. $result = $this->drupalPost('node/add/' . $content_type->type, $edit, t('Save'));
  68. $this->assertResponse(200);
  69. $time = format_date(time());
  70. $this->assertRaw('What bar is it? it is <em>' . $time . '</em>');
  71. // Enable foo filter in other format id 2
  72. $edit = array(
  73. 'filters[filter_foo][status]' => TRUE,
  74. );
  75. $this->drupalPost('admin/config/content/formats/' . $this->fullHtml->format, $edit, t('Save configuration'));
  76. // Change foo filter replacement with a random string in format id 2
  77. $replacement = $this->randomName();
  78. $options = array(
  79. 'filters[filter_foo][settings][filter_example_foo]' => $replacement,
  80. );
  81. $this->drupalPost('admin/config/content/formats/' . $this->fullHtml->format, $options, t('Save configuration'));
  82. // Create a test node with content format 2
  83. $langcode = LANGUAGE_NONE;
  84. $edit = array(
  85. "title" => $this->randomName(),
  86. "body[$langcode][0][value]" => 'What foo is it? it is <time />',
  87. "body[$langcode][0][format]" => $this->fullHtml->format,
  88. );
  89. $result = $this->drupalPost('node/add/' . $content_type->type, $edit, t('Save'));
  90. $this->assertResponse(200);
  91. // Only foo filter is enabled.
  92. $this->assertRaw("What " . $replacement . " is it", 'Foo filter successfully verified.');
  93. }
  94. }