You are here

public function QuickEditIntegrationTest::testMetadata in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/editor/src/Tests/QuickEditIntegrationTest.php \Drupal\editor\Tests\QuickEditIntegrationTest::testMetadata()

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

File

core/modules/editor/src/Tests/QuickEditIntegrationTest.php, line 157
Contains \Drupal\editor\Tests\QuickEditIntegrationTest.

Class

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

Namespace

Drupal\editor\Tests

Code

public function testMetadata() {
  $this->editorManager = $this->container
    ->get('plugin.manager.quickedit.editor');
  $this->accessChecker = new MockEditEntityFieldAccessCheck();
  $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 = entity_create('entity_test');
  $entity->{$this->fieldName}->value = 'Test';
  $entity->{$this->fieldName}->format = 'full_html';
  $entity
    ->save();
  $entity = entity_load('entity_test', $entity
    ->id());

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