From af474609e3e80db9ba1d16b9ad2eae89775f51c8 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 20 Apr 2008 18:24:07 +0000 Subject: - Added a test framework to Drupal along with a first batch of tests for Drupal core! This is an important milestone for the project so enable the module and check it out ... :) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran Lal, Moshe Weitzman, and the many other people that helped with testing over the past years and that drove this home. It all works but it is still rough around the edges (i.e. documentation is still being written, the coding style is not 100% yet, a number of tests still fail) but we spent the entire weekend working on it in Paris and made a ton of progress. The best way to help and to get up to speed, is to start writing and contributing some tests ... as well as fixing some of the failures. For those willing to help with improving the test framework, here are some next steps and issues to resolve: - How to best approach unit tests and mock functions? - How to test drupal_mail() and drupal_http_request()? - How to improve the admin UI so we have a nice progress bar? - How best to do code coverage? - See http://g.d.o/node/10099 for more ... --- modules/trigger/trigger.test | 114 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 modules/trigger/trigger.test (limited to 'modules/trigger') diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test new file mode 100644 index 000000000..1a6b687bc --- /dev/null +++ b/modules/trigger/trigger.test @@ -0,0 +1,114 @@ + t('Trigger content (node) actions'), + 'description' => t('Perform various tests with content actions.') , + 'group' => t('Trigger'), + ); + } + + function setUp() { + parent::setUp('trigger'); + } + + /** + * 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'); + + foreach ($content_actions as $action) { + $hash = md5($action); + $info = $this->actionInfo($action); + + // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire. + $test_user = $this->drupalCreateUser(array('administer actions')); + $this->drupalLogin($test_user); + $edit = array('aid' => $hash); + $this->drupalPost('admin/build/trigger/node', $edit, t('Assign')); + // Create an unpublished node. + $web_user = $this->drupalCreateUser(array('create page content', 'access content', 'administer nodes')); + $this->drupalLogin($web_user); + $edit = array(); + $edit['title'] = '!SimpleTest test node! ' . $this->randomName(10); + $edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32); + $edit[$info['property']] = !$info['expected']; + $this->drupalPost('node/add/page', $edit, t('Save')); + // Make sure the text we want appears. + $this->assertRaw(t('!post %title has been created.', array ('!post' => 'Page', '%title' => $edit['title'])), t('Make sure the page has actually been created')); + // Action should have been fired. + $loaded_node = node_load(array('title' => $edit['title']), NULL, TRUE); + $this->assertTrue($loaded_node->$info['property'] == $info['expected'], t('Make sure the @action action fired.', array('@action' => $info['name']))); + // Leave action assigned for next test + + // Test 2: There should be an error when the action is assigned to the trigger twice. + $test_user = $this->drupalCreateUser(array('administer actions')); + $this->drupalLogin($test_user); + $edit = array('aid' => $hash); + $this->drupalPost('admin/build/trigger/node', $edit, t('Assign')); + $edit = array('aid' => $hash); + $this->drupalPost('admin/build/trigger/node', $edit, t('Assign')); + $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.')); + + // Test 3: The action should be able to be unassigned from a trigger. + $this->drupalPost('admin/build/trigger/unassign/nodeapi/presave/'. $hash, array(), t('Unassign')); + $this->assertRaw(t('Action %action has been unassigned.', array('%action' => 'Publish post')), t('Check to make sure the @action action can be unassigned from the trigger.', array('@action' => $info['name']))); + $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.')); + } + } + + /** + * Helper function for testActionsContent(): returns some info about each of the content actions. + * + * @param $action + * The name of the action to return info about. + * @return + * An associative array of info about the action. + */ + function actionInfo($action) { + $info = array( + 'node_publish_action' => array( + 'property' => 'status', + 'expected' => 1, + 'name' => t('publish post'), + ), + 'node_unpublish_action' => array( + 'property' => 'status', + 'expected' => 0, + 'name' => t('unpublish post'), + ), + 'node_make_sticky_action' => array( + 'property' => 'sticky', + 'expected' => 1, + 'name' => t('make post sticky'), + ), + 'node_make_unsticky_action' => array( + 'property' => 'sticky', + 'expected' => 0, + 'name' => t('make post unsticky'), + ), + 'node_promote_action' => array( + 'property' => 'promote', + 'expected' => 1, + 'name' => t('promote post to front page'), + ), + 'node_unpromote_action' => array( + 'property' => 'promote', + 'expected' => 0, + 'name' => t('remove post from front page'), + ), + ); + return $info[$action]; + } +} \ No newline at end of file -- cgit v1.2.3