You are here

class OembedFileEntityTestCase in oEmbed 8

Same name and namespace in other branches
  1. 7 oembed.test \OembedFileEntityTestCase
  2. 7.0 oembed.test \OembedFileEntityTestCase

Hierarchy

Expanded class hierarchy of OembedFileEntityTestCase

File

./oembed.test, line 144
Tests for oembed.module.

View source
class OembedFileEntityTestCase extends OembedTestHelper {
  function setUp() {
    parent::setUp(array(
      'file_entity',
      'image',
    ));
  }
  public static function getInfo() {
    return array(
      'name' => 'File entity oEmbed',
      'description' => 'Tests oEmbed + File entity integration.',
      'group' => 'oEmbed',
    );
  }

  /**
   * Tests the oembed render element types.
   */
  function testOembedFileFormatters() {
    foreach ($this->urls as $url => $info) {

      // Every URL should render through the oEmbed formatter.
      $file = oembed_url_to_file($url, TRUE);
      $displays = array(
        'oembed' => array(
          'status' => TRUE,
          'weight' => 1,
          'settings' => array(),
        ),
      );
      $element = file_view_file($file, $displays);
      $this
        ->assertRenderedElement($element, '//*');

      // Only responses with thumbnails will render through the oembed_thumbnail
      // formatter. Rendered elements are always images.
      if (isset($info['thumbnail']) && $info['thumbnail']) {
        $displays = array(
          'oembed_thumbnail' => array(
            'status' => TRUE,
            'weight' => 1,
            'settings' => array(),
          ),
        );
        $element = file_view_file($file, $displays);
        $this
          ->assertRenderedElement($element, '//img');
      }

      // If a response is a photo or has a thumbnail, it should always render
      // an image here.
      if ($info['type'] == 'photo' || isset($info['thumbnail']) && $info['thumbnail']) {
        $displays = array(
          'oembed_thumbnail' => array(
            'status' => TRUE,
            'weight' => 1,
            'settings' => array(),
          ),
          'oembed' => array(
            'status' => TRUE,
            'weight' => 2,
            'settings' => array(),
          ),
        );
        $element = file_view_file($file, $displays);
        $this
          ->assertRenderedElement($element, '//img');
      }
    }
  }

  /**
   * Tests the oembed render element types.
   */
  function testOembedImageFileFormatters() {
    foreach ($this->urls as $url => $info) {

      // If a response is a photo or has a thumbnail, it should always render
      // an image here.
      $file = oembed_url_to_file($url, TRUE);
      if ($info['type'] == 'photo' || isset($info['thumbnail']) && $info['thumbnail']) {
        foreach (array_keys(image_styles()) as $style_name) {
          $displays = array(
            'oembed_image' => array(
              'status' => TRUE,
              'weight' => 1,
              'settings' => array(
                'image_style' => $style_name,
                'alt' => '',
                'title' => '',
              ),
            ),
          );
          $element = file_view_file($file, $displays);
          $this
            ->assertRenderedElement($element, '//img');
          $url = image_style_url($style_name, $element['#path']);
          $this
            ->drupalGet($url);
          $this
            ->assertResponse(200, t('Image was generated at the URL.'));
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OembedFileEntityTestCase::getInfo public static function
OembedFileEntityTestCase::setUp function Overrides OembedTestHelper::setUp
OembedFileEntityTestCase::testOembedFileFormatters function Tests the oembed render element types.
OembedFileEntityTestCase::testOembedImageFileFormatters function Tests the oembed render element types.
OembedTestHelper::$profile protected property
OembedTestHelper::$urls protected property
OembedTestHelper::assertFileEntityAccess function Asserts file_entity_access correctly grants or denies access.
OembedTestHelper::assertRenderedElement protected function
OembedTestHelper::xpathArgsFromAttributes protected function