You are here

protected function ContentLanguageAccessTestCase::addLanguage in Content Language Access 6

Same name and namespace in other branches
  1. 7 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 112
Test suite for content language access module

Class

ContentLanguageAccessTestCase
@file Test suite for content language access module

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/settings/language/add', $edit, t('Add language'));

    // Make sure not using cached version.
    $languages = language_list('language', TRUE);
    $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.'));
  }
}