diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-04-28 12:36:26 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-04-28 12:36:26 +0000 |
commit | 19a45ce5446f1ebc87f98d294a3acffdc8b54478 (patch) | |
tree | 29182a43073943cc35a35aa4d68964a44e7eaa08 /modules/simpletest | |
parent | 748c31038d0de19185c7c176731d7eed958b7c9d (diff) | |
download | brdo-19a45ce5446f1ebc87f98d294a3acffdc8b54478.tar.gz brdo-19a45ce5446f1ebc87f98d294a3acffdc8b54478.tar.bz2 |
- Patch #765860 by effulgentsia, dww, dereine, mikey_p, sun: make drupal_alter() support multiple alter hooks executed by module weight.
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/tests/form.test | 34 | ||||
-rw-r--r-- | modules/simpletest/tests/form_test.module | 47 |
2 files changed, 81 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index 7ecfde9ac..40c7490da 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -210,6 +210,40 @@ class FormsTestCase extends DrupalWebTestCase { } /** + * Test form alter hooks. + */ +class FormAlterTestCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Form alter hooks', + 'description' => 'Tests hook_form_alter() and hook_form_FORM_ID_alter().', + 'group' => 'Form API', + ); + } + + function setUp() { + parent::setUp('form_test'); + } + + /** + * Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter(). + */ + function testExecutionOrder() { + $this->drupalGet('form-test/alter'); + // Ensure that the order is first by module, then for a given module, the + // id-specific one after the generic one. + $expected = array( + 'block_form_form_test_alter_form_alter() executed.', + 'form_test_form_alter() executed.', + 'form_test_form_form_test_alter_form_alter() executed.', + 'system_form_form_test_alter_form_alter() executed.', + ); + $content = preg_replace('/\s+/', ' ', filter_xss($this->content, array())); + $this->assert(strpos($content, implode(' ', $expected)) !== FALSE, t('Form alter hooks executed in the expected order.')); + } +} + +/** * Test form validation handlers. */ class FormValidationTestCase extends DrupalWebTestCase { diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index e035eb721..a8a22abfa 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -10,6 +10,13 @@ * Implements hook_menu(). */ function form_test_menu() { + $items['form-test/alter'] = array( + 'title' => 'Form altering test', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_alter_form'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); $items['form-test/validate'] = array( 'title' => 'Form validation handlers test', 'page callback' => 'drupal_get_form', @@ -142,6 +149,46 @@ function form_test_menu() { } /** + * Form builder for testing hook_form_alter() and hook_form_FORM_ID_alter(). + */ +function form_test_alter_form($form, &$form_state) { + // Elements can be added as needed for future testing needs, but for now, + // we're only testing alter hooks that do not require any elements added by + // this function. + return $form; +} + +/** + * Implements hook_form_FORM_ID_alter() on behalf of block.module. + */ +function block_form_form_test_alter_form_alter(&$form, &$form_state) { + drupal_set_message('block_form_form_test_alter_form_alter() executed.'); +} + +/** + * Implements hook_form_alter(). + */ +function form_test_form_alter(&$form, &$form_state, $form_id) { + if ($form_id == 'form_test_alter_form') { + drupal_set_message('form_test_form_alter() executed.'); + } +} + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function form_test_form_form_test_alter_form_alter(&$form, &$form_state) { + drupal_set_message('form_test_form_form_test_alter_form_alter() executed.'); +} + +/** + * Implements hook_form_FORM_ID_alter() on behalf of system.module. + */ +function system_form_form_test_alter_form_alter(&$form, &$form_state) { + drupal_set_message('system_form_form_test_alter_form_alter() executed.'); +} + +/** * Form builder for testing drupal_validate_form(). * * Serves for testing form processing and alterations by form validation |