LanguageSelectWidgetTest.php in Drupal 10
File
core/modules/language/tests/src/Kernel/LanguageSelectWidgetTest.php
View source
<?php
namespace Drupal\Tests\language\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
class LanguageSelectWidgetTest extends KernelTestBase {
protected static $modules = [
'entity_test',
'language',
'user',
'system',
];
protected $entityFormDisplay;
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,
]);
}
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);
}
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);
}
}