public function MediaWYSIWYGWYSIWYGOverridesTest::testAttributeOverrides in D7 Media 7.4
Same name and namespace in other branches
- 7.2 modules/media_wysiwyg/tests/media_wysiwyg.macro.test \MediaWYSIWYGWYSIWYGOverridesTest::testAttributeOverrides()
- 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 media token with a style attribute and assert that it is
// rendered.
$attributes = array(
'style' => 'width: 50px;',
);
$nid = $this
->createNode($file->fid, $attributes);
$this
->drupalGet('node/' . $nid);
$this
->assertPattern('|<img[^>]* style="[^">]*width: *50px|', t("Image displays with overridden 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.'));
}