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