You are here

public function MediaWYSIWYGWYSIWYGOverridesTest::testAttributeOverrides in D7 Media 7.2

Same name and namespace in other branches
  1. 7.4 modules/media_wysiwyg/tests/media_wysiwyg.macro.test \MediaWYSIWYGWYSIWYGOverridesTest::testAttributeOverrides()
  2. 7.3 modules/media_wysiwyg/tests/media_wysiwyg.macro.test \MediaWYSIWYGWYSIWYGOverridesTest::testAttributeOverrides()

Test image media overrides.

File

modules/media_wysiwyg/tests/media_wysiwyg.macro.test, line 108
Tests for ensuring media macros render properly.

Class

MediaWYSIWYGWYSIWYGOverridesTest
Defines media macro override test cases.

Code

public function testAttributeOverrides() {
  $files = $this
    ->drupalGetTestFiles('image');
  $file = file_save($files[0]);

  // Create a node to test with.
  $nid = $this
    ->createNode($file->fid);
  $this
    ->drupalGet('node/' . $nid);
  $this
    ->assertRaw('width="100"', t('Image displays with default width attribute.'));
  $this
    ->assertRaw('height="100"', t('Image displays with default height attribute.'));

  // Create a node with a style attribute.
  $attributes = array(
    'style' => 'float: left; width: 50px;',
  );
  $nid = $this
    ->createNode($file->fid, $attributes);
  $this
    ->drupalGet('node/' . $nid);
  $this
    ->assertRaw(drupal_attributes($attributes), t('Image displays with overriden attributes.'));

  // Create a node with overriden alt/title attributes.
  $attributes = array(
    'alt' => $this
      ->randomName(),
    'title' => $this
      ->randomName(),
  );
  $nid = $this
    ->createNode($file->fid, $attributes);
  $this
    ->drupalGet('node/' . $nid);
  $this
    ->assertRaw(drupal_attributes($attributes), t('Image displays with alt/title set as attributes.'));

  // Create a node with overriden alt/title fields.
  $fields = $attributes = array();
  $attributes['alt'] = $fields['field_file_image_alt_text[und][0][value]'] = $this
    ->randomName();
  $attributes['title'] = $fields['field_file_image_title_text[und][0][value]'] = $this
    ->randomName();
  $nid = $this
    ->createNode($file->fid, array(), $fields);
  $this
    ->drupalGet('node/' . $nid);

  // Ensure that the alt/title from attributes display.
  $this
    ->assertRaw(drupal_attributes($attributes), t('Image displays with alt/title set as fields.'));

  // Create a node with overriden alt/title fields as well as attributes.
  $attributes = array(
    'alt' => $this
      ->randomName(),
    'title' => $this
      ->randomName(),
  );
  $fields = array(
    'field_file_image_alt_text[und][0][value]' => $this
      ->randomName(),
    'field_file_image_title_text[und][0][value]' => $this
      ->randomName(),
  );
  $nid = $this
    ->createNode($file->fid, $attributes, $fields);
  $this
    ->drupalGet('node/' . $nid);

  // Ensure that the alt/title from attributes display rather the field ones.
  $this
    ->assertRaw(drupal_attributes($attributes), t('Image displays with alt/title set as attributes overriding field values.'));
}