You are here

protected function UserProtectWebTestBase::userprotectPostForm in User protect 7

Executes a form submission, but does not require all fields to be present.

@todo Update for 7.x-1.x.

Parameters

NULL|string $path: Location of the post form.

array $edit: Field data in an associative array.

string $submit: Value of the submit button whose click is to be emulated.

array $options: (optional) Options to be forwarded to the url generator.

array $headers: (optional) An array containing additional HTTP request headers.

string $form_html_id: (optional) HTML ID of the form to be submitted.

Return value

NULL|string Result of CURL in case form could be posted. NULL otherwise.

10 calls to UserProtectWebTestBase::userprotectPostForm()
UserProtectPermissionsWebTest::testNoEditOwnMail in tests/UserProtectPermissionsWebTest.test
Tests edit mail without permission "change own e-mail".
UserProtectPermissionsWebTest::testNoEditOwnPass in tests/UserProtectPermissionsWebTest.test
Tests edit password without permission "change own password".
UserProtectProtectionWebTest::testMailProtection in tests/UserProtectProtectionWebTest.test
Tests if the user's mail address field has the expected protection.
UserProtectProtectionWebTest::testNameProtection in tests/UserProtectProtectionWebTest.test
Tests if the user's name field has the expected protection.
UserProtectProtectionWebTest::testPassProtection in tests/UserProtectProtectionWebTest.test
Tests if the user's password field has the expected protection.

... See full list

File

tests/UserProtectWebTestBase.test, line 187
Contains \UserProtectWebTestBase.

Class

UserProtectWebTestBase
Base class for User protect web tests.

Code

protected function userprotectPostForm($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL) {
  if (isset($path)) {
    $this
      ->drupalGet($path, $options);
  }
  if ($this
    ->parse()) {
    $edit_save = $edit;

    // Let's iterate over all the forms.
    $xpath = "//form";
    if (!empty($form_html_id)) {
      $xpath .= "[@id='" . $form_html_id . "']";
    }
    $forms = $this
      ->xpath($xpath);
    foreach ($forms as $form) {

      // We try to set the fields of this form as specified in $edit.
      $edit = $edit_save;
      $post = array();
      $upload = array();
      $submit_matches = $this
        ->handleForm($post, $edit, $upload, $submit, $form);
      $action = isset($form['action']) ? $this
        ->getAbsoluteUrl((string) $form['action']) : $this
        ->getUrl();
      if ($submit_matches) {
        $post = array_merge($post, $edit);
        $out = $this
          ->curlExec(array(
          CURLOPT_URL => $action,
          CURLOPT_POST => TRUE,
          CURLOPT_POSTFIELDS => $post,
          CURLOPT_HTTPHEADER => $headers,
        ));
        $verbose = 'POST request to: ' . $path;
        $verbose .= '<hr />Ending URL: ' . $this
          ->getUrl();
        $verbose .= '<hr />Fields: ' . highlight_string('<?php ' . var_export($post, TRUE), TRUE);
        $verbose .= '<hr />' . $out;
        $this
          ->verbose($verbose);
        return $out;
      }
    }
    $this
      ->fail(format_string('Found the requested form fields at @path', array(
      '@path' => $path,
    )));
  }
}