You are here

function ALProfilesWebTest::testThumbnailImage in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 acquia_lift_profiles/tests/acquia_lift_profiles.test \ALProfilesWebTest::testThumbnailImage()

File

acquia_lift_profiles/tests/acquia_lift_profiles.test, line 124
Tests for Acquia Lift Profiles module.

Class

ALProfilesWebTest
Tests Acquia Lift Profiles functionality.

Code

function testThumbnailImage() {
  $this
    ->configureALProfiles();
  $this
    ->drupalLogin($this->admin_user);

  // Create a new article node of this type.
  $test_image = current($this
    ->drupalGetTestFiles('image'));
  $edit = array(
    'title' => $this
      ->randomName(),
  );
  $edit['files[field_image_' . LANGUAGE_NONE . '_0]'] = drupal_realpath($test_image->uri);
  $this
    ->drupalPost('node/add/article', $edit, t('Save'));
  $nid = $this
    ->getNidFromCurrentUrl();
  $items = field_get_items('node', node_load($nid), 'field_image');
  $image_uri = $items[0]['uri'];

  // Verify that the image thumbnail is empty in the page context.
  $this
    ->drupalGet('node/' . $nid);
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertTrue($settings['acquia_lift_profiles']['pageContext']['thumbnail_url'] == '', 'Thumbnail image is blank');

  // Set the thumbnail fields for articles.
  $edit = array(
    'acquia_lift_profiles[thumbnail]' => 'field_image|image_image',
    'acquia_lift_profiles[style]' => 'thumbnail',
  );
  $this
    ->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));

  // Verify that the thumbnail is set (after stripping off the token).
  $token_regex = '/\\?itok=[a-zA-Z0-9]*/';
  $thumbnail_image = preg_replace($token_regex, '', image_style_url('thumbnail', $image_uri));
  $this
    ->drupalGet('node/' . $nid);
  $settings = $this
    ->drupalGetSettings();
  $settings_image = preg_replace($token_regex, '', $settings['acquia_lift_profiles']['pageContext']['thumbnail_url']);
  $this
    ->assertEqual($thumbnail_image, $settings_image);

  // Change the image style.
  $edit['acquia_lift_profiles[style]'] = 'medium';
  $this
    ->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));

  // Verify that the new image style appears in the page context.
  $this
    ->drupalGet('node/' . $nid);
  $thumbnail_image = preg_replace($token_regex, '', image_style_url('medium', $image_uri));
  $this
    ->drupalGet('node/' . $nid);
  $settings = $this
    ->drupalGetSettings();
  $settings_image = preg_replace($token_regex, '', $settings['acquia_lift_profiles']['pageContext']['thumbnail_url']);
  $this
    ->assertEqual($thumbnail_image, $settings_image);

  // Create an article without an image.
  $edit = array(
    'title' => $this
      ->randomName(),
  );
  $this
    ->drupalPost('node/add/article', $edit, t('Save'));
  $second_nid = $this
    ->getNidFromCurrentUrl();

  // Verify that the image is blank in the page context.
  $this
    ->drupalGet('node/' . $second_nid);
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertTrue($settings['acquia_lift_profiles']['pageContext']['thumbnail_url'] == '', 'Thumbnail image is blank');

  // Verify image is not passed on node aggregate pages.
  $this
    ->drupalGet('node');
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertTrue(!isset($settings['acquia_lift_profiles']['pageContext']['thumbnail_url']), 'Thumbnail image is not set');

  // Remove the thumbnail setting.
  $edit = array(
    'acquia_lift_profiles[thumbnail]' => '',
  );
  $this
    ->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));

  // Verify that no thumbnail is passed in page context.
  $this
    ->drupalGet('node/' . $nid);
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertTrue($settings['acquia_lift_profiles']['pageContext']['thumbnail_url'] == '', 'Thumbnail image is blank');
}