Index: drupal_test_case.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/drupal_test_case.php,v retrieving revision 1.34 diff -u -r1.34 drupal_test_case.php --- drupal_test_case.php 23 Sep 2007 08:35:23 -0000 1.34 +++ drupal_test_case.php 27 Dec 2007 10:00:34 -0000 @@ -13,6 +13,7 @@ var $_cleanupVariables = array(); var $_cleanupUsers = array(); var $_cleanupRoles = array(); + var $_cleanupNodes = array(); function DrupalTestCase($label = NULL) { @@ -24,6 +25,61 @@ } $this->WebTestCase($label); } + + /** + * Creates a node based on default settings. + * + * @param settings An array of settings to change from the defaults, in the form of 'body' => 'Hello, world!' + * @param user A user to use as the author for the node. + * @param node A node object if applicable to work with. + */ + function drupalCreateNode($settings = array(), $account = NULL, $mod_node = NULL) { + $modifying = FALSE; + if (is_object($mod_node)) { + $modifying = TRUE; + $mod_node = (array) $mod_node; + } + else { + $mod_node = array(); + } + if (!isset($account)) { + global $user; + $account = $user; + } + + // Populate defaults array + $defaults = array( + 'body' => $this->randomName(32), + 'title' => $this->randomName(8), + 'comment' => 2, + 'changed' => time(), + 'format' => 1, + 'moderate' => 0, + 'name' => $account->name, + 'uid' => $account->uid, + 'promote' => 0, + 'revision' => 1, + 'log' => '', + 'status' => 1, + 'sticky' => 0, + 'type' => 'page', + 'revisions' => NULL, + 'taxonomy' => NULL, + ); + $defaults['teaser'] = $defaults['body']; + // If we already have a node, we use the original node's created time, and this + $defaults['created'] = $modifying ? $mod_node['created'] : $deafults['changed']; + $defaults['date'] = format_date($defaults['created'], 'custom', 'Y-m-d H:i:s O'); + + $node = ($settings + $mod_node + $defaults); + + $node = (object)$node; + + node_save($node); + $this->_cleanupNodes[] = $node->nid; + return $node; + } + /** * @abstract Checks to see if we need to send @@ -384,6 +440,10 @@ $this->assertTrue(TRUE, "$type: $msg"); } } + + foreach ($this->_cleanupNodes as $nid) { + node_delete($node); + } parent::tearDown(); } Index: tests/content_actions.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/tests/content_actions.test,v retrieving revision 1.1 diff -u -r1.1 content_actions.test --- tests/content_actions.test 27 Dec 2007 07:37:50 -0000 1.1 +++ tests/content_actions.test 27 Dec 2007 09:30:51 -0000 @@ -1,88 +1,69 @@ - t('Actions content'), 'desc' => t('Perform various tests with content actions.') , 'group' => 'Actions'); - } - - /** - * Setup function - */ - function setup() { - } - - /** - * Various tests, all in one function to assure they happen in the right order. - */ - function testActionsContent() { - global $user; - - $this->drupalModuleEnable('trigger'); - - $content_actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action'); - - $hash = md5('node_publish_action'); - - $not_clean = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); - - if ($not_clean) { - $this->assertFalse($not_clean, t('Actions were already assigned to the trigger. Unassign all content triggers before attempting to run again.')); - return; - } - else { - $this->assertFalse($not_clean, t('Actions were already not assigned to the trigger.')); - } - - // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire. (Wow, those metaphors work out nicely). - - $test_user = $this->drupalCreateUserRolePerm(array('administer actions', 'create page content')); - $this->drupalLoginUser($test_user); - - // Set action id to "publish post". - $edit = array('aid' => $hash); - $this->drupalPostRequest('admin/build/trigger/node', $edit, 'Assign'); - - // Create an unpublished node. - $node->body = $this->randomName(32); - $node->title = $this->randomName(8); - $node->teaser = $node->body; - $node->comment = 2; - $node->format = 1; - $node->name = $test_user->name; - $node->uid = $test_user->uid; - $node->promote = 0; - $node->revision = 0; - $node->status = 0; - $node->sticky = 0; - $node->type = 'page'; - $node->revisions = NULL; - $node->taxonomy = NULL; - node_save($node); - // Node should be published automatically. - $loaded_node = node_load($node->nid); - $this->assertTrue($loaded_node->status == 1, t('Check to make sure the node is automatically published')); - - // Leave action assigned for next test - - // Test 2: There should be an error when the action is assigned to the trigger twice. - - $edit = array('aid' => $hash); - $this->drupalPostRequest('admin/build/trigger/node', $edit, 'Assign'); - $this->assertWantedRaw(t('The action you choose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.')); - - // Test 3: The action should be able to be unassigned from a trigger. - - // This effectively cleans up as well. - $this->drupalPostRequest('admin/build/trigger/unassign/nodeapi/presave/'. $hash, array(), 'Unassign'); - $this->assertWantedRaw(t('Action %action has been unassigned.', array('%action' => 'Publish post')), t('Check to make sure action can be unassigned from trigger.')); - - $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); - $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.')); - } -} + t('Actions content'), 'desc' => t('Perform various tests with content actions.') , 'group' => 'Actions'); + } + + /** + * Setup function + */ + function setup() { + } + + /** + * Various tests, all in one function to assure they happen in the right order. + */ + function testActionsContent() { + global $user; + + $content_actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action'); + + $hash = md5('node_publish_action'); + + $not_clean = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); + $this->assertFalse($not_clean, t('Actions were already assigned to the trigger. Clean up triggers systems before attempting to run again.')); + if ($not_clean) { + return; + } + + // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire. (Wow, those metaphors work out nicely). + + $test_user = $this->drupalCreateUserRolePerm(array('administer actions', 'create page content')); + $this->drupalLoginUser($test_user); + + // Set action id to "publish post". + $edit = array('aid' => $hash); + $this->drupalPostRequest('admin/build/trigger/node', $edit, 'Assign'); + + // Create an unpublished node. + $node = $this->drupalCreateNode(array('status' => 0)); + // Node should be published automatically. + $loaded_node = node_load($node->nid); + $this->assertTrue($node->status == 1, t('Check to make sure the node is automatically published')); + + // Leave action assigned for next test + + // Test 2: There should be an error when the action is assigned to the trigger twice. + + $edit = array('aid' => $hash); + $this->drupalPostRequest('admin/build/trigger/node', $edit, 'Assign'); + $this->assertWantedRaw(t('The action you choose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.')); + + // Test 3: The action should be able to be unassigned from a trigger. + + // This effectively cleans up as well. + $this->drupalPostRequest('admin/build/trigger/unassign/nodeapi/presave/'. $hash, array(), 'Unassign'); + $this->assertWantedRaw(t('Action %action has been unassigned.', array('%action' => 'Publish post')), t('Check to make sure action can be unassigned from trigger.')); + + $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); + $this->assertFalse($assigned, t('Unassign did not work properly.')); + } +} +?> \ No newline at end of file Index: tests/node_revisions.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/tests/node_revisions.test,v retrieving revision 1.1 diff -u -r1.1 node_revisions.test --- tests/node_revisions.test 25 Dec 2007 11:52:12 -0000 1.1 +++ tests/node_revisions.test 27 Dec 2007 09:53:19 -0000 @@ -21,42 +21,27 @@ global $user; $returnarray = array(); - $node = new stdClass(); $numtimes = 3; // First, middle, last. for ($i = 0; $i < $numtimes; $i++) { - $node->body = $this->randomName(32 + $i); - $node->title = $this->randomName(8 + $i); - $node->teaser = $node->body; - $node->comment = '2'; - $node->created = time(); - $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); - $node->format = '1'; - $node->moderate = 0; - $node->name = $user->name; - $node->uid = $user->uid; - $node->promote = 0; - $node->revision = 1; - $node->log = ''; - if ($i == 1 && $log) { - $logmessage = $this->randomName(32); - $node->log = $logmessage; + $settings = array('revision' => 1); + if ($log && $i == 1) { + $logmessage = $this->randomName(32); + $settings['log'] = $logmessage; $returnarray['log'] = $logmessage; } - $node->status = '1'; - $node->sticky = 0; - $node->type = 'page'; - $node->revisions = NULL; - $node->changed = $node->created; - $node->taxonomy = NULL; - node_save($node); - // Avoid confusion on the revisions overview page which is sorted by r.timestamp. - sleep(1); if ($i == 1) { - $text = $node->body; - $vid = $node->vid; - $returnarray['vid'] = $vid; - $returnarray['text'] = $text; + $settings['body'] = $this->randomName(32); + $returnarray['text'] = $settings['body']; + $settings['vid'] = $node->vid; + $returnarray['vid'] = $node->vid; + } + $mod_node = NULL; + if ($i != 0) { + $mod_node = $node; } + $node = $this->drupalCreateNode($settings, NULL, $mod_node); + // Avoid confusion on the revisions overview page which is sorted by r.timestamp. + sleep(1); } $returnarray['node'] = $node; return $returnarray; Index: tests/page_view.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/tests/page_view.test,v retrieving revision 1.11 diff -u -r1.11 page_view.test --- tests/page_view.test 27 Dec 2007 08:49:25 -0000 1.11 +++ tests/page_view.test 27 Dec 2007 10:06:37 -0000 @@ -18,26 +18,7 @@ function testPageView() { /* Prepare a node to view */ global $user; - $node = new stdClass(); - $node->body = $this->randomName(32); - $node->title = $this->randomName(8); - $node->teaser = $node->body; - $node->comment = '2'; - $node->created = time(); - $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); - $node->format = '1'; - $node->moderate = 0; - $node->name = $user->name; - $node->uid = $user->uid; - $node->promote = 0; - $node->revision = 0; - $node->status = '1'; - $node->sticky = 0; - $node->type = 'page'; - $node->revisions = NULL; - $node->changed = $node->created; - $node->taxonomy = NULL; - node_save($node); + $node = $this->drupalCreateNode(); $this->assertNotNull(node_load($node->nid), 'Node created'); /* Tries to edit with anonymous user */