You are here

function SecurePagesTestCase::_testFormAlter in Secure Pages 7

Same name and namespace in other branches
  1. 8 securepages.test \SecurePagesTestCase::_testFormAlter()
  2. 6.2 securepages.test \SecurePagesTestCase::_testFormAlter()
  3. 6 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 160
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.
  user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
    'access comments' => TRUE,
    'post comments' => TRUE,
    'skip comment approval' => TRUE,
  ));
  $this->web_user = $this
    ->drupalCreateUser(array(
    'access comments',
    'post comments',
    'skip comment approval',
  ));
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    '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, array(
      'https' => FALSE,
    ));
    $this
      ->assertFieldByXPath('//form[@class="comment-form" and starts-with(@action, "https:")]', NULL, "The {$mode} comment form action is https.");
    $this
      ->drupalPost(NULL, array(
      'comment_body[und][0][value]' => 'test comment',
    ), t('Save'));
    $this
      ->assertRaw(t('Your comment has been posted.'));

    // Test HTTPS posting to plain HTTP.
    variable_set('securepages_pages', "node/*\nuser*");
    $this
      ->drupalGet('node/' . $node->nid, array(
      'https' => TRUE,
    ));
    $this
      ->assertUrl(url('node/' . $node->nid, array(
      'https' => TRUE,
      'absolute' => TRUE,
    )));
    $this
      ->assertFieldByXPath('//form[@class="comment-form" and starts-with(@action, "http:")]', NULL, "The {$mode} comment form action is http.");
    $this
      ->drupalPost(NULL, array(
      'comment_body[und][0][value]' => 'test',
    ), t('Save'));
    $this
      ->assertRaw(t('Your comment has been posted.'));
  }
  $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');
}