You are here

protected function EntityCachePageEditTestCase::drupalPost in Entity cache 7

Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.

Parameters

$path: Location of the post form. Either a Drupal path or an absolute path or NULL to post to the current page. For multi-stage forms you can set the path to NULL and have it post to the last received page. Example:


  // First step in form.
  $edit = array(...);
  $this->drupalPost('some_url', $edit, t('Save'));

  // Second step in form.
  $edit = array(...);
  $this->drupalPost(NULL, $edit, t('Save'));
  

$edit: Field data in an associative array. Changes the current input fields (where possible) to the values indicated. A checkbox can be set to TRUE to be checked and FALSE to be unchecked. Note that when a form contains file upload fields, other fields cannot start with the '@' character.

Multiple select fields can be set using name[] and setting each of the possible values. Example:

$edit = array();
$edit['name[]'] = array(
  'value1',
  'value2',
);

$submit: Value of the submit button whose click is to be emulated. For example, t('Save'). The processing of the request depends on this value. For example, a form may have one button with the value t('Save') and another button with the value t('Delete'), and execute different code depending on which one is clicked.

This function can also be called to emulate an Ajax submission. In this case, this value needs to be an array with the following keys:

  • path: A path to submit the form values to for Ajax-specific processing, 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 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.

$options: Options to be forwarded to url().

$headers: An array containing additional HTTP request headers, each formatted as "name: value".

$form_html_id: (optional) HTML ID of the form to be submitted. On some pages there are many identical forms, so just using the value of the submit button is not enough. For example: 'trigger-node-presave-assign-form'. Note that this is not the Drupal $form_id, but rather the HTML ID of the form, which is typically the same thing but with hyphens replacing the underscores.

$extra_post: (optional) A string of additional data to append to the POST submission. This can be used to add POST data for which there are no HTML fields, as is done by drupalPostAJAX(). This string is literally appended to the POST data, so it must already be urlencoded and contain a leading "&" (e.g., "&extra_var1=hello+world&extra_var2=you%26me").

Overrides DrupalWebTestCase::drupalPost

File

./entitycache.test, line 861
Entity Cache module tests.

Class

EntityCachePageEditTestCase
Copy of PageEditTestCase.

Code

protected function drupalPost($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) {
  $result = parent::drupalPost($path, $edit, $submit, $options, $headers, $form_html_id, $extra_post);

  // Reset the cache, to let the test pass. The problem is that the test
  // adds a new revision using ::drupalPost so the static cache in the context
  // of the test, never has the chance to react.
  if (!empty($edit['revision'])) {
    $node = $this
      ->drupalGetNodeByTitle($edit['title']);
    $nid = $node->nid;
    entity_get_controller('node')
      ->resetCache(array(
      $nid,
    ));
  }
  return $result;
}