public function S3fsTest::testImageDerivatives in S3 File System 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/S3fsTest.php \Drupal\Tests\s3fs\Functional\S3fsTest::testImageDerivatives()
Test the image derivative functionality.
File
- tests/
src/ Functional/ S3fsTest.php, line 147
Class
- S3fsTest
- S3 File System Tests.
Namespace
Drupal\Tests\s3fs\FunctionalCode
public function testImageDerivatives() {
// Prevent issues with derivative tokens during test.
$this
->config('image.settings')
->set('allow_insecure_derivatives', TRUE)
->save();
// Use the large image style for for presigned tests.
$this
->config('s3fs.settings')
->set('presigned_urls', "6000|.*/large/.*")
->save();
$img_uri1 = "{$this->remoteTestsFolderUri}/test.png";
$img_localpath = __DIR__ . '/../../fixtures/test.png';
// Upload the test image.
$this
->assertTrue(\Drupal::service('file_system')
->mkdir($this->remoteTestsFolderUri), 'Created the testing directory in the DB.');
$img_data = file_get_contents($img_localpath);
$img_file = file_save_data($img_data, $img_uri1);
$this
->assertNotIdentical($img_file, FALSE, "Copied the the test image to {$img_uri1}.");
// Request a derivative.
// Parse query parameters to ensure they get passed.
$style_url_parsed = UrlHelper::parse(ImageStyle::load('thumbnail')
->buildUrl($img_uri1));
$derivative = $this
->drupalGet($style_url_parsed['path'], [
'query' => $style_url_parsed['query'],
]);
$this
->assertNotFalse(imagecreatefromstring($derivative), 'The returned derivative is a valid image.');
$style_presigned_url_parsed = UrlHelper::parse(ImageStyle::load('large')
->buildUrl($img_uri1));
$presigned_derivative = $this
->drupalGet($style_presigned_url_parsed['path'], [
'query' => $style_presigned_url_parsed['query'],
]);
$this
->assertNotFalse(imagecreatefromstring($presigned_derivative), 'The returned signed derivative is a valid image.');
}