function TranslationTest::addLanguage

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

Parameters

$langcode: The language code to check.

2 calls to TranslationTest::addLanguage()
TranslationTest::setUp in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Sets up a Drupal site for running functional and integration tests.
TranslationTest::testLanguageSwitcherBlockIntegration in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Tests that the language switcher block alterations work as intended.

File

drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php, line 306
Definition of Drupal\translation\Tests\TranslationTest.

Class

TranslationTest
Functional tests for the Translation module.

Namespace

Drupal\translation\Tests

Code

function addLanguage($langcode) {

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

    // Doesn't have language installed so add it.
    $edit = array();
    $edit['predefined_langcode'] = $langcode;
    $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();
    $this
      ->assertTrue(array_key_exists($langcode, $languages), 'Language was installed successfully.');
    if (array_key_exists($langcode, $languages)) {
      $this
        ->assertRaw(t('The language %language has been created and can now be used.', array(
        '%language' => $languages[$langcode]->name,
      )), 'Language has been created.');
    }
  }
  else {

    // It's installed. No need to do anything.
    $this
      ->assertTrue(TRUE, 'Language [' . $langcode . '] already installed.');
  }
}