You are here

public function EditorIntegrationTest::testMetadata in Drupal 9

Tests (custom) metadata when the formatted text editor is used.

File

core/modules/quickedit/tests/src/Kernel/EditorIntegrationTest.php, line 167

Class

EditorIntegrationTest
Tests Edit module integration (Editor module's inline editing support).

Namespace

Drupal\Tests\quickedit\Kernel

Code

public function testMetadata() {
  $this->editorManager = $this->container
    ->get('plugin.manager.quickedit.editor');
  $this->accessChecker = new MockQuickEditEntityFieldAccessCheck();
  $this->editorSelector = $this->container
    ->get('quickedit.editor.selector');
  $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);

  // Create an entity with values for the field.
  $entity = EntityTest::create();
  $entity->{$this->fieldName}->value = 'Test';
  $entity->{$this->fieldName}->format = 'full_html';
  $entity
    ->save();
  $entity = EntityTest::load($entity
    ->id());

  // Verify metadata.
  $items = $entity
    ->get($this->fieldName);
  $metadata = $this->metadataGenerator
    ->generateFieldMetadata($items, 'default');
  $expected = [
    'access' => TRUE,
    'label' => 'Long text field',
    'editor' => 'editor',
    'custom' => [
      'format' => 'full_html',
      'formatHasTransformations' => FALSE,
    ],
  ];
  $this
    ->assertEquals($expected, $metadata, 'The correct metadata (including custom metadata) is generated.');
}