diff --git a/modules/trigger/tests/trigger_test.module b/modules/trigger/tests/trigger_test.module index 72fe352842..005d750a36 100644 --- a/modules/trigger/tests/trigger_test.module +++ b/modules/trigger/tests/trigger_test.module @@ -134,3 +134,12 @@ function trigger_test_generic_any_action($context) { // Indicate successful execution by setting a persistent variable. variable_set('trigger_test_generic_any_action', variable_get('trigger_test_generic_any_action', 0) + 1); } + +/** + * Implements hook_node_insert() so we can make sure it's being invoked. + */ +function trigger_test_node_insert($node) { + $nodes = variable_get('trigger_test_nodes_inserted', array()); + $nodes[] = $node->nid; + variable_set('trigger_test_nodes_inserted', $nodes); +} diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index 09169b723d..3ffcf69fec 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -135,6 +135,50 @@ class TriggerContentTestCase extends TriggerWebTestCase { $this->assertTrue($count == 2, format_string('Action was triggered 2 times. Actual: %count', array('%count' => $count))); } + /** + * Tests that the go to page action doesn't break node creation. + * + * Verifies that if you add a trigger/action to redirect to the + * site home page when new content is saved, hook_node_insert() is still + * being invoked. + * + * See issue http://drupal.org/node/732542 + */ + function testGoToOnNodeSave() { + // Create a user who can create content and administer actions/triggers. + $web_user = $this->drupalCreateUser(array('administer nodes', 'administer actions', 'create page content')); + $this->drupalLogin($web_user); + + // Create an advanced action to redirect to the site home page. + $edit = array( + 'actions_label' => $this->randomName(), + 'url' => '', + ); + $aid = $this->configureAdvancedAction('system_goto_action', $edit); + + // Set up to trigger this advanced action when new content is saved. + $info = array( + 'aid' => drupal_hash_base64($aid), + ); + $this->drupalPost('admin/structure/trigger/node', $info, t('Assign'), array(), array(), 'trigger-node-insert-assign-form'); + + // Use the node add form to save content. + $before = variable_get('trigger_test_nodes_inserted', array()); + $edit = array( + 'title' => $this->randomName(), + 'body[und][0][value]' => $this->randomName(), + ); + $this->drupalPost('node/add/page', $edit, t('Save')); + + // Verify that we are redirected to the home page. + $url = $this->getURL(); + $this->assertEqual($url, url('', array('absolute' => TRUE)), 'Node save was redirected to home page'); + + // Verify that hook_node_insert() was invoked. + $after = variable_get('trigger_test_nodes_inserted', array()); + $this->assertTrue(count($after) > count($before), 'hook_node_insert() was invoked'); + } + /** * Returns some info about each of the content actions. * @@ -606,15 +650,36 @@ class TriggerOtherTestCase extends TriggerWebTestCase { $edit = array('aid' => drupal_hash_base64($aid)); $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-login-assign-form'); + // Assign a configurable action 'Redirect to URL' to the user_login trigger. + $action_url_edit = array( + 'actions_label' => $this->randomName(16), + 'url' => 'contact', + ); + $aid_url = $this->configureAdvancedAction('system_goto_action', $action_url_edit); + $edit = array('aid' => drupal_hash_base64($aid_url)); + $this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-login-assign-form'); + // Verify that the action has been assigned to the correct hook. $actions = trigger_get_assigned_actions('user_login'); - $this->assertEqual(1, count($actions), 'One Action assigned to the hook'); + $this->assertEqual(2, count($actions), 'Two Actions assigned to the hook'); $this->assertEqual($actions[$aid]['label'], $action_edit['actions_label'], 'Correct action label found.'); + $this->assertEqual($actions[$aid_url]['label'], $action_url_edit['actions_label'], t('Correct action label found.')); // User should get the configured message at login. - $contact_user = $this->drupalCreateUser(array('access site-wide contact form'));; + $contact_user = $this->drupalCreateUser(array('access site-wide contact form')); $this->drupalLogin($contact_user); + $this->drupalLogout(); + + // Trying to login from different page to be redirected. + $edit = array( + 'name' => $contact_user->name, + 'pass' => $contact_user->pass_raw, + ); + $this->drupalPost('filter/tips', $edit, t('Log in')); $this->assertText($action_edit['message']); + + // Verify that redirect happened. + $this->assertEqual(url('contact', array('absolute' => TRUE)), $this->url, t('Redirected successfully by the trigger.')); } /**