function LinkEmbedFormatterTest::testLinkEmbedFormatter in URL Embed 8
Tests the 'url_embed' formatter.
File
- tests/
src/ Functional/ LinkEmbedFormatterTest.php, line 39
Class
- LinkEmbedFormatterTest
- Tests url_embed link field formatter.
Namespace
Drupal\Tests\url_embed\FunctionalCode
function testLinkEmbedFormatter() {
$field_name = mb_strtolower($this
->randomMachineName());
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'link',
'cardinality' => 2,
));
$this->fieldStorage
->save();
\Drupal::service('entity_type.manager')
->getStorage('field_config')
->create(array(
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
'settings' => array(
'title' => DRUPAL_OPTIONAL,
'link_type' => LinkItemInterface::LINK_GENERIC,
),
))
->save();
\Drupal::service('entity_display.repository')
->getFormDisplay('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'type' => 'link_default',
))
->save();
$display_options = array(
'type' => 'url_embed',
'label' => 'hidden',
);
\Drupal::service('entity_display.repository')
->getViewDisplay('entity_test', 'entity_test', 'full')
->setComponent($field_name, $display_options)
->save();
// Create an entity to test the embed formatter.
$url = UrlEmbedTestBase::FLICKR_URL;
$entity = EntityTest::create();
$entity
->set($field_name, $url);
$entity
->save();
// Render the entity and verify that the link is output as an embed.
$output = $this
->renderTestEntity($entity
->id());
$this
->assertStringContainsString(UrlEmbedTestBase::FLICKR_OUTPUT_FIELD, $output);
}