3 namespace Drupal\Tests\options\Kernel\Views;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
9 * Test to ensure views data is properly created for the Options module.
13 class ViewsDataTest extends OptionsTestBase {
18 public static $modules = ['options', 'options_test', 'entity_test', 'views'];
23 * @var \Drupal\Core\Field\FieldStorageDefinitionInterface
25 protected $fieldStorage;
30 protected function setUp($import_test_views = TRUE) {
33 $field_name = 'test_options';
34 $this->fieldStorage = FieldStorageConfig::create([
35 'field_name' => $field_name,
36 'entity_type' => 'entity_test',
37 'type' => 'list_string',
40 'allowed_values_function' => 'options_test_dynamic_values_callback',
43 $this->fieldStorage->save();
45 $this->field = FieldConfig::create([
46 'field_name' => $field_name,
47 'entity_type' => 'entity_test',
48 'bundle' => 'entity_test',
54 * Tests the option module's implementation of hook_field_views_data().
56 public function testOptionsFieldViewsData() {
57 $field_data = \Drupal::service('views.views_data')->get('entity_test__test_options');
59 // Check that the options module has properly overridden default views data.
60 $test_options_field = $field_data['test_options_value'];
61 $this->assertEqual($test_options_field['argument']['id'], 'string_list_field', 'Argument handler is properly set for fields with allowed value callbacks.');
62 $this->assertEqual($test_options_field['filter']['id'], 'list_field', 'Filter handler is properly set for fields with allowed value callbacks.');