1
|
<?php
|
2
|
|
3
|
class ActionsConfigurationTestCase extends DrupalWebTestCase {
|
4
|
public static function getInfo() {
|
5
|
return array(
|
6
|
'name' => 'Actions configuration',
|
7
|
'description' => 'Tests complex actions configuration by adding, editing, and deleting a complex action.',
|
8
|
'group' => 'Actions',
|
9
|
);
|
10
|
}
|
11
|
|
12
|
/**
|
13
|
* Test the configuration of advanced actions through the administration
|
14
|
* interface.
|
15
|
*/
|
16
|
function testActionConfiguration() {
|
17
|
// Create a user with permission to view the actions administration pages.
|
18
|
$user = $this->drupalCreateUser(array('administer actions'));
|
19
|
$this->drupalLogin($user);
|
20
|
|
21
|
// Make a POST request to admin/config/system/actions/manage.
|
22
|
$edit = array();
|
23
|
$edit['action'] = drupal_hash_base64('system_goto_action');
|
24
|
$this->drupalPost('admin/config/system/actions/manage', $edit, t('Create'));
|
25
|
|
26
|
// Make a POST request to the individual action configuration page.
|
27
|
$edit = array();
|
28
|
$action_label = $this->randomName();
|
29
|
$edit['actions_label'] = $action_label;
|
30
|
$edit['url'] = 'admin';
|
31
|
$this->drupalPost('admin/config/system/actions/configure/' . drupal_hash_base64('system_goto_action'), $edit, t('Save'));
|
32
|
|
33
|
// Make sure that the new complex action was saved properly.
|
34
|
$this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action."));
|
35
|
$this->assertText($action_label, t("Make sure the action label appears on the configuration page after we've saved the complex action."));
|
36
|
|
37
|
// Make another POST request to the action edit page.
|
38
|
$this->clickLink(t('configure'));
|
39
|
preg_match('|admin/config/system/actions/configure/(\d+)|', $this->getUrl(), $matches);
|
40
|
$aid = $matches[1];
|
41
|
$edit = array();
|
42
|
$new_action_label = $this->randomName();
|
43
|
$edit['actions_label'] = $new_action_label;
|
44
|
$edit['url'] = 'admin';
|
45
|
$this->drupalPost(NULL, $edit, t('Save'));
|
46
|
|
47
|
// Make sure that the action updated properly.
|
48
|
$this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully updated the complex action."));
|
49
|
$this->assertNoText($action_label, t("Make sure the old action label does NOT appear on the configuration page after we've updated the complex action."));
|
50
|
$this->assertText($new_action_label, t("Make sure the action label appears on the configuration page after we've updated the complex action."));
|
51
|
|
52
|
// Make sure that deletions work properly.
|
53
|
$this->clickLink(t('delete'));
|
54
|
$edit = array();
|
55
|
$this->drupalPost("admin/config/system/actions/delete/$aid", $edit, t('Delete'));
|
56
|
|
57
|
// Make sure that the action was actually deleted.
|
58
|
$this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), t('Make sure that we get a delete confirmation message.'));
|
59
|
$this->drupalGet('admin/config/system/actions/manage');
|
60
|
$this->assertNoText($new_action_label, t("Make sure the action label does not appear on the overview page after we've deleted the action."));
|
61
|
$exists = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'drupal_goto_action'))->fetchField();
|
62
|
$this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.'));
|
63
|
}
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Test actions executing in a potential loop, and make sure they abort properly.
|
68
|
*/
|
69
|
class ActionLoopTestCase extends DrupalWebTestCase {
|
70
|
public static function getInfo() {
|
71
|
return array(
|
72
|
'name' => 'Actions executing in a potentially infinite loop',
|
73
|
'description' => 'Tests actions executing in a loop, and makes sure they abort properly.',
|
74
|
'group' => 'Actions',
|
75
|
);
|
76
|
}
|
77
|
|
78
|
function setUp() {
|
79
|
parent::setUp('dblog', 'trigger', 'actions_loop_test');
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Set up a loop with 3 - 12 recursions, and see if it aborts properly.
|
84
|
*/
|
85
|
function testActionLoop() {
|
86
|
$user = $this->drupalCreateUser(array('administer actions'));
|
87
|
$this->drupalLogin($user);
|
88
|
|
89
|
$hash = drupal_hash_base64('actions_loop_test_log');
|
90
|
$edit = array('aid' => $hash);
|
91
|
$this->drupalPost('admin/structure/trigger/actions_loop_test', $edit, t('Assign'));
|
92
|
|
93
|
// Delete any existing watchdog messages to clear the plethora of
|
94
|
// "Action added" messages from when Drupal was installed.
|
95
|
db_delete('watchdog')->execute();
|
96
|
// To prevent this test from failing when xdebug is enabled, the maximum
|
97
|
// recursion level should be kept low enough to prevent the xdebug
|
98
|
// infinite recursion protection mechanism from aborting the request.
|
99
|
// See http://drupal.org/node/587634.
|
100
|
variable_set('actions_max_stack', 7);
|
101
|
$this->triggerActions();
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Create an infinite loop by causing a watchdog message to be set,
|
106
|
* which causes the actions to be triggered again, up to actions_max_stack
|
107
|
* times.
|
108
|
*/
|
109
|
protected function triggerActions() {
|
110
|
$this->drupalGet('<front>', array('query' => array('trigger_actions_on_watchdog' => TRUE)));
|
111
|
$expected = array();
|
112
|
$expected[] = 'Triggering action loop';
|
113
|
for ($i = 1; $i <= variable_get('actions_max_stack', 35); $i++) {
|
114
|
$expected[] = "Test log #$i";
|
115
|
}
|
116
|
$expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.';
|
117
|
|
118
|
$result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid");
|
119
|
$loop_started = FALSE;
|
120
|
foreach ($result as $row) {
|
121
|
$expected_message = array_shift($expected);
|
122
|
$this->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array('%expected' => $expected_message, '%message' => $row->message)));
|
123
|
}
|
124
|
$this->assertTrue(empty($expected), t('All expected messages found.'));
|
125
|
}
|
126
|
}
|