You are here

public function MetatagCoreImageTest::testConfigProtocolRelativeURL in Metatag 7

Confirm images can be added to a global config w its protocol-relative URL.

File

tests/MetatagCoreImageTest.test, line 155
Tests for the Metatag module to ensure image handling doesn't break.

Class

MetatagCoreImageTest
Tests for the Metatag module to ensure image handling doesn't break.

Code

public function testConfigProtocolRelativeURL() {

  // Generate a test image.
  $image_uri = $this
    ->generateImage();
  $this
    ->verbose($image_uri);

  // Work out the web-accessible URL for this image.
  $image_url = file_create_url($image_uri);

  // Make the URL protocol-relative.
  $relative_url = str_replace('http://', '//', $image_url);

  // Update the global config to add an image meta tag.
  $config = metatag_config_load('global');
  $config->config['image_src']['value'] = $relative_url;
  metatag_config_save($config);

  // Dump out the current config, to aid with debugging.
  $this
    ->verbose($config);

  // Load the front page.
  $this
    ->drupalGet('<front>');
  $this
    ->assertResponse(200);

  // Confirm that the image_src meta tag has the expected values.
  $xpath = $this
    ->xpath("//link[@rel='image_src']");
  $this
    ->assertEqual(count($xpath), 1, 'One image_src meta tag found.');
  $this
    ->assertEqual($xpath[0]['href'], $relative_url, 'The image_src meta tag with a protocol-relative URL is being output correctly.');
  $this
    ->assertNotEqual($xpath[0]['href'], $image_url, 'The image_src meta tag does not contain the absolute URL.');
}