You are here

function DrupalTestCase::drupalPostRequest in SimpleTest 5

Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser

Parameters

string $path location of the post form:

array $edit field data:

string $submit name of the submit button, untranslated:

20 calls to DrupalTestCase::drupalPostRequest()
DrupalTestCase::drupalLoginUser in ./drupal_test_case.php
Logs in a user with the internal browser
ImageModuleTest::testImageNode in tests/image_module.test
PageCreationTest::testPageCreation in tests/page_creation.test
ProfileModuleTest2::testProfileOtherFields in tests/profile_module.test
ProfileModuleTestCheckbox::testProfileCheckbox in tests/profile_module.test

... See full list

File

./drupal_test_case.php, line 97

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function drupalPostRequest($path, $edit = [], $submit) {
  $url = url($path, NULL, NULL, TRUE);
  $ret = $this
    ->drupalGet($url);
  $this
    ->assertTrue($ret, t(' [browser] GET path "@path"', array(
    '@path' => $path,
  )));
  foreach ($edit as $field_name => $field_value) {
    $ret = $this->_browser
      ->setFieldByName($field_name, $field_value) || $this->_browser
      ->setFieldById("edit-{$field_name}", $field_value);
    $this
      ->assertTrue($ret, " [browser] Setting {$field_name}=\"{$field_value}\"");
  }
  $ret = $this->_browser
    ->clickSubmit(t($submit)) || $this->_browser
    ->clickSubmitById($submit) || $this->_browser
    ->clickSubmitByName($submit) || $this->_browser
    ->clickImageByName($submit);
  $this
    ->assertTrue($ret, ' [browser] POST by click on ' . t($submit));
  $this->_content = $this->_browser
    ->getContent();
}