You are here

function SecurePagesTestCase::_testXHR in Secure Pages 7

Same name and namespace in other branches
  1. 8 securepages.test \SecurePagesTestCase::_testXHR()
  2. 6.2 securepages.test \SecurePagesTestCase::_testXHR()
  3. 6 securepages.test \SecurePagesTestCase::_testXHR()

Test detection of XHR and overlay requests.

1 call to SecurePagesTestCase::_testXHR()
SecurePagesTestCase::testSecurePages in ./securepages.test
Runs all the test functions. These are run from a single outer function to avoid multiple re-installs by simpletest.

File

./securepages.test, line 286
Provides SimpleTests for Secure Pages module.

Class

SecurePagesTestCase
@file Provides SimpleTests for Secure Pages module.

Code

function _testXHR() {
  $admin_user = $this
    ->drupalCreateUser(array(
    'access overlay',
    'access user profiles',
    'administer users',
    'access administration pages',
  ));
  $this
    ->drupalLogin($admin_user);

  // Without XHR header
  $this
    ->drupalGet('user/autocomplete/a', array(
    'https' => FALSE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('user/autocomplete/a', array(
    'https' => TRUE,
    'absolute' => TRUE,
  )));

  // With XHR header
  $this
    ->drupalGet('user/autocomplete/a', array(
    'https' => FALSE,
  ), array(
    'X-Requested-With: XMLHttpRequest',
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('user/autocomplete/a', array(
    'https' => FALSE,
    'absolute' => TRUE,
  )));

  // Test the overlay
  $this
    ->drupalGet('admin', array(
    'query' => array(
      'render' => 'overlay',
    ),
    'https' => FALSE,
  ), array(
    'X-Requested-With: XMLHttpRequest',
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('"closeOverlay":true');

  // Clean up
  $this
    ->drupalLogout();
}