class LanguageSelectWidgetTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/language/tests/src/Kernel/LanguageSelectWidgetTest.php \Drupal\Tests\language\Kernel\LanguageSelectWidgetTest
- 9 core/modules/language/tests/src/Kernel/LanguageSelectWidgetTest.php \Drupal\Tests\language\Kernel\LanguageSelectWidgetTest
Tests the language select widget.
@group language
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\language\Kernel\LanguageSelectWidgetTest
Expanded class hierarchy of LanguageSelectWidgetTest
File
- core/
modules/ language/ tests/ src/ Kernel/ LanguageSelectWidgetTest.php, line 13
Namespace
Drupal\Tests\language\KernelView source
class LanguageSelectWidgetTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
'language',
'user',
'system',
];
/**
* The entity form display.
*
* @var \Drupal\Core\Entity\Entity\EntityFormDisplay
*/
protected $entityFormDisplay;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
$storage = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display');
$this->entityFormDisplay = $storage
->create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
]);
}
/**
* Tests the widget with the locked languages.
*/
public function testWithIncludedLockedLanguage() {
$this->entityFormDisplay
->setComponent('langcode', [
'type' => 'language_select',
])
->save();
$entity = EntityTest::create([
'name' => $this
->randomString(),
]);
$form = $this->container
->get('entity.form_builder')
->getForm($entity);
$options = array_keys($form['langcode']['widget'][0]['value']['#options']);
$this
->assertSame([
'en',
'und',
'zxx',
], $options);
}
/**
* Tests the widget without the locked languages.
*/
public function testWithoutIncludedLockedLanguage() {
$this->entityFormDisplay
->setComponent('langcode', [
'type' => 'language_select',
'settings' => [
'include_locked' => FALSE,
],
])
->save();
$entity = EntityTest::create([
'name' => $this
->randomString(),
]);
$form = $this->container
->get('entity.form_builder')
->getForm($entity);
$options = array_keys($form['langcode']['widget'][0]['value']['#options']);
$this
->assertSame([
'en',
], $options);
}
}