You are here

function SecurePagesTestCase::_testLocale in Secure Pages 8

Same name and namespace in other branches
  1. 6.2 securepages.test \SecurePagesTestCase::_testLocale()
  2. 7 securepages.test \SecurePagesTestCase::_testLocale()

Tests correct operation with locale module.

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

Class

SecurePagesTestCase
@file Provides SimpleTests for Secure Pages module.

Code

function _testLocale() {

  // Enable "Switch back to http pages when there are no matches".
  variable_set('securepages_switch', TRUE);

  // User to add and remove language.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer languages',
    'access administration pages',
  ));
  $this
    ->drupalLogin($admin_user);

  // Add predefined language.
  $edit = array(
    'langcode' => 'fr',
  );
  $this
    ->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
  $this
    ->assertText('fr', t('Language added successfully.'));

  // Enable URL language detection and selection.
  $edit = array(
    'language[enabled][locale-url]' => '1',
  );
  $this
    ->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
  drupal_static_reset('language_list');
  drupal_static_reset('locale_url_outbound_alter');
  $languages = language_list('language');
  $lang = $languages['fr'];
  $this
    ->drupalGet('user', array(
    'language' => $lang,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('user', array(
    'https' => TRUE,
    'absolute' => TRUE,
    'language' => $lang,
  )));
  $this
    ->assertTrue(strstr($this->url, 'fr/user'), t('URL contains language prefix.'));
  $this
    ->drupalGet('', array(
    'language' => $lang,
    'https' => TRUE,
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl(url('', array(
    'https' => FALSE,
    'absolute' => TRUE,
    'language' => $lang,
  )));

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