function EditorUploadImageScaleTest::testEditorUploadImageScale
Same name in other branches
- 8.9.x core/modules/editor/tests/src/Functional/EditorUploadImageScaleTest.php \Drupal\Tests\editor\Functional\EditorUploadImageScaleTest::testEditorUploadImageScale()
- 10 core/modules/editor/tests/src/Functional/EditorUploadImageScaleTest.php \Drupal\Tests\editor\Functional\EditorUploadImageScaleTest::testEditorUploadImageScale()
Tests scaling of inline images.
File
-
core/
modules/ editor/ tests/ src/ Functional/ EditorUploadImageScaleTest.php, line 78
Class
- EditorUploadImageScaleTest
- Tests scaling of inline images.
Namespace
Drupal\Tests\editor\FunctionalCode
public function testEditorUploadImageScale() {
// Generate testing images.
$testing_image_list = $this->getTestFiles('image');
// Case 1: no max dimensions set: uploaded image not scaled.
$test_image = $testing_image_list[0];
[
$image_file_width,
$image_file_height,
] = $this->getTestImageInfo($test_image->uri);
$max_width = NULL;
$max_height = NULL;
$this->setMaxDimensions($max_width, $max_height);
$this->assertSavedMaxDimensions($max_width, $max_height);
[
$uploaded_image_file_width,
$uploaded_image_file_height,
] = $this->uploadImage($test_image->uri);
$this->assertEquals($image_file_width, $uploaded_image_file_width);
$this->assertEquals($image_file_height, $uploaded_image_file_height);
$this->assertSession()
->pageTextNotContains("The image was resized to fit within the maximum allowed dimensions of {$max_width}x{$max_height} pixels.");
// Case 2: max width smaller than uploaded image: image scaled down.
$test_image = $testing_image_list[1];
[
$image_file_width,
$image_file_height,
] = $this->getTestImageInfo($test_image->uri);
$max_width = $image_file_width - 5;
$max_height = $image_file_height;
$this->setMaxDimensions($max_width, $max_height);
$this->assertSavedMaxDimensions($max_width, $max_height);
[
$uploaded_image_file_width,
$uploaded_image_file_height,
] = $this->uploadImage($test_image->uri);
$this->assertEquals($max_width, $uploaded_image_file_width);
$this->assertEquals($uploaded_image_file_height * ($uploaded_image_file_width / $max_width), $uploaded_image_file_height);
$this->assertSession()
->pageTextContains("The image was resized to fit within the maximum allowed dimensions of {$max_width}x{$max_height} pixels.");
// Case 3: max height smaller than uploaded image: image scaled down.
$test_image = $testing_image_list[2];
[
$image_file_width,
$image_file_height,
] = $this->getTestImageInfo($test_image->uri);
$max_width = $image_file_width;
$max_height = $image_file_height - 5;
$this->setMaxDimensions($max_width, $max_height);
$this->assertSavedMaxDimensions($max_width, $max_height);
[
$uploaded_image_file_width,
$uploaded_image_file_height,
] = $this->uploadImage($test_image->uri);
$this->assertEquals($uploaded_image_file_width * ($uploaded_image_file_height / $max_height), $uploaded_image_file_width);
$this->assertEquals($max_height, $uploaded_image_file_height);
$this->assertSession()
->pageTextContains("The image was resized to fit within the maximum allowed dimensions of {$max_width}x{$max_height} pixels.");
// Case 4: max dimensions greater than uploaded image: image not scaled.
$test_image = $testing_image_list[3];
[
$image_file_width,
$image_file_height,
] = $this->getTestImageInfo($test_image->uri);
$max_width = $image_file_width + 5;
$max_height = $image_file_height + 5;
$this->setMaxDimensions($max_width, $max_height);
$this->assertSavedMaxDimensions($max_width, $max_height);
[
$uploaded_image_file_width,
$uploaded_image_file_height,
] = $this->uploadImage($test_image->uri);
$this->assertEquals($image_file_width, $uploaded_image_file_width);
$this->assertEquals($image_file_height, $uploaded_image_file_height);
$this->assertSession()
->pageTextNotContains("The image was resized to fit within the maximum allowed dimensions of {$max_width}x{$max_height} pixels.");
// Case 5: only max width dimension was provided and it was smaller than
// uploaded image: image scaled down.
$test_image = $testing_image_list[4];
[
$image_file_width,
$image_file_height,
] = $this->getTestImageInfo($test_image->uri);
$max_width = $image_file_width - 5;
$max_height = NULL;
$this->setMaxDimensions($max_width, $max_height);
$this->assertSavedMaxDimensions($max_width, $max_height);
[
$uploaded_image_file_width,
$uploaded_image_file_height,
] = $this->uploadImage($test_image->uri);
$this->assertEquals($max_width, $uploaded_image_file_width);
$this->assertEquals($uploaded_image_file_height * ($uploaded_image_file_width / $max_width), $uploaded_image_file_height);
$this->assertSession()
->pageTextContains("The image was resized to fit within the maximum allowed width of {$max_width} pixels.");
// Case 6: only max height dimension was provided and it was smaller than
// uploaded image: image scaled down.
$test_image = $testing_image_list[5];
[
$image_file_width,
$image_file_height,
] = $this->getTestImageInfo($test_image->uri);
$max_width = NULL;
$max_height = $image_file_height - 5;
$this->setMaxDimensions($max_width, $max_height);
$this->assertSavedMaxDimensions($max_width, $max_height);
[
$uploaded_image_file_width,
$uploaded_image_file_height,
] = $this->uploadImage($test_image->uri);
$this->assertEquals($uploaded_image_file_width * ($uploaded_image_file_height / $max_height), $uploaded_image_file_width);
$this->assertEquals($max_height, $uploaded_image_file_height);
$this->assertSession()
->pageTextContains("The image was resized to fit within the maximum allowed height of {$max_height} pixels.");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.