<?php
class ActionsConfigurationTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Actions configuration',
'description' => 'Tests complex actions configuration by adding, editing, and deleting a complex action.',
'group' => 'Actions',
);
}
function testActionConfiguration() {
$user = $this
->drupalCreateUser(array(
'administer actions',
));
$this
->drupalLogin($user);
$edit = array();
$edit['action'] = drupal_hash_base64('system_goto_action');
$this
->drupalPost('admin/config/system/actions/manage', $edit, t('Create'));
$edit = array();
$action_label = $this
->randomName();
$edit['actions_label'] = $action_label;
$edit['url'] = 'admin';
$this
->drupalPost('admin/config/system/actions/configure/' . drupal_hash_base64('system_goto_action'), $edit, t('Save'));
$this
->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action."));
$this
->assertText($action_label, t("Make sure the action label appears on the configuration page after we've saved the complex action."));
$this
->clickLink(t('configure'));
preg_match('|admin/config/system/actions/configure/(\\d+)|', $this
->getUrl(), $matches);
$aid = $matches[1];
$edit = array();
$new_action_label = $this
->randomName();
$edit['actions_label'] = $new_action_label;
$edit['url'] = 'admin';
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully updated the complex action."));
$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."));
$this
->assertText($new_action_label, t("Make sure the action label appears on the configuration page after we've updated the complex action."));
$this
->clickLink(t('delete'));
$edit = array();
$this
->drupalPost("admin/config/system/actions/delete/{$aid}", $edit, t('Delete'));
$this
->assertRaw(t('Action %action was deleted', array(
'%action' => $new_action_label,
)), t('Make sure that we get a delete confirmation message.'));
$this
->drupalGet('admin/config/system/actions/manage');
$this
->assertNoText($new_action_label, t("Make sure the action label does not appear on the overview page after we've deleted the action."));
$exists = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(
':callback' => 'drupal_goto_action',
))
->fetchField();
$this
->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.'));
}
}
class ActionLoopTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Actions executing in a potentially infinite loop',
'description' => 'Tests actions executing in a loop, and makes sure they abort properly.',
'group' => 'Actions',
);
}
function setUp() {
parent::setUp('dblog', 'trigger', 'actions_loop_test');
}
function testActionLoop() {
$user = $this
->drupalCreateUser(array(
'administer actions',
));
$this
->drupalLogin($user);
$hash = drupal_hash_base64('actions_loop_test_log');
$edit = array(
'aid' => $hash,
);
$this
->drupalPost('admin/structure/trigger/actions_loop_test', $edit, t('Assign'));
db_delete('watchdog')
->execute();
variable_set('actions_max_stack', 7);
$this
->triggerActions();
}
protected function triggerActions() {
$this
->drupalGet('<front>', array(
'query' => array(
'trigger_actions_on_watchdog' => TRUE,
),
));
$expected = array();
$expected[] = 'Triggering action loop';
for ($i = 1; $i <= variable_get('actions_max_stack', 35); $i++) {
$expected[] = "Test log #{$i}";
}
$expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.';
$result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid");
$loop_started = FALSE;
foreach ($result as $row) {
$expected_message = array_shift($expected);
$this
->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array(
'%expected' => $expected_message,
'%message' => $row->message,
)));
}
$this
->assertTrue(empty($expected), t('All expected messages found.'));
}
}