rules_admin.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @file
  4. * Rules UI tests.
  5. */
  6. /**
  7. * Tests for creating rules through the UI.
  8. */
  9. class RulesUiTestCase extends DrupalWebTestCase {
  10. /**
  11. * Declares test metadata.
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Rules UI Tests ',
  16. 'description' => 'Tests Rules UI.',
  17. 'group' => 'Rules',
  18. );
  19. }
  20. /**
  21. * Overrides DrupalWebTestCase::setUp().
  22. */
  23. protected function setUp() {
  24. parent::setUp('rules', 'rules_admin', 'rules_test');
  25. RulesLog::logger()->clear();
  26. variable_set('rules_debug_log', TRUE);
  27. }
  28. /**
  29. * Tests that NOT condition labels are not HTML-encoded in the UI.
  30. *
  31. * @see https://www.drupal.org/project/rules/issues/1945006
  32. */
  33. public function testConditionLabel() {
  34. // Create a simple user account with permission to create a rule.
  35. $user = $this->drupalCreateUser(array('access administration pages', 'administer rules'));
  36. $this->drupalLogin($user);
  37. // First we need an event.
  38. $this->drupalGet('admin/config/workflow/rules/reaction/add');
  39. $edit = array(
  40. 'settings[label]' => 'Test node event',
  41. 'settings[name]' => 'test_node_event',
  42. 'event' => 'node_insert',
  43. );
  44. $this->drupalPost(NULL, $edit, 'Save');
  45. $this->assertText('Editing reaction rule', 'Rule edit page is shown.');
  46. // Now add a condition with a special character in the label.
  47. $this->clickLink('Add condition');
  48. $this->assertText('Add a new condition', 'Condition edit page is shown.');
  49. $edit = array(
  50. 'element_name' => 'rules_test_condition_apostrophe',
  51. );
  52. $this->drupalPost(NULL, $edit, 'Continue');
  53. // Negate the condition, as this is how it gets improperly HTML encoded.
  54. $edit = array(
  55. 'negate' => TRUE,
  56. );
  57. $this->drupalPost(NULL, $edit, 'Save');
  58. $this->assertNoRaw("&amp;#039;", 'Apostrophe is not HTML-encoded.');
  59. }
  60. }
  61. /**
  62. * UI test cases for the minimal profile.
  63. *
  64. * The minimal profile is useful for testing because it has fewer dependencies
  65. * so the tests run faster. Also, removing the profile-specific configuration
  66. * reveals assumptions in the code. For example, the minimal profile doesn't
  67. * define any content types, so when Rules expects to have content types to
  68. * operate on that assumpation may cause errors.
  69. */
  70. class RulesMinimalProfileTestCase extends DrupalWebTestCase {
  71. protected $profile = 'minimal';
  72. /**
  73. * Declares test metadata.
  74. */
  75. public static function getInfo() {
  76. return array(
  77. 'name' => 'Rules UI Minimal Profile Tests ',
  78. 'description' => 'Tests UI support for minimal profile.',
  79. 'group' => 'Rules',
  80. );
  81. }
  82. /**
  83. * Overrides DrupalWebTestCase::setUp().
  84. */
  85. protected function setUp() {
  86. parent::setUp('rules', 'rules_admin');
  87. RulesLog::logger()->clear();
  88. variable_set('rules_debug_log', TRUE);
  89. }
  90. /**
  91. * Tests node event UI without content types.
  92. *
  93. * @see https://www.drupal.org/project/rules/issues/2267341
  94. */
  95. public function testNodeEventUi() {
  96. // Create a simple user account with permission to create a rule.
  97. $user = $this->drupalCreateUser(array('access administration pages', 'administer rules'));
  98. $this->drupalLogin($user);
  99. $this->drupalGet('admin/config/workflow/rules/reaction/add');
  100. $edit = array(
  101. 'settings[label]' => 'Test node event',
  102. 'settings[name]' => 'test_node_event',
  103. 'event' => 'node_insert',
  104. );
  105. $this->drupalPostAJAX(NULL, $edit, 'event');
  106. $this->assertText('Restrict by type', 'Restrict by type selection is visible.');
  107. $this->drupalPost(NULL, $edit, 'Save');
  108. $this->assertText('Editing reaction rule', 'Rule edit page is shown.');
  109. }
  110. }