Version 1
[yaffs-website] / web / core / modules / options / tests / src / Kernel / Views / ViewsDataTest.php
1 <?php
2
3 namespace Drupal\Tests\options\Kernel\Views;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7
8 /**
9  * Test to ensure views data is properly created for the Options module.
10  *
11  * @group views
12  */
13 class ViewsDataTest extends OptionsTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['options', 'options_test', 'entity_test', 'views'];
19
20   /**
21    * The field storage.
22    *
23    * @var \Drupal\Core\Field\FieldStorageDefinitionInterface
24    */
25   protected $fieldStorage;
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp($import_test_views = TRUE) {
31     parent::setUp();
32
33     $field_name = 'test_options';
34     $this->fieldStorage = FieldStorageConfig::create([
35       'field_name' => $field_name,
36       'entity_type' => 'entity_test',
37       'type' => 'list_string',
38       'cardinality' => 1,
39       'settings' => [
40         'allowed_values_function' => 'options_test_dynamic_values_callback',
41       ],
42     ]);
43     $this->fieldStorage->save();
44
45     $this->field = FieldConfig::create([
46       'field_name' => $field_name,
47       'entity_type' => 'entity_test',
48       'bundle' => 'entity_test',
49       'required' => TRUE,
50     ])->save();
51   }
52
53   /**
54    * Tests the option module's implementation of hook_field_views_data().
55    */
56   public function testOptionsFieldViewsData() {
57     $field_data = \Drupal::service('views.views_data')->get('entity_test__test_options');
58
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.');
63   }
64
65 }