diff --git a/core/modules/editor/src/Tests/EditorUploadImageRescaleTest.php b/core/modules/editor/src/Tests/EditorUploadImageScaleTest.php similarity index 79% rename from core/modules/editor/src/Tests/EditorUploadImageRescaleTest.php rename to core/modules/editor/src/Tests/EditorUploadImageScaleTest.php index 9ea8150..66f51c9 100644 --- a/core/modules/editor/src/Tests/EditorUploadImageRescaleTest.php +++ b/core/modules/editor/src/Tests/EditorUploadImageScaleTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\editor\Tests\EditorUploadImageRescaleTest. + * Contains \Drupal\editor\Tests\EditorUploadImageScaleTest. */ namespace Drupal\editor\Tests; @@ -12,11 +12,11 @@ use Drupal\simpletest\WebTestBase; /** - * Test for image rescale function for Editor inline image. + * Test for image scale function for Editor inline image. * * @group editor */ -class EditorUploadImageRescaleTest extends WebTestBase { +class EditorUploadImageScaleTest extends WebTestBase { /** * Modules to enable. @@ -67,51 +67,45 @@ protected function setUp() { } /** - * Tests rescale of inline image. + * Tests scale of inline image. */ - public function testEditorUploadImageRescale() { + public function testEditorUploadImageScale() { // Generate testing images. $testing_image_list = $this->drupalGetTestFiles('image'); // Case 1: Editor "image_upload" has no "max_dimensions" set. The uploaded - // image should not rescale. + // image should not scale. $test_image = $testing_image_list[0]; list($image_file_width, $image_file_height, $image_basename) = $this->getTestImageInfo($test_image); $max_width = ''; $max_height = ''; $this->setMaxDimensions($max_width, $max_height); - $this->drupalGet('editor/dialog/image/basic_html/'); - $this->postImage($test_image->uri); - list($uploaded_image_file_width, $uploaded_image_file_height) = $this->getUploadedImageDimensions($image_basename); + list($uploaded_image_file_width, $uploaded_image_file_height) = $this->uploadImage($test_image->uri, $image_basename); $this->assertEqual($uploaded_image_file_width, $image_file_width); $this->assertEqual($uploaded_image_file_height, $image_file_height); // Case 2: Editor "image_upload" has "max_dimensions" with both width and // height being lower than the uploaded image. The uploaded image should - // rescale. + // scale. $test_image = $testing_image_list[1]; list($image_file_width, $image_file_height, $image_basename) = $this->getTestImageInfo($test_image); $max_width = $image_file_width - 5; $max_height = $image_file_height - 5; $this->setMaxDimensions($max_width, $max_height); - $this->drupalGet('editor/dialog/image/basic_html/'); - $this->postImage($test_image->uri); - list($uploaded_image_file_width, $uploaded_image_file_height) = $this->getUploadedImageDimensions($image_basename); - $rescale_result = ($uploaded_image_file_width <= $max_width) && ($uploaded_image_file_height <= $max_height); - $this->assertTrue($rescale_result, 'Uploaded image had been scaled'); + list($uploaded_image_file_width, $uploaded_image_file_height) = $this->uploadImage($test_image->uri, $image_basename); + $scale_result = ($uploaded_image_file_width <= $max_width) && ($uploaded_image_file_height <= $max_height); + $this->assertTrue($scale_result, 'Uploaded image had been scaled'); $this->assertRaw(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', ['%dimensions' => $max_width . 'x' . $max_height])); // Case 3: Editor "image_upload" has "max_dimensions" with both width and // height being higher than the uploaded image. The uploaded image should - // not rescale. + // not scale. $test_image = $testing_image_list[2]; list($image_file_width, $image_file_height, $image_basename) = $this->getTestImageInfo($test_image); $max_width = $image_file_width + 5; $max_height = $image_file_height + 5; $this->setMaxDimensions($max_width, $max_height); - $this->drupalGet('editor/dialog/image/basic_html/'); - $this->postImage($test_image->uri); - list($uploaded_image_file_width, $uploaded_image_file_height) = $this->getUploadedImageDimensions($image_basename); + list($uploaded_image_file_width, $uploaded_image_file_height) = $this->uploadImage($test_image->uri, $image_basename); $same_dimensions = ($uploaded_image_file_width == $image_file_width) && ($uploaded_image_file_height == $image_file_height); $this->assertTrue($same_dimensions, 'Uploaded image had the same dimensions'); } @@ -127,16 +121,6 @@ protected function getTestImageInfo($image) { ]; } - protected function getUploadedImageDimensions($image_basename) { - $image_factory = $this->container->get('image.factory'); - $uploaded_image_url = 'public://inline-images/' . $image_basename; - $uploaded_image_file = $image_factory->get($uploaded_image_url); - return [ - (int) $uploaded_image_file->getWidth(), - (int) $uploaded_image_file->getHeight(), - ]; - } - protected function setMaxDimensions($width, $height) { $editor = Editor::load('basic_html'); $image_upload_settings = $editor->getImageUploadSettings(); @@ -151,4 +135,17 @@ protected function postImage($uri) { $edit['files[fid]'] = drupal_realpath($uri); $this->drupalPostForm('editor/dialog/image/basic_html/', $edit, t('Upload')); } + + protected function uploadImage($uri, $image_basename) { + $this->drupalGet('editor/dialog/image/basic_html'); + $this->postImage($uri); + $image_factory = $this->container->get('image.factory'); + $uploaded_image_url = 'public://inline-images/' . $image_basename; + $uploaded_image_file = $image_factory->get($uploaded_image_url); + return [ + (int) $uploaded_image_file->getWidth(), + (int) $uploaded_image_file->getHeight(), + ]; + } + }