You are here

function Drupali18nTestCase::addLanguage in Internationalization 7

Same name and namespace in other branches
  1. 6 tests/drupal_i18n_test_case.php \Drupali18nTestCase::addLanguage()

Install a the specified language if it has not been already. Otherwise make sure that the language is enabled.

Parameters

$language_code: The language code the check.

3 calls to Drupali18nTestCase::addLanguage()
Drupali18nConfigTestCase::testEnableLanguages in ./i18n.test
Drupali18nTestCase::setUpLanguages in ./i18n.test
I18nNodeTestCase::setUp in i18n_node/i18n_node.test
Sets up a Drupal site for running functional and integration tests.

File

./i18n.test, line 94
Base class for Internationalization tests

Class

Drupali18nTestCase
@file Base class for Internationalization tests

Code

function addLanguage($language_code) {

  // Check to make sure that language has not already been installed.
  $this
    ->drupalGet('admin/config/regional/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 we are not using a stale list.
    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. More information is available on the <a href="@locale-help">help screen</a>.', array(
        '%language' => $languages[$language_code]->name,
        '@locale-help' => url('admin/help/locale'),
      )), t('Language has been created.'));
    }
  }
  elseif ($this
    ->xpath('//input[@type="checkbox" and @name=:name and @checked="checked"]', array(
    ':name' => 'enabled[' . $language_code . ']',
  ))) {

    // It's installed and enabled. No need to do anything.
    $this
      ->assertTrue(true, 'Language [' . $language_code . '] already installed and enabled.');
  }
  else {

    // It's installed but not enabled. Enable it.
    $this
      ->assertTrue(true, 'Language [' . $language_code . '] already installed.');
    $this
      ->drupalPost(NULL, array(
      'enabled[' . $language_code . ']' => TRUE,
    ), t('Save configuration'));
    $this
      ->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
  }
}