3 namespace Drupal\Tests\language\Kernel;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests the language select widget.
13 class LanguageSelectWidgetTest extends KernelTestBase {
18 protected static $modules = [
26 * The entity form display.
28 * @var \Drupal\Core\Entity\Entity\EntityFormDisplay
30 protected $entityFormDisplay;
35 protected function setUp() {
38 $this->installEntitySchema('entity_test');
39 $this->installEntitySchema('user');
41 $storage = $this->container->get('entity_type.manager')->getStorage('entity_form_display');
42 $this->entityFormDisplay = $storage->create([
43 'targetEntityType' => 'entity_test',
44 'bundle' => 'entity_test',
51 * Tests the widget with the locked languages.
53 public function testWithIncludedLockedLanguage() {
54 $this->entityFormDisplay->setComponent('langcode', [
55 'type' => 'language_select',
57 $entity = EntityTest::create(['name' => $this->randomString()]);
58 $form = $this->container->get('entity.form_builder')->getForm($entity);
59 $options = array_keys($form['langcode']['widget'][0]['value']['#options']);
60 $this->assertSame(['en', 'und', 'zxx'], $options);
64 * Test the widget without the locked languages.
66 public function testWithoutIncludedLockedLanguage() {
67 $this->entityFormDisplay->setComponent('langcode', [
68 'type' => 'language_select',
69 'settings' => ['include_locked' => FALSE],
71 $entity = EntityTest::create(['name' => $this->randomString()]);
72 $form = $this->container->get('entity.form_builder')->getForm($entity);
73 $options = array_keys($form['langcode']['widget'][0]['value']['#options']);
74 $this->assertSame(['en'], $options);