You are here

function SecurePagesTestCase::_testFormAlter in Secure Pages 6.2

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

Tests the ability to alter form actions.

Uses the comment form, since it has an #action set.

1 call to SecurePagesTestCase::_testFormAlter()
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 157
Provides SimpleTests for Secure Pages module.

Class

SecurePagesTestCase
@file Provides SimpleTests for Secure Pages module.

Code

function _testFormAlter() {
  variable_set('securepages_switch', TRUE);

  // Enable anonymous user comments.
  db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", 'access comments, access content, post comments, post comments without approval', DRUPAL_ANONYMOUS_RID);
  $this->web_user = $this
    ->drupalCreateUser(array(
    'access comments',
    'post comments',
    'post comments without approval',
  ));
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'story',
    'promote' => 1,
  ));
  foreach (array(
    'anonymous',
    'authenticated',
  ) as $mode) {
    if ($mode == 'authenticated') {
      $this
        ->drupalLogin($this->web_user);
    }

    // Test plain HTTP posting to HTTPS.
    variable_set('securepages_pages', "comment/reply/*\nuser*");
    $this
      ->drupalGet('node/' . $node->nid);
    $this
      ->assertFieldByXPath('//form[@id="comment-form" and starts-with(@action, "https:")]', NULL, "The {$mode} comment form action is https.");
    $comment_body = $this
      ->randomName(8);
    $this
      ->drupalPost(NULL, array(
      'comment' => $comment_body,
    ), t('Save'));
    $this
      ->assertRaw($comment_body);

    // Test HTTPS posting to plain HTTP.
    variable_set('securepages_pages', "node/*\nuser*");
    $this
      ->drupalGet($this
      ->_toHTTPS(url('node/' . $node->nid), array(
      'absolute' => TRUE,
    )));
    $this
      ->assertUrl($this
      ->_toHTTPS(url('node/' . $node->nid, array(
      'absolute' => TRUE,
    ))));
    $this
      ->assertFieldByXPath('//form[@id="comment-form" and starts-with(@action, "http:")]', NULL, "The {$mode} comment form action is http.");
    $comment_body = $this
      ->randomName(8);
    $this
      ->drupalPost(NULL, array(
      'comment' => $comment_body,
    ), t('Save'));
    $this
      ->assertRaw($comment_body);
  }
  $this
    ->drupalLogout();

  // Test the user login block.
  $this
    ->drupalGet('');
  $edit = array(
    'name' => $this->web_user->name,
    'pass' => $this->web_user->pass_raw,
  );
  $this
    ->drupalPost(NULL, $edit, t('Log in'));
  $this
    ->drupalGet('user/' . $this->web_user->uid . '/edit');
  $this
    ->assertResponse(200);

  // Clean up
  $this
    ->drupalLogout();
  variable_del('securepages_pages');
  variable_del('securepages_switch');
}