You are here

public function FieldWidgetDisplayTest::testDefaultConfiguration in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/Plugin/FieldWidgetDisplayTest.php \Drupal\Tests\entity_browser\Kernel\Plugin\FieldWidgetDisplayTest::testDefaultConfiguration()

Test field widget display plugins configuration and dependencies.

File

tests/src/Kernel/Plugin/FieldWidgetDisplayTest.php, line 52

Class

FieldWidgetDisplayTest
Tests field widget display plugins.

Namespace

Drupal\Tests\entity_browser\Kernel\Plugin

Code

public function testDefaultConfiguration() {

  // Check default configuration for image thumbnail plugin.
  $image_thumbnail_plugin = $this->pluginManager
    ->createInstance('thumbnail');
  $this
    ->assertEquals([
    'image_style' => 'thumbnail',
  ], $image_thumbnail_plugin
    ->defaultConfiguration());
  $this
    ->assertEquals([
    'image_style' => 'thumbnail',
  ], $image_thumbnail_plugin
    ->getConfiguration());
  $this
    ->assertEquals([
    'config' => [
      0 => 'image.style.thumbnail',
    ],
  ], $image_thumbnail_plugin
    ->calculateDependencies());

  // Set configuration different then default.
  $image_thumbnail_plugin
    ->setConfiguration([
    'image_style' => 'large',
  ]);
  $this
    ->assertEquals([
    'image_style' => 'thumbnail',
  ], $image_thumbnail_plugin
    ->defaultConfiguration());
  $this
    ->assertEquals([
    'image_style' => 'large',
  ], $image_thumbnail_plugin
    ->getConfiguration());
  $this
    ->assertEquals([
    'config' => [
      0 => 'image.style.large',
    ],
  ], $image_thumbnail_plugin
    ->calculateDependencies());

  // Check default configuration for rendered entity plugin.
  $rendered_entity_plugin = $this->pluginManager
    ->createInstance('rendered_entity', [
    'entity_type' => 'comment',
  ]);
  $this
    ->assertEquals([
    'view_mode' => 'default',
  ], $rendered_entity_plugin
    ->defaultConfiguration());
  $this
    ->assertEquals([
    'view_mode' => 'default',
    'entity_type' => 'comment',
  ], $rendered_entity_plugin
    ->getConfiguration());
  $this
    ->assertEquals([], $rendered_entity_plugin
    ->calculateDependencies());

  // Set configuration different then default.
  $rendered_entity_plugin
    ->setConfiguration([
    'entity_type' => 'comment',
    'view_mode' => 'full',
  ]);
  $this
    ->assertEquals([
    'view_mode' => 'default',
  ], $rendered_entity_plugin
    ->defaultConfiguration());
  $this
    ->assertEquals([
    'view_mode' => 'full',
    'entity_type' => 'comment',
  ], $rendered_entity_plugin
    ->getConfiguration());
  $this
    ->assertEquals([
    'config' => [
      0 => 'core.entity_view_mode.comment.full',
    ],
  ], $rendered_entity_plugin
    ->calculateDependencies());
}