AclAwareAmazonS3Spec.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. use AmazonS3;
  4. use Gaufrette\Adapter;
  5. use PhpSpec\ObjectBehavior;
  6. class AclAwareAmazonS3Spec extends ObjectBehavior
  7. {
  8. /**
  9. * @param \Gaufrette\Adapter $adapter
  10. * @param \AmazonS3 $service
  11. */
  12. function let(Adapter $adapter, AmazonS3 $service)
  13. {
  14. $this->beConstructedWith($adapter, $service, 'bucketName');
  15. }
  16. function it_is_adapter()
  17. {
  18. $this->shouldHaveType('Gaufrette\Adapter');
  19. }
  20. function it_supports_metadata()
  21. {
  22. $this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
  23. }
  24. /**
  25. * @param \Gaufrette\Adapter $adapter
  26. */
  27. function it_delegates_read(Adapter $adapter)
  28. {
  29. $adapter->read('filename')->willReturn('some content');
  30. $adapter->read('filename2')->willReturn('other content');
  31. $this->read('filename')->shouldReturn('some content');
  32. $this->read('filename2')->shouldReturn('other content');
  33. }
  34. /**
  35. * @param \Gaufrette\Adapter $adapter
  36. * @param \AmazonS3 $service
  37. */
  38. function it_delegates_rename_and_update_acl(Adapter $adapter, AmazonS3 $service)
  39. {
  40. $service
  41. ->set_object_acl('bucketName', 'filename2', \AmazonS3::ACL_PRIVATE)
  42. ->shouldBeCalled()
  43. ->willReturn(new \CFResponse(array(), '', 200))
  44. ;
  45. $adapter
  46. ->rename('filename', 'filename2')
  47. ->shouldBeCalled()
  48. ->willReturn(true)
  49. ;
  50. $adapter
  51. ->delete('filename')
  52. ->shouldNotBeCalled()
  53. ;
  54. $this->rename('filename', 'filename2')->shouldReturn(true);
  55. }
  56. /**
  57. * @param \Gaufrette\Adapter $adapter
  58. * @param \AmazonS3 $service
  59. */
  60. function it_does_not_rename_when_cannot_update_acl(Adapter $adapter, AmazonS3 $service)
  61. {
  62. $service
  63. ->set_object_acl('bucketName', 'filename2', \AmazonS3::ACL_PRIVATE)
  64. ->shouldBeCalled()
  65. ->willReturn(new \CFResponse(array(), '', 500));
  66. $adapter
  67. ->rename('filename', 'filename2')
  68. ->shouldBeCalled()
  69. ->willReturn(true);
  70. $adapter
  71. ->delete('filename2')
  72. ->shouldBeCalled();
  73. $this->rename('filename', 'filename2')->shouldReturn(false);
  74. }
  75. /**
  76. * @param \Gaufrette\Adapter $adapter
  77. * @param \AmazonS3 $service
  78. */
  79. function it_updates_acl_with_users_array_when_rename(Adapter $adapter, AmazonS3 $service)
  80. {
  81. $service
  82. ->set_object_acl('bucketName', 'filename2', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))
  83. ->shouldBeCalled()
  84. ->willReturn(new \CFResponse(array(), '', 200))
  85. ;
  86. $adapter
  87. ->rename('filename', 'filename2')
  88. ->willReturn(true)
  89. ;
  90. $this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
  91. $this->rename('filename', 'filename2')->shouldReturn(true);
  92. }
  93. /**
  94. * @param \Gaufrette\Adapter $adapter
  95. * @param \AmazonS3 $service
  96. */
  97. function it_delegates_write_and_update_acl(Adapter $adapter, AmazonS3 $service)
  98. {
  99. $service
  100. ->set_object_acl('bucketName', 'filename', \AmazonS3::ACL_PRIVATE)
  101. ->shouldBeCalled()
  102. ->willReturn(new \CFResponse(array(), '', 200))
  103. ;
  104. $adapter
  105. ->write('filename', 'some content')
  106. ->shouldBeCalled()
  107. ->willReturn(12)
  108. ;
  109. $adapter
  110. ->delete('filename')
  111. ->shouldNotBeCalled()
  112. ;
  113. $this->write('filename', 'some content')->shouldReturn(12);
  114. }
  115. /**
  116. * @param \Gaufrette\Adapter $adapter
  117. * @param \AmazonS3 $service
  118. */
  119. function it_does_not_write_when_cannot_update_acl(Adapter $adapter, AmazonS3 $service)
  120. {
  121. $service
  122. ->set_object_acl('bucketName', 'filename', \AmazonS3::ACL_PRIVATE)
  123. ->shouldBeCalled()
  124. ->willReturn(new \CFResponse(array(), '', 500))
  125. ;
  126. $adapter
  127. ->write('filename', 'some content')
  128. ->shouldBeCalled()
  129. ->willReturn(12)
  130. ;
  131. $adapter
  132. ->delete('filename')
  133. ->shouldBeCalled()
  134. ;
  135. $this->write('filename', 'some content')->shouldReturn(false);
  136. }
  137. /**
  138. * @param \Gaufrette\Adapter $adapter
  139. * @param \AmazonS3 $service
  140. */
  141. function it_updates_acl_with_users_array_when_write(Adapter $adapter, AmazonS3 $service)
  142. {
  143. $service
  144. ->set_object_acl('bucketName', 'filename', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))
  145. ->shouldBeCalled()
  146. ->willReturn(new \CFResponse(array(), '', 200))
  147. ;
  148. $adapter
  149. ->write('filename', 'some content')
  150. ->willReturn(12)
  151. ;
  152. $this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
  153. $this->write('filename', 'some content')->shouldReturn(12);
  154. }
  155. /**
  156. * @param \Gaufrette\Adapter $adapter
  157. */
  158. function it_delegates_exists(Adapter $adapter)
  159. {
  160. $adapter->exists('filename')->willReturn(true);
  161. $adapter->exists('filename2')->willReturn(false);
  162. $this->exists('filename')->shouldReturn(true);
  163. $this->exists('filename2')->shouldReturn(false);
  164. }
  165. /**
  166. * @param \Gaufrette\Adapter $adapter
  167. */
  168. function it_delegates_mtime(Adapter $adapter)
  169. {
  170. $adapter->mtime('filename')->willReturn(1234);
  171. $adapter->mtime('filename2')->willReturn(2345);
  172. $this->mtime('filename')->shouldReturn(1234);
  173. $this->mtime('filename2')->shouldReturn(2345);
  174. }
  175. /**
  176. * @param \Gaufrette\Adapter $adapter
  177. */
  178. function it_delegates_directory_check(Adapter $adapter)
  179. {
  180. $adapter->isDirectory('filename')->willReturn(true);
  181. $adapter->isDirectory('filename2')->willReturn(false);
  182. $this->isDirectory('filename')->shouldReturn(true);
  183. $this->isDirectory('filename2')->shouldReturn(false);
  184. }
  185. /**
  186. * @param \Gaufrette\Adapter $adapter
  187. */
  188. function it_delegates_keys(Adapter $adapter)
  189. {
  190. $adapter->keys()->willReturn(array('filename', 'filename2'));
  191. $this->keys()->shouldReturn(array('filename', 'filename2'));
  192. }
  193. /**
  194. * @param \spec\Gaufrette\Adapter\TestDelegateAdapter $extendedAdapter
  195. * @param \AmazonS3 $service
  196. */
  197. function it_delegates_metadata_handling(TestDelegateAdapter $extendedAdapter, AmazonS3 $service)
  198. {
  199. $this->beConstructedWith($extendedAdapter, $service, 'bucketName');
  200. $extendedAdapter->setMetadata('filename', array('some'))->shouldBeCalled();
  201. $extendedAdapter->getMetadata('filename')->shouldBeCalled()->willReturn(array('some2'));
  202. $this->setMetadata('filename', array('some'));
  203. $this->getMetadata('filename')->shouldReturn(array('some2'));
  204. }
  205. }
  206. interface TestDelegateAdapter extends \Gaufrette\Adapter,
  207. \Gaufrette\Adapter\MetadataSupporter
  208. {
  209. }