You are here

function OembedProviderTestCase::testOembedProviders in oEmbed 7

Same name and namespace in other branches
  1. 8 modules/oembedprovider/oembedprovider.test \OembedProviderTestCase::testOembedProviders()
  2. 7.0 oembedprovider/oembedprovider.test \OembedProviderTestCase::testOembedProviders()

File

modules/oembedprovider/oembedprovider.test, line 17

Class

OembedProviderTestCase

Code

function testOembedProviders() {
  ctools_include('plugins');
  $file = current($this
    ->drupalGetTestFiles('image'));
  $file->uid = 1;
  $file->status = FILE_STATUS_PERMANENT;
  file_save($file);
  $account = drupal_anonymous_user();
  $this
    ->assertFileEntityAccess(array(
    'view' => TRUE,
  ), $file, $account);
  $url = url('file/' . $file->fid, array(
    'absolute' => TRUE,
  ));
  $plugin = ctools_get_plugins('oembed', 'providers', 'file');
  $matches = array(
    1 => $file->fid,
  );
  $embed = oembed_oembed_fetch($plugin, $url, $matches);
  $errors = oembed_validate_response($embed);
  $this
    ->assertTrue(empty($errors), 'oEmbed response is valid');
  $output = theme('oembed__photo', array(
    'embed' => $embed,
  ));
  $vars = array(
    'path' => $file->uri,
    'alt' => oembed_alt_attr($embed),
    'width' => $file->image_dimensions['width'],
    'height' => $file->image_dimensions['height'],
  );
  $this
    ->assertEqual($output, theme('image', $vars), t('Expected img tag was found.'));
  $node = $this
    ->drupalCreateNode();
  $this
    ->assertTrue(node_load($node->nid), t('Node created.'));
  $url = url('node/' . $node->nid, array(
    'absolute' => TRUE,
  ));
  $plugin = ctools_get_plugins('oembed', 'providers', 'node');
  $matches = array(
    1 => $node->nid,
  );
  $embed = oembed_oembed_fetch($plugin, $url, $matches);
  $errors = oembed_validate_response($embed);
  $this
    ->assertTrue(empty($errors), 'oEmbed response is valid');
  $output = theme('oembed__rich', array(
    'embed' => $embed,
  ));
  $node = node_load($node->nid);
  $compare = node_view($node);
  $this
    ->assertEqual($output, render($compare), t('oEmbed node matches theme output.'));
}