function LanguageSelectElementTest::testLanguageSelectElementOptions in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Form/LanguageSelectElementTest.php \Drupal\system\Tests\Form\LanguageSelectElementTest::testLanguageSelectElementOptions()
Tests that the options printed by the language select element are correct.
File
- core/
modules/ system/ src/ Tests/ Form/ LanguageSelectElementTest.php, line 33 - Contains \Drupal\system\Tests\Form\LanguageSelectElementTest.
Class
- LanguageSelectElementTest
- Tests that the language select form element prints and submits the right options.
Namespace
Drupal\system\Tests\FormCode
function testLanguageSelectElementOptions() {
// Add some languages.
ConfigurableLanguage::create(array(
'id' => 'aaa',
'label' => $this
->randomMachineName(),
))
->save();
ConfigurableLanguage::create(array(
'id' => 'bbb',
'label' => $this
->randomMachineName(),
))
->save();
\Drupal::languageManager()
->reset();
$this
->drupalGet('form-test/language_select');
// Check that the language fields were rendered on the page.
$ids = array(
'edit-languages-all' => LanguageInterface::STATE_ALL,
'edit-languages-configurable' => LanguageInterface::STATE_CONFIGURABLE,
'edit-languages-locked' => LanguageInterface::STATE_LOCKED,
'edit-languages-config-and-locked' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED,
);
foreach ($ids as $id => $flags) {
$this
->assertField($id, format_string('The @id field was found on the page.', array(
'@id' => $id,
)));
$options = array();
/* @var $language_manager \Drupal\Core\Language\LanguageManagerInterface */
$language_manager = $this->container
->get('language_manager');
foreach ($language_manager
->getLanguages($flags) as $langcode => $language) {
$options[$langcode] = $language
->isLocked() ? t('- @name -', array(
'@name' => $language
->getName(),
)) : $language
->getName();
}
$this
->_testLanguageSelectElementOptions($id, $options);
}
// Test that the #options were not altered by #languages.
$this
->assertField('edit-language-custom-options', format_string('The @id field was found on the page.', array(
'@id' => 'edit-language-custom-options',
)));
$this
->_testLanguageSelectElementOptions('edit-language-custom-options', array(
'opt1' => 'First option',
'opt2' => 'Second option',
'opt3' => 'Third option',
));
}