1.20.x file.test FileAttributeOverrideTestCase::testFileFileAttributeOverrides()

Test to see if file attributes can be overridden.

File

modules/file/tests/file.test, line 3306
Tests for file.module.

Class

FileAttributeOverrideTestCase
Tests overriding file attributes.

Code

function testFileFileAttributeOverrides() {
  $overrides = array(
    'width' => 40,
    'height' => 20,
  );

  // Create an image file entity for testing.
  $file = $this->createFile(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['#item'][$attribute], $expected_value, format_string('The %attribute was overridden correctly.', array('%attribute' => $attribute)));
  }
}