function FieldTest::testDefineOptionsWithDefaultFormatterOnFieldType

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testDefineOptionsWithDefaultFormatterOnFieldType()
  2. 10 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testDefineOptionsWithDefaultFormatterOnFieldType()
  3. 11.x core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testDefineOptionsWithDefaultFormatterOnFieldType()

@covers ::defineOptions

File

core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php, line 192

Class

FieldTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21field%21EntityField.php/class/EntityField/8.9.x" title="A field that displays entity field data." class="local">\Drupal\views\Plugin\views\field\EntityField</a> @group views

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public function testDefineOptionsWithDefaultFormatterOnFieldType() {
    $definition = [
        'entity_type' => 'test_entity',
        'field_name' => 'title',
        'default_formatter_settings' => [
            'link_to_entity' => TRUE,
        ],
    ];
    $handler = new EntityField([], 'field', $definition, $this->entityTypeManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer, $this->entityRepository, $this->entityFieldManager);
    // Setup the entity manager to allow fetching the storage definitions.
    $title_storage = $this->getBaseFieldStorage();
    $this->entityFieldManager
        ->expects($this->atLeastOnce())
        ->method('getFieldStorageDefinitions')
        ->with('test_entity')
        ->willReturn([
        'title' => $title_storage,
    ]);
    $options = [];
    $handler->init($this->executable, $this->display, $options);
    $this->assertEquals([
        'link_to_entity' => TRUE,
    ], $handler->options['settings']);
}

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