You are here

protected function BotchaBaseWebTestCase::getFormBuildIdFromForm in BOTCHA Spam Prevention 6.2

Same name and namespace in other branches
  1. 6 botcha.test \BotchaBaseWebTestCase::getFormBuildIdFromForm()
  2. 6.3 tests/botcha.simpletest.test \BotchaBaseWebTestCase::getFormBuildIdFromForm()
  3. 7 botcha.test \BotchaBaseWebTestCase::getFormBuildIdFromForm()
  4. 7.2 botcha.test \BotchaBaseWebTestCase::getFormBuildIdFromForm()
  5. 7.3 tests/botcha.simpletest.test \BotchaBaseWebTestCase::getFormBuildIdFromForm()

Get the form_build_id from the current form in the browser.

1 call to BotchaBaseWebTestCase::getFormBuildIdFromForm()
BotchaNoResubmitTestCase::setFormValues in ./botcha.test
Helper function to generate a default form values array for any form.

File

./botcha.test, line 193
Tests for BOTCHA module.

Class

BotchaBaseWebTestCase
Base class for BOTCHA tests.

Code

protected function getFormBuildIdFromForm($form = NULL) {

  // Form a xpath query string.
  $xpath = '//';
  if (!empty($form)) {

    // Specially to transform user_login to user-login.
    // @todo getFormBuildIdFromForm ?Is there a better way to do it?
    $form_filtered = str_replace('_', '-', $form);

    // If form parameter is set we are looking for forms like it. It is useful
    // when we have multiple forms on one page.
    $xpath .= "form[contains(@id, '{$form_filtered}')]/div/";
  }
  $xpath .= "input[@name='form_build_id']/@value";

  // Force conversion to string.

  //$form_build_id = (string) current($this->xpath("//input[@name='form_build_id']/@value"));
  $form_build_id = (string) current($this
    ->xpath($xpath));
  return $form_build_id;
}