1 image.test ImageFieldValidateTestCase::testHeightDimensions()

Test single height resolution setting.

File

core/modules/image/tests/image.test, line 1099
Tests for image.module.

Class

ImageFieldValidateTestCase
Test class to check for various validations.

Code

function testHeightDimensions() {
  $field_name = strtolower($this->randomName());
  $min_dimensions = 50;
  $max_dimensions = 100;
  $instance_settings = array(
    'max_dimensions' => 'x' . $max_dimensions,
    'min_dimensions' => 'x' . $min_dimensions,
  );
  $this->createImageField($field_name, 'post', array(), $instance_settings);

  // We want a test image that is too small, and a test image that is too
  // big, so cycle through test image files until we have what we need.
  $image_that_is_too_big = FALSE;
  $image_that_is_too_small = FALSE;
  foreach ($this->backdropGetTestFiles('image') as $image) {
    $info = image_get_info($image->uri);
    if ($info['height'] > $max_dimensions) {
      $image_that_is_too_big = $image;
    }
    if ($info['height'] < $min_dimensions) {
      $image_that_is_too_small = $image;
    }
    if ($image_that_is_too_small && $image_that_is_too_big) {
      break;
    }
  }
  $nid = $this->uploadNodeImage($image_that_is_too_small, $field_name, 'post');
  $this->assertText(t('The specified file ' . $image_that_is_too_small->filename . ' could not be uploaded. The image is too small; the minimum height is 50 pixels.'), 'Node save failed when minimum image dimensions was not met.');
  $nid = $this->uploadNodeImage($image_that_is_too_big, $field_name, 'post');
  $this->assertText(t('The image was resized to fit within the maximum allowed height of 100 pixels.'), 'Image exceeding max height was properly resized.');
}