ViewsDataTest.php

Same filename in this branch
  1. 8.9.x core/modules/views/tests/src/Unit/ViewsDataTest.php
Same filename in other branches
  1. 9 core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php
  2. 9 core/modules/views/tests/src/Unit/ViewsDataTest.php
  3. 10 core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php
  4. 10 core/modules/views/tests/src/Unit/ViewsDataTest.php
  5. 10 core/modules/views/tests/src/Kernel/ViewsDataTest.php
  6. 11.x core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php
  7. 11.x core/modules/views/tests/src/Unit/ViewsDataTest.php
  8. 11.x core/modules/views/tests/src/Kernel/ViewsDataTest.php

Namespace

Drupal\Tests\options\Kernel\Views

File

core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php

View source
<?php

namespace Drupal\Tests\options\Kernel\Views;

use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;

/**
 * Test to ensure views data is properly created for the Options module.
 *
 * @group views
 */
class ViewsDataTest extends OptionsTestBase {
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'options',
        'options_test',
        'entity_test',
        'views',
    ];
    
    /**
     * The field storage.
     *
     * @var \Drupal\Core\Field\FieldStorageDefinitionInterface
     */
    protected $fieldStorage;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp($import_test_views = TRUE) {
        parent::setUp();
        $this->installEntitySchema('entity_test');
        $field_name = 'test_options';
        $this->fieldStorage = FieldStorageConfig::create([
            'field_name' => $field_name,
            'entity_type' => 'entity_test',
            'type' => 'list_string',
            'cardinality' => 1,
            'settings' => [
                'allowed_values_function' => 'options_test_dynamic_values_callback',
            ],
        ]);
        $this->fieldStorage
            ->save();
        $this->field = FieldConfig::create([
            'field_name' => $field_name,
            'entity_type' => 'entity_test',
            'bundle' => 'entity_test',
            'required' => TRUE,
        ])->save();
    }
    
    /**
     * Tests the option module's implementation of hook_field_views_data().
     */
    public function testOptionsFieldViewsData() {
        $field_data = \Drupal::service('views.views_data')->get('entity_test__test_options');
        // Check that the options module has properly overridden default views data.
        $test_options_field = $field_data['test_options_value'];
        $this->assertEqual($test_options_field['argument']['id'], 'string_list_field', 'Argument handler is properly set for fields with allowed value callbacks.');
        $this->assertEqual($test_options_field['filter']['id'], 'list_field', 'Filter handler is properly set for fields with allowed value callbacks.');
    }

}

Classes

Title Deprecated Summary
ViewsDataTest Test to ensure views data is properly created for the Options module.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.