You are here

public function BrowserBackendTestCase::testBrowserBackend in SimpleTest 7

Test stream and curl backends execution of GET and POST requests.

File

tests/browser.test, line 65
Tests for the internal web browser.

Class

BrowserBackendTestCase
Test browser backend wrappers.

Code

public function testBrowserBackend() {
  global $db_prefix;
  foreach (array(
    'stream',
    'curl',
  ) as $wrapper) {
    $browser = new Browser($wrapper == 'stream');
    $browser
      ->setUserAgent(drupal_generate_test_ua($db_prefix));
    $string = $this
      ->randomName();
    $edit = array(
      'foo' => $string,
    );

    // Test GET method.
    $request = $browser
      ->get(url('browser_test/print/get', array(
      'absolute' => TRUE,
      'query' => $edit,
    )));
    $this
      ->assertEqual($string, $request['content'], t('String found during GET request ($request)'), $wrapper);
    $this
      ->assertEqual($string, $browser
      ->getContent(), t('String found during GET request ($browser)'), $wrapper);

    // Test POST method.
    $request = $browser
      ->post(url('browser_test/print/post', array(
      'absolute' => TRUE,
    )), $edit, t('Submit'));
    $this
      ->assertEqual($string, $request['content'], t('String found during POST request ($request)'), $wrapper);
    $this
      ->assertEqual($string, $browser
      ->getContent(), t('String found during POST request ($browser)'), $wrapper);
  }
}