summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-09-19 18:38:58 +0000
committerDries Buytaert <dries@buytaert.net>2010-09-19 18:38:58 +0000
commit8580169d0e05e25cd1791f538c0a32ec45082642 (patch)
tree7642fe7555e601566d91ff4468b3c825388867c5 /modules/simpletest/tests
parent5c4dfd44f956cbffd7d201fd6c47e9a37e86ad2d (diff)
downloadbrdo-8580169d0e05e25cd1791f538c0a32ec45082642.tar.gz
brdo-8580169d0e05e25cd1791f538c0a32ec45082642.tar.bz2
- Patch #789186 by effulgentsia: improve drupalPostAJAX() to be used more easily, leading to better AJAX test coverage. (Rollback)
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/ajax.test15
-rw-r--r--modules/simpletest/tests/form.test6
-rw-r--r--modules/simpletest/tests/form_test.file.inc13
3 files changed, 18 insertions, 16 deletions
diff --git a/modules/simpletest/tests/ajax.test b/modules/simpletest/tests/ajax.test
index 9377f4cdb..91572bda0 100644
--- a/modules/simpletest/tests/ajax.test
+++ b/modules/simpletest/tests/ajax.test
@@ -269,17 +269,24 @@ class AJAXMultiFormTestCase extends AJAXTestCase {
// of field items and "add more" button for the multi-valued field within
// each form.
$this->drupalGet('form-test/two-instances-of-same-form');
- foreach ($field_xpaths as $form_html_id => $field_xpath) {
+ foreach ($field_xpaths as $form_id => $field_xpath) {
$this->assert(count($this->xpath($field_xpath . $field_items_xpath_suffix)) == 1, t('Found the correct number of field items on the initial page.'));
$this->assertFieldByXPath($field_xpath . $button_xpath_suffix, NULL, t('Found the "add more" button on the initial page.'));
}
$this->assertNoDuplicateIds(t('Initial page contains unique IDs'), 'Other');
// Submit the "add more" button of each form twice. After each corresponding
- // page update, ensure the same as above.
- foreach ($field_xpaths as $form_html_id => $field_xpath) {
+ // page update, ensure the same as above. To successfully implement
+ // consecutive AJAX submissions, we need to manage $settings as ajax.js
+ // does for Drupal.settings.
+ preg_match('/jQuery\.extend\(Drupal\.settings, (.*?)\);/', $this->content, $matches);
+ $settings = drupal_json_decode($matches[1]);
+ foreach ($field_xpaths as $form_id => $field_xpath) {
for ($i=0; $i<2; $i++) {
- $this->drupalPostAJAX(NULL, array(), array($button_name => $button_value), 'system/ajax', array(), array(), $form_html_id);
+ $button = $this->xpath($field_xpath . $button_xpath_suffix);
+ $button_id = (string) $button[0]['id'];
+ $commands = $this->drupalPostAJAX(NULL, array(), array($button_name => $button_value), 'system/ajax', array(), array(), $form_id, $settings['ajax'][$button_id]);
+ $settings = array_merge_recursive($settings, $commands[0]['settings']);
$this->assert(count($this->xpath($field_xpath . $field_items_xpath_suffix)) == $i+2, t('Found the correct number of field items after an AJAX submission.'));
$this->assertFieldByXPath($field_xpath . $button_xpath_suffix, NULL, t('Found the "add more" button after an AJAX submission.'));
$this->assertNoDuplicateIds(t('Updated page contains unique IDs'), 'Other');
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 969f3f398..c3ef7fd9d 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -996,7 +996,11 @@ class FormsRebuildTestCase extends DrupalWebTestCase {
// submission and verify it worked by ensuring the updated page has two text
// field items in the field for which we just added an item.
$this->drupalGet('node/add/page');
- $this->drupalPostAJAX(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-form');
+ preg_match('/jQuery\.extend\(Drupal\.settings, (.*?)\);/', $this->content, $matches);
+ $settings = drupal_json_decode($matches[1]);
+ $button = $this->xpath('//input[@name="field_ajax_test_add_more"]');
+ $button_id = (string) $button[0]['id'];
+ $this->drupalPostAJAX(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-form', $settings['ajax'][$button_id]);
$this->assert(count($this->xpath('//div[contains(@class, "field-name-field-ajax-test")]//input[@type="text"]')) == 2, t('AJAX submission succeeded.'));
// Submit the form with the non-AJAX "Save" button, leaving the title field
diff --git a/modules/simpletest/tests/form_test.file.inc b/modules/simpletest/tests/form_test.file.inc
index 808863ede..96681eaa8 100644
--- a/modules/simpletest/tests/form_test.file.inc
+++ b/modules/simpletest/tests/form_test.file.inc
@@ -13,17 +13,11 @@
function form_test_load_include_menu($form, &$form_state) {
// Submit the form via AJAX. That way the FAPI has to care about including
// the file specified in hook_menu().
- $ajax_wrapper_id = drupal_html_id('form-test-load-include-menu-ajax-wrapper');
- $form['ajax_wrapper'] = array(
- '#markup' => '<div id="' . $ajax_wrapper_id . '"></div>',
- );
$form['button'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array('form_test_load_include_submit'),
'#ajax' => array(
- 'wrapper' => $ajax_wrapper_id,
- 'method' => 'append',
'callback' => 'form_test_load_include_menu_ajax',
),
);
@@ -38,12 +32,9 @@ function form_test_load_include_submit($form, $form_state) {
}
/**
- * Ajax callback for the file inclusion via menu test.
+ * 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) {
- // We don't need to return anything, since #ajax['method'] is 'append', which
- // does not remove the original #ajax['wrapper'] element, and status messages
- // are automatically added by the AJAX framework as long as there's a wrapper
- // element to add them to.
return '';
}