public function MetadataGeneratorTest::testEditorWithCustomMetadata in Drupal 8
Same name and namespace in other branches
- 9 core/modules/quickedit/tests/src/Kernel/MetadataGeneratorTest.php \Drupal\Tests\quickedit\Kernel\MetadataGeneratorTest::testEditorWithCustomMetadata()
- 10 core/modules/quickedit/tests/src/Kernel/MetadataGeneratorTest.php \Drupal\Tests\quickedit\Kernel\MetadataGeneratorTest::testEditorWithCustomMetadata()
Tests a field whose associated in-place editor generates custom metadata.
File
- core/
modules/ quickedit/ tests/ src/ Kernel/ MetadataGeneratorTest.php, line 122
Class
- MetadataGeneratorTest
- Tests in-place field editing metadata.
Namespace
Drupal\Tests\quickedit\KernelCode
public function testEditorWithCustomMetadata() {
$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, [], 'text_textfield', [
'size' => 42,
], 'text_default', []);
// Create a text format.
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => [
'filter_htmlcorrector' => [
'status' => 1,
],
],
]);
$full_html_format
->save();
// Create an entity with values for this rich text field.
$entity = EntityTest::create();
$entity->{$field_name}->value = 'Test';
$entity->{$field_name}->format = 'full_html';
$entity
->save();
$entity = EntityTest::load($entity
->id());
// Verify metadata.
$items = $entity
->get($field_name);
$metadata = $this->metadataGenerator
->generateFieldMetadata($items, 'default');
$expected = [
'access' => TRUE,
'label' => 'Rich text field',
'editor' => 'wysiwyg',
'custom' => [
'format' => 'full_html',
],
];
$this
->assertEqual($expected, $metadata, 'The correct metadata (including custom metadata) is generated.');
}