You are here

protected function ContentLanguageAccessTestCase::addLanguage in Content Language Access 7

Same name and namespace in other branches
  1. 6 content_language_access.test \ContentLanguageAccessTestCase::addLanguage()

Enables the specified language if it has not been already.

Parameters

string $language_code: The language code to enable.

1 call to ContentLanguageAccessTestCase::addLanguage()
ContentLanguageAccessTestCase::configureLanguages in ./content_language_access.test
Creates the languages for the test execution.

File

./content_language_access.test, line 119
Test suite for content language access module.

Class

ContentLanguageAccessTestCase
Defines the content language access test class.

Code

protected function addLanguage($language_code) {

  // Check to make sure that language has not already been installed.
  $this
    ->drupalGet('admin/settings/language');
  if (strpos($this
    ->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {

    // Doesn't have language installed so add it.
    $edit = array();
    $edit['langcode'] = $language_code;
    $this
      ->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));

    // Make sure not using cached version.
    drupal_static_reset('language_list');
    $languages = language_list('language');
    $this
      ->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
    if (array_key_exists($language_code, $languages)) {
      $this
        ->assertRaw(t('The language %language has been created and can now be used.', array(
        '%language' => $languages[$language_code]->name,
      )), t('Language has been created.'));
    }
  }
  else {

    // Ensure that it is enabled.
    $this
      ->drupalPost(NULL, array(
      'enabled[' . $language_code . ']' => TRUE,
    ), t('Save configuration'));
    $this
      ->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
  }
}