1 translation.test TranslationTestCase::addLanguage($language_code)

Installs the specified language, or enables it if it is already installed.


$language_code: The language code to check.


core/modules/translation/tests/translation.test, line 281
Tests for the Translation module.


Functional tests for the Translation module.


function addLanguage($language_code) {
  // Check to make sure that language has not already been installed.

  if (strpos($this->backdropGetContent(), 'languages[' . $language_code . '][enabled]') === FALSE) {
    // Doesn't have language installed so add it.
    $edit = array();
    $edit['predefined_langcode'] = $language_code;
    $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));

    // Make sure we are not using a stale list.
    $languages = language_list();
    $this->assertTrue(array_key_exists($language_code, $languages), '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)), 'Language has been created.');
  elseif ($this->xpath('//input[@type="checkbox" and @name=:name and @checked="checked"]', array(':name' => 'languages[' . $language_code . '][enabled]'))) {
    // 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->backdropPost(NULL, array('languages[' . $language_code . '][enabled]' => TRUE), t('Save configuration'));
    $this->assertRaw(t('Configuration saved.'), 'Language successfully enabled.');