public function MetadataGeneratorTest::testEditorWithCustomMetadata in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/quickedit/src/Tests/MetadataGeneratorTest.php \Drupal\quickedit\Tests\MetadataGeneratorTest::testEditorWithCustomMetadata()
Tests a field whose associated in-place editor generates custom metadata.
File
- core/
modules/ quickedit/ src/ Tests/ MetadataGeneratorTest.php, line 125 - Contains \Drupal\quickedit\Tests\MetadataGeneratorTest.
Class
- MetadataGeneratorTest
- Tests in-place field editing metadata.
Namespace
Drupal\quickedit\TestsCode
public function testEditorWithCustomMetadata() {
$this
->installSchema('system', 'url_alias');
$this->editorManager = $this->container
->get('plugin.manager.quickedit.editor');
$this->editorSelector = new EditorSelector($this->editorManager, $this->container
->get('plugin.manager.field.formatter'));
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
$this->editorManager = $this->container
->get('plugin.manager.quickedit.editor');
$this->editorSelector = new EditorSelector($this->editorManager, $this->container
->get('plugin.manager.field.formatter'));
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create a rich text field.
$field_name = 'field_rich';
$field_label = 'Rich text field';
$this
->createFieldWithStorage($field_name, 'text', 1, $field_label, array(), 'text_textfield', array(
'size' => 42,
), 'text_default', array());
// Create a text format.
$full_html_format = entity_create('filter_format', array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(
'filter_htmlcorrector' => array(
'status' => 1,
),
),
));
$full_html_format
->save();
// Create an entity with values for this rich text field.
$entity = entity_create('entity_test');
$entity->{$field_name}->value = 'Test';
$entity->{$field_name}->format = 'full_html';
$entity
->save();
$entity = entity_load('entity_test', $entity
->id());
// Verify metadata.
$items = $entity
->get($field_name);
$metadata = $this->metadataGenerator
->generateFieldMetadata($items, 'default');
$expected = array(
'access' => TRUE,
'label' => 'Rich text field',
'editor' => 'wysiwyg',
'custom' => array(
'format' => 'full_html',
),
);
$this
->assertEqual($expected, $metadata);
//, 'The correct metadata (including custom metadata) is generated.');
}