function EditIntegrationTest::testMetadata

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

File

drupal/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php, line 149
Contains \Drupal\editor\Tests\EditorIntegrationTest.

Class

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

Namespace

Drupal\editor\Tests

Code

function testMetadata() {
  $this->editorManager = new InPlaceEditorManager($this->container
    ->get('container.namespaces'));
  $this->accessChecker = new MockEditEntityFieldAccessCheck();
  $this->editorSelector = new EditorSelector($this->editorManager);
  $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);

  // Create an entity with values for the field.
  $this->entity = entity_create('entity_test', array());
  $this->entity->{$this->field_name}->value = 'Test';
  $this->entity->{$this->field_name}->format = 'full_html';
  $this->entity
    ->save();
  $entity = entity_load('entity_test', $this->entity
    ->id());

  // Verify metadata.
  $instance = field_info_instance($entity
    ->entityType(), $this->field_name, $entity
    ->bundle());
  $metadata = $this->metadataGenerator
    ->generate($entity, $instance, Language::LANGCODE_NOT_SPECIFIED, 'default');
  $expected = array(
    'access' => TRUE,
    'label' => 'Long text field',
    'editor' => 'editor',
    'aria' => 'Entity entity_test 1, field Long text field',
    'custom' => array(
      'format' => 'full_html',
      'formatHasTransformations' => FALSE,
    ),
  );
  $this
    ->assertEqual($expected, $metadata, 'The correct metadata (including custom metadata) is generated.');
}