diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index 1c869c2..aeb1211 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -76,14 +76,22 @@ function trigger_menu() { } /** - * Menu access callback for admin/structure/trigger/unassign. + * Access callback: Determines if triggers can be unassigned. + * + * @return bool + * TRUE if there are triggers that the user can unassign, FALSE otherwise. + * + * @see trigger_menu() */ function trigger_menu_unassign_access() { if (!user_access('administer actions')) { return FALSE; } - $actions = actions_get_all_actions(); - return !empty($actions); + $count = db_select('trigger_assignments') + ->countQuery() + ->execute() + ->fetchField(); + return $count > 0; } /** diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index 138de62..829e189 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -740,3 +740,32 @@ class TriggerOrphanedActionsTestCase extends DrupalWebTestCase { $this->assertRaw(t('!post %title has been updated.', array('!post' => 'Basic page', '%title' => $edit["title"])), t('Make sure the Basic page can be updated with the missing trigger function.')); } } + +/** + * Tests the unassigning of triggers. + */ +class TriggerUnassignTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Trigger unassigning', + 'description' => 'Tests the unassigning of triggers.', + 'group' => 'Trigger', + ); + } + + function setUp() { + parent::setUp('trigger', 'trigger_test'); + $web_user = $this->drupalCreateUser(array('administer actions')); + $this->drupalLogin($web_user); + } + + /** + * Tests an attempt to unassign triggers when none are assigned. + */ + function testUnassignAccessDenied() { + $this->drupalGet('admin/structure/trigger/unassign'); + $this->assertResponse(403, 'If there are no actions available, return access denied.'); + } + +}