You are here

public function FileFieldFormatterTest::testFileFieldFormatter in Entity Embed 7.3

Tests file field formatter Entity Embed Display plugin.

File

./entity_embed.test, line 633
Test integration for the entity_embed module.

Class

FileFieldFormatterTest
Tests the file field formatter provided by entity_embed.

Code

public function testFileFieldFormatter() {

  // Ensure that file field formatters are available as plugins.
  $this
    ->assertAvailableDisplayPlugins('file', array(
    'entityreference_label',
    'entityreference_entity_id',
    'entityreference_entity_view',
    'file_default',
    'file_table',
    'file_url_plain',
  ));

  // Ensure that correct form attributes are returned for the file_default plugin.
  $form = array();
  $form_state = form_state_defaults();
  $conf_form = entity_embed_field_info_formatter_settings('file', $this->file, 'file_default', array(), $form, $form_state);

  // Ensure that correct form attributes are returned for the file_default plugin.
  $this
    ->assertIdentical(array_keys($conf_form), array());

  // Test entity embed using 'Image' Entity Embed Display plugin.
  $content = '<drupal-entity data-entity-type="file" data-entity-id="' . $this->file->fid . '" data-entity-embed-display="file:file_default">This placeholder should not be rendered.</drupal-entity>';
  $settings = array();
  $settings['type'] = 'page';
  $settings['title'] = 'Test entity embed with image:image';
  $settings['body'] = array(
    LANGUAGE_NONE => array(
      array(
        'value' => $content,
        'format' => 'custom_format',
      ),
    ),
  );
  $node = $this
    ->drupalCreateNode($settings);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertNoText(strip_tags($content), 'Placeholder does not appears in the output when embed is successful.');
  $this
    ->assertLinkByHref(file_create_url($this->file->uri), 0, 'Link to the embedded file exists.');
}