- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
<?php
// $Id$
2010-03-07 18:06:06 +00:00
/**
* Class with common helper methods.
*/
class TriggerWebTestCase extends DrupalWebTestCase {
/**
* Configure an advanced action.
*
* @param $action
* The name of the action callback. For example: 'user_block_user_action'
* @param $edit
* The $edit array for the form to be used to configure.
* Example members would be 'actions_label' (always), 'message', etc.
* @return
* the aid (action id) of the configured action, or FALSE if none.
*/
protected function configureAdvancedAction($action, $edit) {
// Create an advanced action.
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action);
2010-03-07 18:06:06 +00:00
$this->drupalPost("admin/config/system/actions/configure/$hash", $edit, t('Save'));
$this->assertText(t('The action has been successfully saved.'));
// Now we have to find out the action ID of what we created.
return db_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(':callback' => $action, ':label' => $edit['actions_label']))->fetchField();
}
}
/**
* Test node triggers.
*/
class TriggerContentTestCase extends TriggerWebTestCase {
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
var $_cleanup_roles = array();
var $_cleanup_users = array();
2009-03-31 01:49:55 +00:00
public static function getInfo() {
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Trigger content (node) actions',
2010-03-07 07:22:42 +00:00
'description' => 'Perform various tests with content actions.',
2009-07-13 21:51:42 +00:00
'group' => 'Trigger',
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
);
}
function setUp() {
2010-03-26 20:44:10 +00:00
parent::setUp('trigger', 'trigger_test');
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
}
/**
* 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');
2010-03-27 18:32:06 +00:00
$test_user = $this->drupalCreateUser(array('administer actions'));
$web_user = $this->drupalCreateUser(array('create page content', 'access content', 'administer nodes'));
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
foreach ($content_actions as $action) {
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action);
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$info = $this->actionInfo($action);
2010-03-07 07:22:42 +00:00
// Assign an action to a trigger, then pull the trigger, and make sure
// the actions fire.
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$this->drupalLogin($test_user);
$edit = array('aid' => $hash);
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-presave-assign-form');
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
// Create an unpublished node.
$this->drupalLogin($web_user);
$edit = array();
2009-12-02 19:26:23 +00:00
$langcode = LANGUAGE_NONE;
2010-01-09 21:54:01 +00:00
$edit["title"] = '!SimpleTest test node! ' . $this->randomName(10);
2009-08-22 00:58:55 +00:00
$edit["body[$langcode][0][value]"] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$edit[$info['property']] = !$info['expected'];
$this->drupalPost('node/add/page', $edit, t('Save'));
// Make sure the text we want appears.
2010-01-10 22:56:51 +00:00
$this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"])), t('Make sure the Basic page has actually been created'));
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
// Action should have been fired.
2010-02-09 12:29:39 +00:00
$loaded_node = $this->drupalGetNodeByTitle($edit["title"]);
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$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
2010-03-07 07:22:42 +00:00
// There should be an error when the action is assigned to the trigger
// twice.
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$this->drupalLogin($test_user);
2010-03-27 18:32:06 +00:00
// This action already assigned in this test.
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$edit = array('aid' => $hash);
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-presave-assign-form');
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$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.'));
2010-03-07 07:22:42 +00:00
// The action should be able to be unassigned from a trigger.
2009-09-19 11:07:37 +00:00
$this->drupalPost('admin/structure/trigger/unassign/node/node_presave/' . $hash, array(), t('Unassign'));
2008-06-02 17:39:12 +00:00
$this->assertRaw(t('Action %action has been unassigned.', array('%action' => ucfirst($info['name']))), t('Check to make sure the @action action can be unassigned from the trigger.', array('@action' => $info['name'])));
2009-07-28 19:18:08 +00:00
$assigned = db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchField();
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
$this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.'));
}
}
2010-03-26 20:44:10 +00:00
/**
* Test that node actions are fired for each node individually if acting on
* multiple nodes.
*/
function testActionContentMultiple() {
// Assign an action to the node save/update trigger.
$test_user = $this->drupalCreateUser(array('administer actions', 'administer nodes', 'create page content', 'access administration pages', 'access content overview'));
$this->drupalLogin($test_user);
for ($index = 0; $index < 3; $index++) {
$edit = array('title' => $this->randomName());
$this->drupalPost('node/add/page', $edit, t('Save'));
}
$action_id = 'trigger_test_generic_any_action';
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action_id);
2010-03-26 20:44:10 +00:00
$edit = array('aid' => $hash);
2010-04-10 10:49:15 +00:00
$this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-update-assign-form');
2010-03-26 20:44:10 +00:00
$edit = array(
'operation' => 'unpublish',
'nodes[1]' => TRUE,
'nodes[2]' => TRUE,
);
$this->drupalPost('admin/content', $edit, t('Update'));
2010-04-10 10:49:15 +00:00
$count = variable_get('trigger_test_generic_any_action', 0);
$this->assertTrue($count == 2, t('Action was triggered 2 times. Actual: %count', array('%count' => $count)));
2010-03-26 20:44:10 +00:00
}
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
/**
* 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,
2009-09-19 11:07:37 +00:00
'name' => t('publish content'),
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
),
'node_unpublish_action' => array(
'property' => 'status',
'expected' => 0,
2009-09-19 11:07:37 +00:00
'name' => t('unpublish content'),
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
),
'node_make_sticky_action' => array(
'property' => 'sticky',
'expected' => 1,
2009-09-19 11:07:37 +00:00
'name' => t('make content sticky'),
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
),
'node_make_unsticky_action' => array(
'property' => 'sticky',
'expected' => 0,
2009-09-19 11:07:37 +00:00
'name' => t('make content unsticky'),
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
),
'node_promote_action' => array(
'property' => 'promote',
'expected' => 1,
2009-09-19 11:07:37 +00:00
'name' => t('promote content to front page'),
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
),
'node_unpromote_action' => array(
'property' => 'promote',
'expected' => 0,
2009-09-19 11:07:37 +00:00
'name' => t('remove content from front page'),
- 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 ... :)
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 ...
2008-04-20 18:24:07 +00:00
),
);
return $info[$action];
}
2008-12-05 22:18:46 +00:00
}
2009-05-27 16:29:05 +00:00
/**
* Test cron trigger.
*/
2010-03-07 18:06:06 +00:00
class TriggerCronTestCase extends TriggerWebTestCase {
2009-05-27 18:07:28 +00:00
public static function getInfo() {
2009-05-27 16:29:05 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Trigger cron (system) actions',
2010-03-07 07:22:42 +00:00
'description' => 'Perform various tests with cron trigger.',
2009-07-13 21:51:42 +00:00
'group' => 'Trigger',
2009-05-27 16:29:05 +00:00
);
}
function setUp() {
parent::setUp('trigger', 'trigger_test');
}
/**
2009-05-31 03:12:19 +00:00
* Test assigning multiple actions to the cron trigger.
*
* This test ensures that both simple and multiple complex actions
* succeed properly. This is done in the cron trigger test because
* cron allows passing multiple actions in at once.
2009-05-27 16:29:05 +00:00
*/
function testActionsCron() {
2009-05-31 03:12:19 +00:00
// Create an administrative user.
2009-05-27 16:29:05 +00:00
$test_user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($test_user);
2009-09-19 11:07:37 +00:00
2009-05-31 03:12:19 +00:00
// Assign a non-configurable action to the cron run trigger.
2010-05-01 08:12:23 +00:00
$edit = array('aid' => drupal_hash_base64('trigger_test_system_cron_action'));
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'), array(), array(), 'trigger-cron-assign-form');
2009-09-19 11:07:37 +00:00
2009-05-31 03:12:19 +00:00
// Assign a configurable action to the cron trigger.
2009-09-19 11:07:37 +00:00
$action_label = $this->randomName();
2009-05-31 03:12:19 +00:00
$edit = array(
2009-09-19 11:07:37 +00:00
'actions_label' => $action_label,
'subject' => $action_label,
2009-05-31 03:12:19 +00:00
);
2010-03-07 18:06:06 +00:00
$aid = $this->configureAdvancedAction('trigger_test_system_cron_conf_action', $edit);
2009-10-18 06:56:24 +00:00
// $aid is likely 3 but if we add more uses for the sequences table in
// core it might break, so it is easier to get the value from the database.
2010-05-01 08:12:23 +00:00
$edit = array('aid' => drupal_hash_base64($aid));
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'), array(), array(), 'trigger-cron-assign-form');
2009-09-19 11:07:37 +00:00
2009-05-31 03:12:19 +00:00
// Add a second configurable action to the cron trigger.
2009-09-19 11:07:37 +00:00
$action_label = $this->randomName();
2009-05-31 03:12:19 +00:00
$edit = array(
2009-09-19 11:07:37 +00:00
'actions_label' => $action_label,
'subject' => $action_label,
2009-05-31 03:12:19 +00:00
);
2010-03-07 18:06:06 +00:00
$aid = $this->configureAdvancedAction('trigger_test_system_cron_conf_action', $edit);
2010-05-01 08:12:23 +00:00
$edit = array('aid' => drupal_hash_base64($aid));
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/system', $edit, t('Assign'), array(), array(), 'trigger-cron-assign-form');
2009-09-19 11:07:37 +00:00
2009-05-27 16:29:05 +00:00
// Force a cron run.
2009-10-13 05:37:46 +00:00
$this->cronRun();
2009-09-19 11:07:37 +00:00
2009-05-31 03:12:19 +00:00
// Make sure the non-configurable action has fired.
2009-05-27 16:29:05 +00:00
$action_run = variable_get('trigger_test_system_cron_action', FALSE);
$this->assertTrue($action_run, t('Check that the cron run triggered the test action.'));
2009-09-19 11:07:37 +00:00
2009-05-31 03:12:19 +00:00
// Make sure that both configurable actions have fired.
$action_run = variable_get('trigger_test_system_cron_conf_action', 0) == 2;
$this->assertTrue($action_run, t('Check that the cron run triggered both complex actions.'));
2009-05-27 16:29:05 +00:00
}
}
2009-09-19 11:07:37 +00:00
/**
* Test other triggers.
*/
2010-03-07 18:06:06 +00:00
class TriggerOtherTestCase extends TriggerWebTestCase {
2009-09-19 11:07:37 +00:00
var $_cleanup_roles = array();
var $_cleanup_users = array();
public static function getInfo() {
return array(
'name' => 'Trigger other actions',
2010-03-07 07:22:42 +00:00
'description' => 'Test triggering of user, comment, taxonomy actions.',
2009-09-19 11:07:37 +00:00
'group' => 'Trigger',
);
}
function setUp() {
2010-03-07 18:06:06 +00:00
parent::setUp('trigger', 'trigger_test', 'contact');
2009-09-19 11:07:37 +00:00
}
/**
2010-03-07 18:06:06 +00:00
* Test triggering on user create and user login.
2009-09-19 11:07:37 +00:00
*/
function testActionsUser() {
// Assign an action to the create user trigger.
$test_user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($test_user);
$action_id = 'trigger_test_generic_action';
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action_id);
2009-09-19 11:07:37 +00:00
$edit = array('aid' => $hash);
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-insert-assign-form');
2009-09-19 11:07:37 +00:00
// Set action variable to FALSE.
variable_set( $action_id, FALSE );
// Create an unblocked user
$web_user = $this->drupalCreateUser(array('administer users'));
$this->drupalLogin($web_user);
$name = $this->randomName();
$pass = user_password();
$edit = array();
$edit['name'] = $name;
$edit['mail'] = $name . '@example.com';
$edit['pass[pass1]'] = $pass;
$edit['pass[pass2]'] = $pass;
$edit['status'] = 1;
$this->drupalPost('admin/people/create', $edit, t('Create new account'));
// Verify that the action variable has been set.
$this->assertTrue(variable_get($action_id, FALSE), t('Check that creating a user triggered the test action.'));
// Reset the action variable.
2010-03-07 18:06:06 +00:00
variable_set($action_id, FALSE);
$this->drupalLogin($test_user);
// Assign a configurable action 'System message' to the user_login trigger.
$action_edit = array(
'actions_label' => $this->randomName(16),
'message' => t("You have logged in:") . $this->randomName(16),
);
// Configure an advanced action that we can assign.
$aid = $this->configureAdvancedAction('system_message_action', $action_edit);
2010-05-01 08:12:23 +00:00
$edit = array('aid' => drupal_hash_base64($aid));
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), 'trigger-user-login-assign-form');
2010-03-07 18:06:06 +00:00
// Verify that the action has been assigned to the correct hook.
$actions = trigger_get_assigned_actions('user_login');
$this->assertEqual(1, count($actions), t('One Action assigned to the hook'));
$this->assertEqual($actions[$aid]['label'], $action_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'));;
$this->drupalLogin($contact_user);
$this->assertText($action_edit['message']);
2009-09-19 11:07:37 +00:00
}
/**
* Test triggering on comment save.
*/
function testActionsComment() {
// Assign an action to the comment save trigger.
$test_user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($test_user);
$action_id = 'trigger_test_generic_action';
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action_id);
2009-09-19 11:07:37 +00:00
$edit = array('aid' => $hash);
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/comment', $edit, t('Assign'), array(), array(), 'trigger-comment-insert-assign-form');
2009-09-19 11:07:37 +00:00
// Set action variable to FALSE.
2010-03-07 18:06:06 +00:00
variable_set($action_id, FALSE);
2009-09-19 11:07:37 +00:00
// Create a node and add a comment to it.
$web_user = $this->drupalCreateUser(array('create article content', 'access content', 'post comments without approval', 'post comments'));
$this->drupalLogin($web_user);
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$edit = array();
$edit['subject'] = $this->randomName(10);
2010-01-07 05:23:52 +00:00
$edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName(10) . ' ' . $this->randomName(10);
2009-09-19 11:07:37 +00:00
$this->drupalGet('comment/reply/' . $node->nid);
$this->drupalPost(NULL, $edit, t('Save'));
// Verify that the action variable has been set.
$this->assertTrue(variable_get($action_id, FALSE), t('Check that creating a comment triggered the action.'));
}
/**
* Test triggering on taxonomy new term.
*/
function testActionsTaxonomy() {
// Assign an action to the taxonomy term save trigger.
$test_user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($test_user);
$action_id = 'trigger_test_generic_action';
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action_id);
2009-09-19 11:07:37 +00:00
$edit = array('aid' => $hash);
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/taxonomy', $edit, t('Assign'), array(), array(), 'trigger-taxonomy-term-insert-assign-form');
2009-09-19 11:07:37 +00:00
// Set action variable to FALSE.
2010-03-07 18:06:06 +00:00
variable_set($action_id, FALSE);
2009-09-19 11:07:37 +00:00
// Create a taxonomy vocabulary and add a term to it.
// Create a vocabulary.
$vocabulary = new stdClass();
$vocabulary->name = $this->randomName();
$vocabulary->description = $this->randomName();
$vocabulary->machine_name = drupal_strtolower($this->randomName());
$vocabulary->help = '';
$vocabulary->nodes = array('article' => 'article');
$vocabulary->weight = mt_rand(0, 10);
taxonomy_vocabulary_save($vocabulary);
$term = new stdClass();
$term->name = $this->randomName();
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
// Verify that the action variable has been set.
$this->assertTrue(variable_get($action_id, FALSE), t('Check that creating a taxonomy term triggered the action.'));
}
2010-03-07 18:06:06 +00:00
2009-09-19 11:07:37 +00:00
}
2010-03-07 07:22:42 +00:00
/**
* Test that orphaned actions are properly handled.
*/
class TriggerOrphanedActionsTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Trigger orphaned actions',
'description' => 'Test triggering an action that has since been removed.',
'group' => 'Trigger',
);
}
function setUp() {
parent::setUp('trigger', 'trigger_test');
}
/**
* Test logic around orphaned actions.
*/
function testActionsOrphaned() {
$action = 'trigger_test_generic_any_action';
2010-05-01 08:12:23 +00:00
$hash = drupal_hash_base64($action);
2010-03-07 07:22:42 +00:00
// Assign an action from a disable-able module 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);
2010-03-27 18:32:06 +00:00
$this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'), array(), array(), 'trigger-node-presave-assign-form');
2010-03-07 07:22:42 +00:00
// Create an unpublished node.
$web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'access content', 'administer nodes'));
$this->drupalLogin($web_user);
$edit = array();
$langcode = LANGUAGE_NONE;
$edit["title"] = '!SimpleTest test node! ' . $this->randomName(10);
$edit["body[$langcode][0][value]"] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
$this->drupalPost('node/add/page', $edit, t('Save'));
$this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"])), t('Make sure the Basic page has actually been created'));
// Action should have been fired.
$this->assertTrue(variable_get('trigger_test_generic_any_action', FALSE), t('Trigger test action successfully fired.'));
// Disable the module that provides the action and make sure the trigger
// doesn't white screen.
module_disable(array('trigger_test'));
$loaded_node = $this->drupalGetNodeByTitle($edit["title"]);
$edit["body[$langcode][0][value]"] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
$this->drupalPost("node/$loaded_node->nid/edit", $edit, t('Save'));
// If the node body was updated successfully we have dealt with the
// unavailable action.
$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.'));
}
}