123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- namespace spec\Gaufrette\Adapter;
- use AmazonS3;
- use Gaufrette\Adapter;
- use PhpSpec\ObjectBehavior;
- class AclAwareAmazonS3Spec extends ObjectBehavior
- {
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function let(Adapter $adapter, AmazonS3 $service)
- {
- $this->beConstructedWith($adapter, $service, 'bucketName');
- }
- function it_is_adapter()
- {
- $this->shouldHaveType('Gaufrette\Adapter');
- }
- function it_supports_metadata()
- {
- $this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- */
- function it_delegates_read(Adapter $adapter)
- {
- $adapter->read('filename')->willReturn('some content');
- $adapter->read('filename2')->willReturn('other content');
- $this->read('filename')->shouldReturn('some content');
- $this->read('filename2')->shouldReturn('other content');
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function it_delegates_rename_and_update_acl(Adapter $adapter, AmazonS3 $service)
- {
- $service
- ->set_object_acl('bucketName', 'filename2', \AmazonS3::ACL_PRIVATE)
- ->shouldBeCalled()
- ->willReturn(new \CFResponse(array(), '', 200))
- ;
- $adapter
- ->rename('filename', 'filename2')
- ->shouldBeCalled()
- ->willReturn(true)
- ;
- $adapter
- ->delete('filename')
- ->shouldNotBeCalled()
- ;
- $this->rename('filename', 'filename2')->shouldReturn(true);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function it_does_not_rename_when_cannot_update_acl(Adapter $adapter, AmazonS3 $service)
- {
- $service
- ->set_object_acl('bucketName', 'filename2', \AmazonS3::ACL_PRIVATE)
- ->shouldBeCalled()
- ->willReturn(new \CFResponse(array(), '', 500));
- $adapter
- ->rename('filename', 'filename2')
- ->shouldBeCalled()
- ->willReturn(true);
- $adapter
- ->delete('filename2')
- ->shouldBeCalled();
- $this->rename('filename', 'filename2')->shouldReturn(false);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function it_updates_acl_with_users_array_when_rename(Adapter $adapter, AmazonS3 $service)
- {
- $service
- ->set_object_acl('bucketName', 'filename2', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))
- ->shouldBeCalled()
- ->willReturn(new \CFResponse(array(), '', 200))
- ;
- $adapter
- ->rename('filename', 'filename2')
- ->willReturn(true)
- ;
- $this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
- $this->rename('filename', 'filename2')->shouldReturn(true);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function it_delegates_write_and_update_acl(Adapter $adapter, AmazonS3 $service)
- {
- $service
- ->set_object_acl('bucketName', 'filename', \AmazonS3::ACL_PRIVATE)
- ->shouldBeCalled()
- ->willReturn(new \CFResponse(array(), '', 200))
- ;
- $adapter
- ->write('filename', 'some content')
- ->shouldBeCalled()
- ->willReturn(12)
- ;
- $adapter
- ->delete('filename')
- ->shouldNotBeCalled()
- ;
- $this->write('filename', 'some content')->shouldReturn(12);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function it_does_not_write_when_cannot_update_acl(Adapter $adapter, AmazonS3 $service)
- {
- $service
- ->set_object_acl('bucketName', 'filename', \AmazonS3::ACL_PRIVATE)
- ->shouldBeCalled()
- ->willReturn(new \CFResponse(array(), '', 500))
- ;
- $adapter
- ->write('filename', 'some content')
- ->shouldBeCalled()
- ->willReturn(12)
- ;
- $adapter
- ->delete('filename')
- ->shouldBeCalled()
- ;
- $this->write('filename', 'some content')->shouldReturn(false);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- * @param \AmazonS3 $service
- */
- function it_updates_acl_with_users_array_when_write(Adapter $adapter, AmazonS3 $service)
- {
- $service
- ->set_object_acl('bucketName', 'filename', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))
- ->shouldBeCalled()
- ->willReturn(new \CFResponse(array(), '', 200))
- ;
- $adapter
- ->write('filename', 'some content')
- ->willReturn(12)
- ;
- $this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
- $this->write('filename', 'some content')->shouldReturn(12);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- */
- function it_delegates_exists(Adapter $adapter)
- {
- $adapter->exists('filename')->willReturn(true);
- $adapter->exists('filename2')->willReturn(false);
- $this->exists('filename')->shouldReturn(true);
- $this->exists('filename2')->shouldReturn(false);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- */
- function it_delegates_mtime(Adapter $adapter)
- {
- $adapter->mtime('filename')->willReturn(1234);
- $adapter->mtime('filename2')->willReturn(2345);
- $this->mtime('filename')->shouldReturn(1234);
- $this->mtime('filename2')->shouldReturn(2345);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- */
- function it_delegates_directory_check(Adapter $adapter)
- {
- $adapter->isDirectory('filename')->willReturn(true);
- $adapter->isDirectory('filename2')->willReturn(false);
- $this->isDirectory('filename')->shouldReturn(true);
- $this->isDirectory('filename2')->shouldReturn(false);
- }
- /**
- * @param \Gaufrette\Adapter $adapter
- */
- function it_delegates_keys(Adapter $adapter)
- {
- $adapter->keys()->willReturn(array('filename', 'filename2'));
- $this->keys()->shouldReturn(array('filename', 'filename2'));
- }
- /**
- * @param \spec\Gaufrette\Adapter\TestDelegateAdapter $extendedAdapter
- * @param \AmazonS3 $service
- */
- function it_delegates_metadata_handling(TestDelegateAdapter $extendedAdapter, AmazonS3 $service)
- {
- $this->beConstructedWith($extendedAdapter, $service, 'bucketName');
- $extendedAdapter->setMetadata('filename', array('some'))->shouldBeCalled();
- $extendedAdapter->getMetadata('filename')->shouldBeCalled()->willReturn(array('some2'));
- $this->setMetadata('filename', array('some'));
- $this->getMetadata('filename')->shouldReturn(array('some2'));
- }
- }
- interface TestDelegateAdapter extends \Gaufrette\Adapter,
- \Gaufrette\Adapter\MetadataSupporter
- {
- }
|