You are here

public function MediaWYSIWYGRenderMacrosTest::testEmptyField in D7 Media 7.4

Same name and namespace in other branches
  1. 7.2 modules/media_wysiwyg/tests/media_wysiwyg.macro.test \MediaWYSIWYGRenderMacrosTest::testEmptyField()
  2. 7.3 modules/media_wysiwyg/tests/media_wysiwyg.macro.test \MediaWYSIWYGRenderMacrosTest::testEmptyField()

Test that displayed fields on file entity are rendered correctly.

File

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

Class

MediaWYSIWYGRenderMacrosTest
Defines rendered media macros test cases.

Code

public function testEmptyField() {

  // Add a field as part of the rendered macro.
  $edit = array(
    'fields[field_file_image_title_text][type]' => 'text_default',
  );
  $this
    ->drupalPost('admin/structure/file-types/manage/image/display/preview', $edit, t('Save'));

  // Assert that fields that are enabled in display settings for macro are NOT
  // rendered if empty.
  $files = $this
    ->drupalGetTestFiles('image');
  $attributes = array(
    'alt' => $this
      ->randomName(),
    'title' => '',
  );
  $fields = array(
    'field_file_image_alt_text[und][0][value]' => $attributes['alt'],
    'field_file_image_title_text[und][0][value]' => $attributes['title'],
  );
  $files[0]->field_file_image_alt_text[LANGUAGE_NONE][0]['value'] = $attributes['alt'];
  $files[0]->field_file_image_title_text[LANGUAGE_NONE][0]['value'] = $attributes['title'];
  $file = file_save($files[0]);
  $nid = $this
    ->createNode($file->fid, $attributes, $fields);
  $this
    ->drupalGet('node/' . $nid);

  // Assert that the empty field isn't rendered.
  $this
    ->assertNoPattern('|<div class="[^">]*field-name-field-file-image-title-text|', t('Displayed text field with empty value not rendered.'));
}