From ecc7ce08754ca321110c25ca29567f9726813637 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 17 Jul 2010 18:52:39 +0000 Subject: - Patch #561226 by fago, effulgentsia, sun, YesCT, marcingy: orms (elements) need to able to specify include files to be loaded for building. --- modules/simpletest/tests/form.test | 34 ++++++++++++++++++++++++ modules/simpletest/tests/form_test.file.inc | 40 +++++++++++++++++++++++++++++ modules/simpletest/tests/form_test.info | 1 + modules/simpletest/tests/form_test.module | 34 ++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 modules/simpletest/tests/form_test.file.inc (limited to 'modules/simpletest/tests') diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index 29fb5eb53..d139f4dcb 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -1175,3 +1175,37 @@ class FormsArbitraryRebuildTestCase extends DrupalWebTestCase { $this->assertFieldByName('mail', 'bar@example.com', 'Entered mail address has been kept.'); } } + +/** + * Tests form API file inclusion. + */ +class FormsFileInclusionTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Form API file inclusion', + 'description' => 'Tests form API file inclusion.', + 'group' => 'Form API', + ); + } + + function setUp() { + parent::setUp('form_test'); + } + + /** + * Tests loading an include specified in hook_menu(). + */ + function testLoadMenuInclude() { + $this->drupalPostAJAX('form-test/load-include-menu', array(), array('op' => t('Save')), 'system/ajax', array(), array(), 'form-test-load-include-menu'); + $this->assertText('Submit callback called.'); + } + + /** + * Tests loading a custom specified inlcude. + */ + function testLoadCustomInclude() { + $this->drupalPost('form-test/load-include-custom', array(), t('Save')); + $this->assertText('Submit callback called.'); + } +} diff --git a/modules/simpletest/tests/form_test.file.inc b/modules/simpletest/tests/form_test.file.inc new file mode 100644 index 000000000..96681eaa8 --- /dev/null +++ b/modules/simpletest/tests/form_test.file.inc @@ -0,0 +1,40 @@ + 'submit', + '#value' => t('Save'), + '#submit' => array('form_test_load_include_submit'), + '#ajax' => array( + 'callback' => 'form_test_load_include_menu_ajax', + ), + ); + return $form; +} + +/** + * Submit callback for the form API file inclusion test forms. + */ +function form_test_load_include_submit($form, $form_state) { + drupal_set_message('Submit callback called.'); +} + +/** + * Ajax callback for the file inclusion via menu test. We don't need to return + * anything as the messages are added automatically. + */ +function form_test_load_include_menu_ajax($form) { + return ''; +} diff --git a/modules/simpletest/tests/form_test.info b/modules/simpletest/tests/form_test.info index d138f15cc..b7030c339 100644 --- a/modules/simpletest/tests/form_test.info +++ b/modules/simpletest/tests/form_test.info @@ -5,4 +5,5 @@ package = Testing version = VERSION core = 7.x files[] = form_test.module +files[] = form_test.file.inc hidden = TRUE diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index cbc4c0ead..64360f93f 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -153,6 +153,23 @@ function form_test_menu() { ); } + $items['form-test/load-include-menu'] = array( + 'title' => 'FAPI test loading includes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_load_include_menu'), + 'access callback' => TRUE, + 'file' => 'form_test.file.inc', + 'type' => MENU_CALLBACK, + ); + + $items['form-test/load-include-custom'] = array( + 'title' => 'FAPI test loading includes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_load_include_custom'), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -1182,3 +1199,20 @@ function form_test_two_instances() { $return['node_form_2'] = drupal_get_form('page_node_form', $node2); return $return; } + +/** + * Menu callback for testing custom form includes. + */ +function form_test_load_include_custom($form, &$form_state) { + $form['button'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#submit' => array('form_test_load_include_submit'), + ); + // Specify the include file and enable form caching. That way the form is + // cached when it is submitted, but needs to find the specified submit handler + // in the include. + $form_state['build_info']['files'][] = array('module' => 'form_test', 'name' => 'form_test.file'); + $form_state['cache'] = TRUE; + return $form; +} -- cgit v1.2.3