Mercurial > hg > isophonics-drupal-site
comparison core/modules/options/tests/src/Kernel/OptionsFieldUnitTestBase.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\options\Kernel; | |
4 | |
5 use Drupal\field\Entity\FieldConfig; | |
6 use Drupal\Tests\field\Kernel\FieldKernelTestBase; | |
7 use Drupal\field\Entity\FieldStorageConfig; | |
8 | |
9 /** | |
10 * Base class for Options module integration tests. | |
11 */ | |
12 abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase { | |
13 | |
14 /** | |
15 * Modules to enable. | |
16 * | |
17 * @var array | |
18 */ | |
19 public static $modules = ['options']; | |
20 | |
21 /** | |
22 * The field name used in the test. | |
23 * | |
24 * @var string | |
25 */ | |
26 protected $fieldName = 'test_options'; | |
27 | |
28 /** | |
29 * The field storage definition used to created the field storage. | |
30 * | |
31 * @var array | |
32 */ | |
33 protected $fieldStorageDefinition; | |
34 | |
35 /** | |
36 * The list field storage used in the test. | |
37 * | |
38 * @var \Drupal\field\Entity\FieldStorageConfig | |
39 */ | |
40 protected $fieldStorage; | |
41 | |
42 /** | |
43 * The list field used in the test. | |
44 * | |
45 * @var \Drupal\field\Entity\FieldConfig | |
46 */ | |
47 protected $field; | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 protected function setUp() { | |
53 parent::setUp(); | |
54 $this->container->get('router.builder')->rebuild(); | |
55 | |
56 $this->fieldStorageDefinition = [ | |
57 'field_name' => $this->fieldName, | |
58 'entity_type' => 'entity_test', | |
59 'type' => 'list_integer', | |
60 'cardinality' => 1, | |
61 'settings' => [ | |
62 'allowed_values' => [1 => 'One', 2 => 'Two', 3 => 'Three'], | |
63 ], | |
64 ]; | |
65 $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition); | |
66 $this->fieldStorage->save(); | |
67 | |
68 $this->field = FieldConfig::create([ | |
69 'field_storage' => $this->fieldStorage, | |
70 'bundle' => 'entity_test', | |
71 ]); | |
72 $this->field->save(); | |
73 | |
74 entity_get_form_display('entity_test', 'entity_test', 'default') | |
75 ->setComponent($this->fieldName, [ | |
76 'type' => 'options_buttons', | |
77 ]) | |
78 ->save(); | |
79 } | |
80 | |
81 } |