summaryrefslogtreecommitdiff
path: root/modules/simpletest/drupal_web_test_case.php
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-26 18:58:12 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-26 18:58:12 +0000
commitc327b4d407c0fc3ea74037789214b23d2b35e9a0 (patch)
treeb03f23a11760e8f511bf9d5b0d3781f5a16a4458 /modules/simpletest/drupal_web_test_case.php
parenta7d001f7d18c738875fc846dbb719c4bbdf9272b (diff)
downloadbrdo-c327b4d407c0fc3ea74037789214b23d2b35e9a0.tar.gz
brdo-c327b4d407c0fc3ea74037789214b23d2b35e9a0.tar.bz2
- Patch #684846 by effulgentsia, rfay, quicksketch, aspilicious: AJAX triggered by non-submit element fails if any elements are validated.
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r--modules/simpletest/drupal_web_test_case.php32
1 files changed, 23 insertions, 9 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index f2622444d..42ac83058 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1576,11 +1576,18 @@ class DrupalWebTestCase extends DrupalTestCase {
* which is likely different than the $path parameter used for retrieving
* the initial form. Defaults to 'system/ajax'.
* - triggering_element: If the value for the 'path' key is 'system/ajax' or
- * another generic AJAX processing path, this needs to be set to the '/'
- * separated path to the element within the server's cached $form array.
- * The callback for the generic AJAX processing path uses this to find
- * the #ajax information for the element, including which specific
- * callback to use for processing the request.
+ * another generic AJAX processing path, this needs to be set to the name
+ * of the element. If the name doesn't identify the element uniquely, then
+ * this should instead be an array with a single key/value pair,
+ * corresponding to the element name and value. The callback for the
+ * generic AJAX processing path uses this to find the #ajax information
+ * for the element, including which specific callback to use for
+ * processing the request.
+ *
+ * This can also be set to NULL in order to emulate an Internet Explorer
+ * submission of a form with a single text field, and pressing ENTER in that
+ * textfield: under these conditions, no button information is added to the
+ * POST data.
* @param $options
* Options to be forwarded to url().
* @param $headers
@@ -1622,7 +1629,7 @@ class DrupalWebTestCase extends DrupalTestCase {
// We post only if we managed to handle every field in edit and the
// submit button matches.
- if (!$edit && $submit_matches) {
+ if (!$edit && ($submit_matches || !isset($submit))) {
$post_array = $post;
if ($upload) {
// TODO: cURL handles file uploads for us, but the implementation
@@ -1643,7 +1650,14 @@ class DrupalWebTestCase extends DrupalTestCase {
$post[$key] = urlencode($key) . '=' . urlencode($value);
}
if ($ajax && isset($submit['triggering_element'])) {
- $post['ajax_triggering_element'] = 'ajax_triggering_element=' . urlencode($submit['triggering_element']);
+ if (is_array($submit['triggering_element'])) {
+ // Get the first key/value pair in the array.
+ $post['_triggering_element_value'] = '_triggering_element_value=' . urlencode(reset($submit['triggering_element']));
+ $post['_triggering_element_name'] = '_triggering_element_name=' . urlencode(key($submit['triggering_element']));
+ }
+ else {
+ $post['_triggering_element_name'] = '_triggering_element_name=' . urlencode($submit['triggering_element']);
+ }
}
$post = implode('&', $post);
}
@@ -1666,7 +1680,7 @@ class DrupalWebTestCase extends DrupalTestCase {
foreach ($edit as $name => $value) {
$this->fail(t('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
}
- if (!$ajax) {
+ if (!$ajax && isset($submit)) {
$this->assertTrue($submit_matches, t('Found the @submit button', array('@submit' => $submit)));
}
$this->fail(t('Found the requested form fields at @path', array('@path' => $path)));
@@ -1856,7 +1870,7 @@ class DrupalWebTestCase extends DrupalTestCase {
break;
case 'submit':
case 'image':
- if ($submit == $value) {
+ if (isset($submit) && $submit == $value) {
$post[$name] = $value;
$submit_matches = TRUE;
}