diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 1239c9720f..bdf8f805e0 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -229,7 +229,6 @@ public function transformDimensions(array &$dimensions, $uri) { ->dispatch(ImageDerivativePipelineEvents::RESOLVE_DERIVATIVE_IMAGE_DIMENSIONS); $dimensions['width'] = $pipeline->getVariable('derivativeImageWidth'); $dimensions['height'] = $pipeline->getVariable('derivativeImageHeight'); - return; } /** diff --git a/core/modules/image/tests/src/Functional/ImageDimensionsTest.php b/core/modules/image/tests/src/Functional/ImageDimensionsTest.php index 70f271504c..3564782887 100644 --- a/core/modules/image/tests/src/Functional/ImageDimensionsTest.php +++ b/core/modules/image/tests/src/Functional/ImageDimensionsTest.php @@ -347,7 +347,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(120, $image_file->getWidth()); @@ -368,7 +368,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(60, $image_file->getWidth()); @@ -390,7 +390,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(45, $image_file->getWidth()); @@ -412,7 +412,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(45, $image_file->getWidth()); @@ -430,7 +430,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(45, $image_file->getWidth()); @@ -451,7 +451,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); // Add a crop effect. @@ -470,7 +470,7 @@ public function testImageDimensions() { $this->assertEqual('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(30, $image_file->getWidth()); @@ -493,7 +493,7 @@ public function testImageDimensions() { // $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); // @todo Uncomment this once @@ -541,7 +541,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(100, $image_file->getWidth()); @@ -558,7 +558,7 @@ public function testImageDimensions() { $this->assertSame('', $this->getImageTag($variables)); $this->assertFileNotExists($generated_uri, 'Generated file does not exist.'); $this->drupalGet($this->getAbsoluteUrl($url)); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri, 'Generated file does exist after we accessed it.'); $image_file = $image_factory->get($generated_uri); $this->assertSame(50, $image_file->getWidth()); diff --git a/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php index 8632f5dbdf..8d4176dbd4 100644 --- a/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php +++ b/core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php @@ -402,7 +402,7 @@ public function testImageStyleUrlForMissingSourceImage() { ->getDerivativeImageUrl() ->toString(); $this->drupalGet($generated_url); - $this->assertResponse(404, 'Accessing an image style URL with a source image that does not exist provides a 404 error response.'); + $this->assertSession()->statusCodeEquals(404); } /** @@ -490,10 +490,10 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ // Add some extra chars to the token. $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url)); - $this->assertResponse(404, 'Image was inaccessible at the URL with an invalid token.'); + $this->assertSession()->statusCodeEquals(404); // Change the parameter name so the token is missing. $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $generate_url)); - $this->assertResponse(404, 'Image was inaccessible at the URL with a missing token.'); + $this->assertSession()->statusCodeEquals(404); // Check that the generated URL is the same when we pass in a relative path // rather than a URI. We need to temporarily switch the default scheme to @@ -511,7 +511,7 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ // Fetch the URL that generates the file. $this->drupalGet($generate_url); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri); // assertRaw can't be used with string containing non UTF-8 chars. $this->assertNotEmpty(file_get_contents($generated_uri), 'URL returns expected file.'); @@ -532,7 +532,7 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ // Make sure that a second request to the already existing derivative // works too. $this->drupalGet($generate_url); - $this->assertResponse(200, 'Image was generated at the URL.'); + $this->assertSession()->statusCodeEquals(200); // Check that the second request also returned the generated image. $this->assertSame($image->getFileSize(), (int) $this->drupalGetHeader('Content-Length')); @@ -544,7 +544,7 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ // have access. \Drupal::state()->delete('image.test_file_download'); $this->drupalGet($generate_url); - $this->assertResponse(403, 'Confirmed that access is denied for the private image style.'); + $this->assertSession()->statusCodeEquals(403); // Repeat this with a different file that we do not have access to and // make sure that access is denied. @@ -558,7 +558,7 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ $generate_url_noaccess = $pipeline->getDerivativeImageUrl()->toString(); $this->drupalGet($generate_url_noaccess); - $this->assertResponse(403, 'Confirmed that access is denied for the private image style.'); + $this->assertSession()->statusCodeEquals(403); // Verify that images are not appended to the response. // Currently this test only uses PNG images. $this->assertStringContainsString('.png', $generate_url, 'Confirming that private image styles are not appended require PNG file.'); @@ -575,7 +575,7 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ if ($clean_url) { // Add some extra chars to the token. $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url)); - $this->assertResponse(200, 'Existing image was accessible at the URL with an invalid token.'); + $this->assertSession()->statusCodeEquals(200); } } @@ -606,7 +606,7 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ $generate_url = $pipeline->getDerivativeImageUrl()->toString(); $this->assertStringNotContainsString(IMAGE_DERIVATIVE_TOKEN . '=', $generate_url, 'The security token does not appear in the image style URL.'); $this->drupalGet($generate_url); - $this->assertResponse(200, 'Image was accessible at the URL with a missing token.'); + $this->assertSession()->statusCodeEquals(200); // Stop suppressing the security token in the URL. $this->config('image.settings')->set('suppress_itok_output', FALSE)->save(); @@ -623,16 +623,16 @@ public function testImageStyleUrlAndPath(string $scheme, bool $clean_url, bool $ $this->assertTrue($matches_expected_url_format, "URL for a derivative of an image style matches expected format."); $nested_url_with_wrong_token = str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $nested_url); $this->drupalGet($nested_url_with_wrong_token); - $this->assertResponse(404, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token.'); + $this->assertSession()->statusCodeEquals(404); // Check that this restriction cannot be bypassed by adding extra slashes // to the URL. $this->drupalGet(substr_replace($nested_url_with_wrong_token, '//styles/', strrpos($nested_url_with_wrong_token, '/styles/'), strlen('/styles/'))); - $this->assertResponse(404, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token, even with an extra forward slash in the URL.'); + $this->assertSession()->statusCodeEquals(404); $this->drupalGet(substr_replace($nested_url_with_wrong_token, '////styles/', strrpos($nested_url_with_wrong_token, '/styles/'), strlen('/styles/'))); - $this->assertResponse(404, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token, even with multiple forward slashes in the URL.'); + $this->assertSession()->statusCodeEquals(404); // Make sure the image can still be generated if a correct token is used. $this->drupalGet($nested_url); - $this->assertResponse(200, 'Image was accessible when a correct token was provided in the URL.'); + $this->assertSession()->statusCodeEquals(200); // Check that requesting a nonexistent image does not create any new // directories in the file system. diff --git a/core/modules/image/tests/src/Kernel/DerivativeImageProcessTest.php b/core/modules/image/tests/src/Kernel/DerivativeImageProcessTest.php index 5f9627be9f..98b277efb1 100644 --- a/core/modules/image/tests/src/Kernel/DerivativeImageProcessTest.php +++ b/core/modules/image/tests/src/Kernel/DerivativeImageProcessTest.php @@ -138,7 +138,7 @@ public function testBuildDerivativeImageFromFile() { ->setImageStyle($this->imageStyle) ->setSourceImageUri('public://test.png'); $this->assertTrue($pipeline->buildDerivativeImage()); - $this->assertTrue(file_exists('public://styles/thumbnail/public/test.png')); + $this->assertFileExists('public://styles/thumbnail/public/test.png'); $image = \Drupal::service('image.factory')->get('public://styles/thumbnail/public/test.png'); $this->assertSame(100, $image->getWidth()); $this->assertSame(67, $image->getHeight()); @@ -148,14 +148,14 @@ public function testBuildDerivativeImageFromFile() { ->setImageStyle($this->imageStyle) ->setSourceImageUri('public://missing.png'); $this->assertFalse($pipeline->buildDerivativeImage()); - $this->assertFalse(file_exists('public://styles/thumbnail/public/missing.png')); + $this->assertFileNotExists('public://styles/thumbnail/public/missing.png'); // Starting off from a path. $pipeline = $this->imageProcessor->createInstance('derivative') ->setImageStyle($this->imageStyle) ->setSourceImageUri('core/modules/image/sample.png'); $this->assertTrue($pipeline->buildDerivativeImage()); - $this->assertTrue(file_exists('public://styles/thumbnail/public/core/modules/image/sample.png')); + $this->assertFileExists('public://styles/thumbnail/public/core/modules/image/sample.png'); $image = \Drupal::service('image.factory')->get('public://styles/thumbnail/public/core/modules/image/sample.png'); $this->assertSame(100, $image->getWidth()); $this->assertSame(75, $image->getHeight()); @@ -192,7 +192,7 @@ public function testBuildDerivativeImageFromImageObject() { $this->assertTrue($pipeline->buildDerivativeImage()); // Check if derivative image exists. - $this->assertTrue(file_exists($derivative_uri)); + $this->assertFileExists($derivative_uri); // Check derivative image after saving, with old object. $this->assertSame(100, $image->getWidth());