You are here

function ImagecacheExternalTestCase::testCachingExternalImage in Imagecache External 7.2

Same name and namespace in other branches
  1. 8 imagecache_external.test \ImagecacheExternalTestCase::testCachingExternalImage()

Test caching an external image.

1 call to ImagecacheExternalTestCase::testCachingExternalImage()
ImagecacheExternalTestCase::testCachingExternalImageUsingWhitelist in ./imagecache_external.test
Test caching an external image using the whitelist.

File

./imagecache_external.test, line 129
Tests for Imagecache External.

Class

ImagecacheExternalTestCase
Tests the functions for working with public/private file schemes.

Code

function testCachingExternalImage() {

  // Create a text field that uses the new style for rendering the image.
  $field_name = strtolower($this
    ->randomName(10));
  $this
    ->createTextField($field_name, 'article');
  $instance = field_info_instance('node', $field_name, 'article');
  $instance['display']['default']['type'] = 'imagecache_external_image';
  $instance['display']['default']['settings']['imagecache_external_style'] = 'thumbnail';
  field_update_instance($instance);

  // Create a new node with an image attached.
  $nid = $this
    ->addNodeImage($this->external_image['url'], $field_name, 'article');
  if ($this->external_image['width'] > $this->external_image['height']) {
    $width = 100;
    $height = ceil(100 * ($this->external_image['height'] / $this->external_image['width']));
  }
  else {
    $height = 100;
    $width = ceil(100 * ($this->external_image['width'] / $this->external_image['height']));
  }

  // Test that image is displayed using newly created style.
  $this
    ->drupalGet('node/' . $nid);
  $img_tag = theme('imagecache_external', array(
    'style_name' => 'thumbnail',
    'path' => $this->external_image['url'],
    'width' => $width,
    'height' => $height,
  ));
  $this
    ->assertRaw($img_tag, t('Image was successfully cached as %path.', array(
    '%path' => $img_tag,
  )));
}