2008-06-29 12:10:32 +00:00
<?php
2008-07-19 12:31:14 +00:00
// $Id$
2008-06-29 12:10:32 +00:00
class ActionsConfigurationTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-06-29 12:10:32 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Actions configuration',
'description' => 'Tests complex actions configuration by adding, editing, and deleting a complex action.',
2009-08-22 15:35:36 +00:00
'group' => 'Actions',
2008-06-29 12:10:32 +00:00
);
}
/**
* Test the configuration of advanced actions through the administration
* interface.
*/
function testActionConfiguration() {
// Create a user with permission to view the actions administration pages.
$user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($user);
2009-09-01 16:50:12 +00:00
// Make a POST request to admin/config/system/actions/manage.
2008-06-29 12:10:32 +00:00
$edit = array();
$edit['action'] = md5('system_goto_action');
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/actions/manage', $edit, t('Create'));
2008-06-29 12:10:32 +00:00
// Make a POST request to the individual action configuration page.
$edit = array();
2009-09-19 11:07:37 +00:00
$action_label = $this->randomName();
$edit['actions_label'] = $action_label;
2008-06-29 12:10:32 +00:00
$edit['url'] = 'admin';
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/actions/configure/' . md5('system_goto_action'), $edit, t('Save'));
2008-06-29 12:10:32 +00:00
// Make sure that the new complex action was saved properly.
$this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action."));
2009-09-19 11:07:37 +00:00
$this->assertText($action_label, t("Make sure the action label appears on the configuration page after we've saved the complex action."));
2008-06-29 12:10:32 +00:00
// Make another POST request to the action edit page.
$this->clickLink(t('configure'));
2009-10-18 06:56:24 +00:00
preg_match('|admin/config/system/actions/configure/(\d+)|', $this->getUrl(), $matches);
$aid = $matches[1];
2008-06-29 12:10:32 +00:00
$edit = array();
2009-09-19 11:07:37 +00:00
$new_action_label = $this->randomName();
$edit['actions_label'] = $new_action_label;
2008-06-29 12:10:32 +00:00
$edit['url'] = 'admin';
2009-10-18 06:56:24 +00:00
$this->drupalPost(NULL, $edit, t('Save'));
2008-06-29 12:10:32 +00:00
// Make sure that the action updated properly.
$this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully updated the complex action."));
2009-09-19 11:07:37 +00:00
$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."));
2008-06-29 12:10:32 +00:00
// Make sure that deletions work properly.
$this->clickLink(t('delete'));
$edit = array();
2009-10-18 06:56:24 +00:00
$this->drupalPost("admin/config/system/actions/delete/$aid", $edit, t('Delete'));
2008-06-29 12:10:32 +00:00
// Make sure that the action was actually deleted.
2009-09-19 11:07:37 +00:00
$this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), t('Make sure that we get a delete confirmation message.'));
2009-09-01 16:50:12 +00:00
$this->drupalGet('admin/config/system/actions/manage');
2009-09-19 11:07:37 +00:00
$this->assertNoText($new_action_label, t("Make sure the action label does not appear on the overview page after we've deleted the action."));
2009-05-30 11:17:32 +00:00
$exists = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'drupal_goto_action'))->fetchField();
2008-06-29 12:10:32 +00:00
$this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.'));
}
}
2009-08-22 15:35:36 +00:00
/**
* Test actions executing in a potential loop, and make sure they abort properly.
*/
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');
}
/**
* Set up a loop with 10-50 recursions, and see if it aborts properly.
*/
function testActionLoop() {
$user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($user);
$hash = md5('actions_loop_test_log');
$edit = array('aid' => $hash);
$this->drupalPost('admin/structure/trigger/actions_loop_test', $edit, t('Assign'));
// Delete any existing watchdog messages to clear the plethora of
// "Action added" messages from when Drupal was installed.
db_delete('watchdog')->execute();
2010-01-10 17:19:01 +00:00
// To prevent this test from failing when xdebug is enabled, the maximum
// recursion level should be kept low enough to prevent the xdebug
// infinite recursion protection mechanism from aborting the request.
// @see http://drupal.org/node/587634.
variable_set('actions_max_stack', mt_rand(3, 12));
2009-08-22 15:35:36 +00:00
$this->triggerActions();
}
/**
* Create an infinite loop by causing a watchdog message to be set,
2010-01-30 07:59:26 +00:00
* which causes the actions to be triggered again, up to actions_max_stack
2010-01-10 17:19:01 +00:00
* times.
2009-08-22 15:35:36 +00:00
*/
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 * FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY timestamp");
$loop_started = FALSE;
2009-09-18 00:04:24 +00:00
foreach ($result as $row) {
2009-11-10 17:27:54 +00:00
2009-08-22 15:35:36 +00:00
$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.'));
}
}