Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -12,15 +12,43 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
* Test min/max resolution settings.
*/
function testResolution() {
$field_name = strtolower($this->randomMachineName());
$min_resolution = 50;
$max_resolution = 100;
$field_settings = array(
'max_resolution' => $max_resolution . 'x' . $max_resolution,
'min_resolution' => $min_resolution . 'x' . $min_resolution,
'alt_field' => 0,
);
$this->createImageField($field_name, 'article', array(), $field_settings);
$field_names = [
0 => strtolower($this->randomMachineName()),
1 => strtolower($this->randomMachineName()),
2 => strtolower($this->randomMachineName()),
];
$min_resolution = [
'width' => 50,
'height' => 50
];
$max_resolution = [
'width' => 100,
'height' => 100
];
$no_height_min_resolution = [
'width' => 50,
'height' => NULL
];
$no_height_max_resolution = [
'width' => 100,
'height' => NULL
];
$no_width_min_resolution = [
'width' => NULL,
'height' => 50
];
$no_width_max_resolution = [
'width' => NULL,
'height' => 100
];
$field_settings = [
0 => $this->getFieldSettings($min_resolution, $max_resolution),
1 => $this->getFieldSettings($no_height_min_resolution, $no_height_max_resolution),
2 => $this->getFieldSettings($no_width_min_resolution, $no_width_max_resolution),
];
$this->createImageField($field_names[0], 'article', [], $field_settings[0]);
$this->createImageField($field_names[1], 'article', [], $field_settings[1]);
$this->createImageField($field_names[2], 'article', [], $field_settings[2]);
// 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.
@ -29,21 +57,29 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
$image_factory = $this->container->get('image.factory');
foreach ($this->drupalGetTestFiles('image') as $image) {
$image_file = $image_factory->get($image->uri);
if ($image_file->getWidth() > $max_resolution) {
if ($image_file->getWidth() > $max_resolution['width']) {
$image_that_is_too_big = $image;
}
if ($image_file->getWidth() < $min_resolution) {
if ($image_file->getWidth() < $min_resolution['width']) {
$image_that_is_too_small = $image;
}
if ($image_that_is_too_small && $image_that_is_too_big) {
break;
}
}
$this->uploadNodeImage($image_that_is_too_small, $field_name, 'article');
$this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $image_that_is_too_small->filename)));
$this->assertRaw(t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => '50x50')));
$this->uploadNodeImage($image_that_is_too_big, $field_name, 'article');
$this->uploadNodeImage($image_that_is_too_small, $field_names[0], 'article');
$this->assertRaw(t('The specified file %name could not be uploaded.', ['%name' => $image_that_is_too_small->filename]));
$this->assertRaw(t('The image is too small; the minimum dimensions are %dimensions pixels.', ['%dimensions' => '50x50']));
$this->uploadNodeImage($image_that_is_too_big, $field_names[0], 'article');
$this->assertText(t('The image was resized to fit within the maximum allowed dimensions of 100x100 pixels.'));
$this->uploadNodeImage($image_that_is_too_small, $field_names[1], 'article');
$this->assertRaw(t('The specified file %name could not be uploaded.', ['%name' => $image_that_is_too_small->filename]));
$this->uploadNodeImage($image_that_is_too_big, $field_names[1], 'article');
$this->assertText(t('The image was resized to fit within the maximum allowed width of 100 pixels.'));
$this->uploadNodeImage($image_that_is_too_small, $field_names[2], 'article');
$this->assertRaw(t('The specified file %name could not be uploaded.', ['%name' => $image_that_is_too_small->filename]));
$this->uploadNodeImage($image_that_is_too_big, $field_names[2], 'article');
$this->assertText(t('The image was resized to fit within the maximum allowed height of 100 pixels.'));
}
/**
@ -102,4 +138,22 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
$this->assertNoText(t('Title field is required.'));
}
/**
* Returns field settings.
*
* @param int[] $min_resolution
* The minimum width and height resolution setting.
* @param int[] $max_resolution
* The maximum width and height resolution setting.
*
* @return array
*/
protected function getFieldSettings($min_resolution, $max_resolution) {
return [
'max_resolution' => $max_resolution['width'] . 'x' . $max_resolution['height'],
'min_resolution' => $min_resolution['width'] . 'x' . $min_resolution['height'],
'alt_field' => 0,
];
}
}