AclAwareAmazonS3Spec.php 6.8 KB

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