You are here

function CDNImageTestCase::testOtherContentLink in CDN 7.2

File

tests/cdn.test, line 582
Test CDN.

Class

CDNImageTestCase

Code

function testOtherContentLink() {
  $cdn = 'http://cdn-a.com';
  $this
    ->variableSet(CDN_BASIC_MAPPING_VARIABLE, "{$cdn}|.png .pdf");
  $this
    ->variableSet(CDN_MODE_VARIABLE, CDN_MODE_BASIC);

  // Image altering type 1: "just image", i.e. "<img />".
  $template = function ($url) {
    return '<a href="' . $url . '">Download this!</a>';
  };

  // Simplest case possible.
  $a_url = base_path() . 'foo/bar/image.png';
  $html = $template($a_url);
  $html = cdn_post_render_html_alter($html);
  $this
    ->assertIdentical($template($cdn . $a_url), $html, 'Other content link correctly altered.');

  // Query strings should not be stripped.
  $a_url = base_path() . 'foo/bar/image.pdf?foobar';
  $html = $template($a_url);
  $html = cdn_post_render_html_alter($html);
  $this
    ->assertIdentical($template($cdn . $a_url), $html, 'Other content link correctly altered (query string not stripped).');

  // Edge case: a script generating an image is not (yet) supported.
  $a_url = base_path() . 'foo/bar/image.gif';
  $html = $template($a_url);
  $html = cdn_post_render_html_alter($html);
  $this
    ->assertIdentical($template($a_url), $html, 'Other content link correctly NOT altered (extension does not map).');

  // Edge case: a script generating an image is not (yet) supported.
  $a_url = base_path() . 'foo/bar/showimage?formula=12345.png';
  $html = $template($a_url);
  $html = cdn_post_render_html_alter($html);
  $this
    ->assertIdentical($template($a_url), $html, 'Other content link correctly NOT altered (extension not pulled from query string).');
}