You are here

function FileEntityAttributeOverrideTestCase::testFileEntityFileAttributeOverrides in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.test \FileEntityAttributeOverrideTestCase::testFileEntityFileAttributeOverrides()

Test to see if file attributes can be overridden.

File

./file_entity.test, line 1649
Test integration for the file_entity module.

Class

FileEntityAttributeOverrideTestCase
Tests overriding file attributes.

Code

function testFileEntityFileAttributeOverrides() {
  $overrides = array(
    'width' => 40,
    'height' => 20,
    'alt' => $this
      ->randomName(),
    'title' => $this
      ->randomName(),
  );

  // Create an image file entity for testing.
  $file = $this
    ->createFileEntity(array(
    'type' => 'image',
  ));

  // Override a variety of attributes.
  foreach ($overrides as $override => $value) {
    $file->override['attributes'][$override] = $value;
  }

  // Build just the file portion of a file entity.
  $build = file_view_file($file, 'full');

  // Verify that all of the overrides replaced the attributes.
  foreach ($overrides as $attribute => $expected_value) {
    $this
      ->assertEqual($build['#file']->{$attribute}, $expected_value, format_string('The %attribute was overridden correctly.', array(
      '%attribute' => $attribute,
    )));
  }
}