Mercurial > hg > isophonics-drupal-site
comparison core/modules/language/tests/src/Kernel/LanguageSelectWidgetTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\language\Kernel; | |
4 | |
5 use Drupal\entity_test\Entity\EntityTest; | |
6 use Drupal\KernelTests\KernelTestBase; | |
7 | |
8 /** | |
9 * Tests the language select widget. | |
10 * | |
11 * @group language | |
12 */ | |
13 class LanguageSelectWidgetTest extends KernelTestBase { | |
14 | |
15 /** | |
16 * {@inheritdoc} | |
17 */ | |
18 protected static $modules = [ | |
19 'entity_test', | |
20 'language', | |
21 'user', | |
22 'system', | |
23 ]; | |
24 | |
25 /** | |
26 * The entity form display. | |
27 * | |
28 * @var \Drupal\Core\Entity\Entity\EntityFormDisplay | |
29 */ | |
30 protected $entityFormDisplay; | |
31 | |
32 /** | |
33 * {@inheritdoc} | |
34 */ | |
35 protected function setUp() { | |
36 parent::setUp(); | |
37 | |
38 $this->installEntitySchema('entity_test'); | |
39 $this->installEntitySchema('user'); | |
40 | |
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', | |
45 'mode' => 'default', | |
46 'status' => TRUE, | |
47 ]); | |
48 } | |
49 | |
50 /** | |
51 * Tests the widget with the locked languages. | |
52 */ | |
53 public function testWithIncludedLockedLanguage() { | |
54 $this->entityFormDisplay->setComponent('langcode', [ | |
55 'type' => 'language_select', | |
56 ])->save(); | |
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); | |
61 } | |
62 | |
63 /** | |
64 * Test the widget without the locked languages. | |
65 */ | |
66 public function testWithoutIncludedLockedLanguage() { | |
67 $this->entityFormDisplay->setComponent('langcode', [ | |
68 'type' => 'language_select', | |
69 'settings' => ['include_locked' => FALSE], | |
70 ])->save(); | |
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); | |
75 } | |
76 | |
77 } |