You are here

public function StreamWrapperTest::testAttachmentSpace in AmazonS3 7.2

Test that we properly encode filenames according to RFC2047.

@covers \Drupal\amazons3\StreamWrapper::getExternalUrl @covers \Drupal\amazons3\StreamWrapper::getContentDispositionAttachment

File

tests/StreamWrapperTest.php, line 432

Class

StreamWrapperTest
Tests \Drupal\amazons3\StreamWrapper.

Namespace

Drupal\amazons3Test

Code

public function testAttachmentSpace() {
  $config = StreamWrapperConfiguration::fromConfig([
    'bucket' => 'bucket.example.com',
    'region' => 'region',
    'caching' => FALSE,
    'expiration' => 0,
    'saveAsPaths' => new MatchablePaths(BasicPath::factory(array(
      'force-download/.*',
    ))),
  ]);
  $wrapper = new StreamWrapper($config);
  $wrapper
    ->setUri('s3://bucket.example.com/force-download/test with spaces.jpg');

  // https://s3.amazonaws.com/bucket.example.com/force-download/test%20with%20spaces.jpg?response-content-disposition=attachment%3B%20filename%3D%22test%20with%20spaces.jpg%22&AWSAccessKeyId=placeholder&Expires=1429987166&Signature=xEZpLFLnNAgIFbRuoP7VRbNUF%2BQ%3D
  $this
    ->assertRegExp('!.*response-content-disposition=attachment%3B%20filename%3D%22test%20with%20spaces\\.jpg.*!', $wrapper
    ->getExternalUrl());
}