filter_example.test

  1. examples
    1. 7 filter_example/filter_example.test
    2. 8 filter_example/filter_example.test

Test case for Testing the filter example module.

This file contains the test cases to check if module is performing as expected.

Classes

NameDescription
FilterExampleTestCase@file Test case for Testing the filter example module.

File

filter_example/filter_example.test
View source
  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. class FilterExampleTestCase extends DrupalWebTestCase {
  10. protected $web_user;
  11. protected $filtered_html;
  12. protected $full_html;
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Filter example functionality',
  16. 'description' => 'Verify that content is processed by example filter.',
  17. 'group' => 'Examples',
  18. );
  19. }
  20. /**
  21. * Enable modules and create user with specific permissions.
  22. */
  23. function setUp() {
  24. parent::setUp('filter_example');
  25. // Load the used input formats.
  26. $this->filtered_html = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchObject();
  27. $this->full_html = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
  28. // Create user.
  29. $this->web_user = $this->drupalCreateUser(array(
  30. 'administer filters',
  31. filter_permission_name($this->filtered_html),
  32. filter_permission_name($this->full_html),
  33. 'bypass node access',
  34. ));
  35. }
  36. /**
  37. * Login user, create an example node, and test blog functionality through the admin and user interfaces.
  38. */
  39. function testFilterExampleBasic() {
  40. // Login the admin user.
  41. $this->drupalLogin($this->web_user);
  42. // Enable both filters in format id 1 (default format)
  43. $edit = array(
  44. 'filters[filter_time][status]' => TRUE,
  45. 'filters[filter_foo][status]' => TRUE,
  46. );
  47. $this->drupalPost('admin/config/content/formats/' . $this->filtered_html->format, $edit, t('Save configuration'));
  48. // Create a content type to test the filters (with default format)
  49. $content_type = $this->drupalCreateContentType();
  50. // Create a test node
  51. $langcode = LANGUAGE_NONE;
  52. $edit = array(
  53. "title" => $this->randomName(),
  54. "body[$langcode][0][value]" => 'What foo is it? it is <time />',
  55. );
  56. $result = $this->drupalPost('node/add/' . $content_type->type, $edit, t('Save'));
  57. $this->assertResponse(200);
  58. $time = format_date(time());
  59. $this->assertRaw('What bar is it? it is <em>' . $time . '</em>');
  60. // Enable foo filter in other format id 2
  61. $edit = array(
  62. 'filters[filter_foo][status]' => TRUE,
  63. );
  64. $this->drupalPost('admin/config/content/formats/' . $this->full_html->format, $edit, t('Save configuration'));
  65. // Change foo filter replacement with a random string in format id 2
  66. $replacement = $this->randomName();
  67. $options = array(
  68. 'filters[filter_foo][settings][filter_example_foo]' => $replacement,
  69. );
  70. $this->drupalPost('admin/config/content/formats/' . $this->full_html->format, $options, t('Save configuration'));
  71. // Create a test node with content format 2
  72. $langcode = LANGUAGE_NONE;
  73. $edit = array(
  74. "title" => $this->randomName(),
  75. "body[$langcode][0][value]" => 'What foo is it? it is <time />',
  76. "body[$langcode][0][format]" => $this->full_html->format,
  77. );
  78. $result = $this->drupalPost('node/add/' . $content_type->type, $edit, t('Save'));
  79. $this->assertResponse(200);
  80. // Only foo filter is enabled
  81. $this->assertRaw("What " . $replacement . " is it", t('Foo filter successfully verified.'));
  82. }
  83. }
Login or register to post comments