You are here

function LanguageListTest::testLanguageStates in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/Tests/LanguageListTest.php \Drupal\language\Tests\LanguageListTest::testLanguageStates()

Functional tests for the language states (locked or configurable).

File

core/modules/language/src/Tests/LanguageListTest.php, line 194
Contains \Drupal\language\Tests\LanguageListTest.

Class

LanguageListTest
Adds a new language and tests changing its status and the default language.

Namespace

Drupal\language\Tests

Code

function testLanguageStates() {

  // Add some languages, and also lock some of them.
  ConfigurableLanguage::create(array(
    'label' => $this
      ->randomMachineName(),
    'id' => 'l1',
  ))
    ->save();
  ConfigurableLanguage::create(array(
    'label' => $this
      ->randomMachineName(),
    'id' => 'l2',
    'locked' => TRUE,
  ))
    ->save();
  ConfigurableLanguage::create(array(
    'label' => $this
      ->randomMachineName(),
    'id' => 'l3',
  ))
    ->save();
  ConfigurableLanguage::create(array(
    'label' => $this
      ->randomMachineName(),
    'id' => 'l4',
    'locked' => TRUE,
  ))
    ->save();
  $expected_locked_languages = array(
    'l4' => 'l4',
    'l2' => 'l2',
    'und' => 'und',
    'zxx' => 'zxx',
  );
  $expected_all_languages = array(
    'l4' => 'l4',
    'l3' => 'l3',
    'l2' => 'l2',
    'l1' => 'l1',
    'en' => 'en',
    'und' => 'und',
    'zxx' => 'zxx',
  );
  $expected_conf_languages = array(
    'l3' => 'l3',
    'l1' => 'l1',
    'en' => 'en',
  );
  $locked_languages = $this->container
    ->get('language_manager')
    ->getLanguages(LanguageInterface::STATE_LOCKED);
  $this
    ->assertEqual(array_diff_key($expected_locked_languages, $locked_languages), array(), 'Locked languages loaded correctly.');
  $all_languages = $this->container
    ->get('language_manager')
    ->getLanguages(LanguageInterface::STATE_ALL);
  $this
    ->assertEqual(array_diff_key($expected_all_languages, $all_languages), array(), 'All languages loaded correctly.');
  $conf_languages = $this->container
    ->get('language_manager')
    ->getLanguages();
  $this
    ->assertEqual(array_diff_key($expected_conf_languages, $conf_languages), array(), 'Configurable languages loaded correctly.');
}