Spike PHPCoverage Details: trigger.test

Line #FrequencySource Line
1 <?php
2 // $Id: trigger.test,v 1.9 2008/04/01 23:33:54 boombatower Exp $
3 
4 class ActionsContentTestCase extends  DrupalTestCase {
5   var $_cleanup_roles = array();
6   var $_cleanup_users = array();
7 
8   /**
9    * Implementation of getInfo() for information
10    */
11   function getInfo() {
12     return array(
131      'name' => t('Actions content'),
14       'description' => t('Perform various tests with content actions.') ,
15       'group' => 'Actions',
16     );
17   }
18 
19   /**
20    * Various tests, all in one function to assure they happen in the right order.
21    */
22   function testActionsContent() {
23     global $user;
24 
25     $this->drupalModuleEnable('trigger');
26 
27     $content_actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action');
28 
29     $hash = md5('node_publish_action');
30 
31     $not_clean = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')"));
32     $this->assertFalse($not_clean, t('Actions were already assigned to the trigger. Unassign all content triggers before attempting to run again.'));
33 
34     if ($not_clean) {
35       return;
36     }
37 
38     // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire. (Wow, those metaphors work out nicely).
39 
40     $test_user = $this->drupalCreateUser(array('administer actions', 'create page content'));
41     $this->drupalLogin($test_user);
42 
43     // Set action id to "publish post".
44     $edit = array('aid' => $hash);
45     $this->drupalPost('admin/build/trigger/node', $edit, t('Assign'));
46 
47     // Create an unpublished node.
48     $node = $this->drupalCreateNode(array('status' => 0));
49     // Node should be published automatically.
50     $loaded_node = node_load($node->nid);
51     $this->assertTrue($loaded_node->status == 1, t('Check to make sure the node is automatically published'));
52 
53     // Leave action assigned for next test
54 
55     // Test 2: There should be an error when the action is assigned to the trigger twice.
56 
57     $edit = array('aid' => $hash);
58     $this->drupalPost('admin/build/trigger/node', $edit, t('Assign'));
59     $this->assertRaw(t('The action you chose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.'));
60 
61     // Test 3: The action should be able to be unassigned from a trigger.
62 
63     // This effectively cleans up as well.
64     $this->drupalPost('admin/build/trigger/unassign/nodeapi/presave/'. $hash, array(), t('Unassign'));
65     $this->assertRaw(t('Action %action has been unassigned.', array('%action' => 'Publish post')), t('Check to make sure action can be unassigned from trigger.'));
66 
67     $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')"));
68     $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.'));
69   }
70 }