GoogleCloudStorageTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Gaufrette\Functional\Adapter;
  3. /**
  4. * Functional tests for the GoogleCloudStorage adapter.
  5. *
  6. * Copy the ../adapters/GoogleCloudStorage.php.dist to GoogleCloudStorage.php and
  7. * adapt to your needs.
  8. *
  9. * @author Patrik Karisch <patrik@karisch.guru>
  10. */
  11. class GoogleCloudStorageTest extends FunctionalTestCase
  12. {
  13. /**
  14. * @test
  15. * @group functional
  16. *
  17. * @expectedException \RuntimeException
  18. */
  19. public function shouldThrowExceptionIfBucketMissing()
  20. {
  21. /** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */
  22. $adapter = $this->filesystem->getAdapter();
  23. $oldBucket = $adapter->getOptions();
  24. $adapter->setBucket('Gaufrette-' . mt_rand());
  25. $adapter->read('foo');
  26. $adapter->setBucket($oldBucket);
  27. }
  28. /**
  29. * @test
  30. * @group functional
  31. */
  32. public function shouldWriteAndReadWithDirectory()
  33. {
  34. /** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */
  35. $adapter = $this->filesystem->getAdapter();
  36. $oldOptions = $adapter->getOptions();
  37. $adapter->setOptions(array('directory' => 'Gaufrette'));
  38. $this->assertEquals(12, $this->filesystem->write('foo', 'Some content'));
  39. $this->assertEquals(13, $this->filesystem->write('test/subdir/foo', 'Some content1', true));
  40. $this->assertEquals('Some content', $this->filesystem->read('foo'));
  41. $this->assertEquals('Some content1', $this->filesystem->read('test/subdir/foo'));
  42. $this->filesystem->delete('foo');
  43. $this->filesystem->delete('test/subdir/foo');
  44. $adapter->setOptions($oldOptions);
  45. }
  46. /**
  47. * @test
  48. * @group functional
  49. */
  50. public function shouldSetMetadataCorrectly()
  51. {
  52. /** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */
  53. $adapter = $this->filesystem->getAdapter();
  54. $adapter->setMetadata('metadata.txt', array(
  55. 'CacheControl' => 'public, maxage=7200',
  56. 'ContentDisposition' => 'attachment; filename="test.txt"',
  57. 'ContentEncoding' => 'identity',
  58. 'ContentLanguage' => 'en',
  59. 'Colour' => 'Yellow',
  60. ));
  61. $this->assertEquals(12, $this->filesystem->write('metadata.txt', 'Some content', true));
  62. $reflectionObject = new \ReflectionObject($adapter);
  63. $reflectionMethod = $reflectionObject->getMethod('getObjectData');
  64. $reflectionMethod->setAccessible(true);
  65. $metadata = $reflectionMethod->invoke($adapter, array('metadata.txt'));
  66. $this->assertEquals('public, maxage=7200', $metadata->cacheControl);
  67. $this->assertEquals('attachment; filename="test.txt"', $metadata->contentDisposition);
  68. $this->assertEquals('identity', $metadata->contentEncoding);
  69. $this->assertEquals('en', $metadata->contentLanguage);
  70. $this->assertEquals(array(
  71. 'Colour' => 'Yellow',
  72. ), $metadata->metadata);
  73. $this->filesystem->delete('metadata.txt');
  74. }
  75. }