Example #1
0
 /**
  * @test
  */
 public function initializes()
 {
     $filelib = new FileLibrary(new MemoryStorageAdapter(), new MemoryBackendAdapter());
     $asynchrony = new Asynchrony($filelib);
     $this->assertInstanceOf('Xi\\Filelib\\Asynchrony\\FileRepository', $filelib->getFileRepository());
     $this->assertInstanceOf('Xi\\Filelib\\Asynchrony\\ExecutionStrategy\\SynchronousExecutionStrategy', $asynchrony->getStrategy(ExecutionStrategies::STRATEGY_SYNC));
 }
Example #2
0
 /**
  * @test
  */
 public function pluginShouldProvideForImage()
 {
     $filelib = new FileLibrary($this->getMockedStorageAdapter(), $this->getMockedBackendAdapter());
     $filelib->addPlugin($this->plugin);
     $this->assertFalse($this->plugin->isApplicableTo(File::create(array('resource' => Resource::create(array('mimetype' => 'video/avi'))))));
     $this->assertTrue($this->plugin->isApplicableTo(File::create(array('resource' => Resource::create(array('mimetype' => 'image/png'))))));
 }
Example #3
0
 /**
  * @param FileLibrary $filelib
  */
 public function attachTo(FileLibrary $filelib)
 {
     $this->fileRepository = $filelib->getFileRepository();
     $this->profiles = $filelib->getProfileManager();
     $this->storage = $filelib->getStorage();
     $this->eventDispatcher = $filelib->getEventDispatcher();
 }
 public function attachTo(FileLibrary $filelib)
 {
     $this->storage = $filelib->getStorage();
     $this->adapter = $filelib->getStorage()->getAdapter()->resolve();
     if (!$this->adapter instanceof FilesystemStorageAdapter) {
         throw new InvalidArgumentException("Symlink filesystem publisher requires filesystem storage");
     }
 }
Example #5
0
 /**
  * @param FileLibrary $filelib
  */
 public function attachTo(FileLibrary $filelib)
 {
     $this->fileRepository = $filelib->getFileRepository();
     $this->profiles = $filelib->getProfileManager();
     $this->eventDispatcher = $filelib->getEventDispatcher();
     $this->eventDispatcher->addSubscriber($this);
     $this->adapter->attachTo($filelib);
     $this->linker->attachTo($filelib);
 }
 /**
  * @test
  */
 public function serializesAndUnserializesAfterUpload()
 {
     $filelib = new FileLibrary(new MemoryStorageAdapter(), new MemoryBackendAdapter());
     $file = $filelib->getFileRepository()->upload(ROOT_TESTS . '/data/self-lussing-manatee.jpg');
     $serializer = new AsynchronyDataSerializer();
     $serializer->attachTo($filelib);
     $unserializedCallback = new SerializedCallback([$filelib->getFileRepository(), 'afterUpload'], [$file]);
     $this->assertTrue($serializer->willSerialize($unserializedCallback));
     $serializedCallback = $serializer->serialize($unserializedCallback);
     $deserializedCallback = $serializer->unserialize($serializedCallback);
     $this->assertEquals($unserializedCallback, $deserializedCallback);
 }
 /**
  * @test
  */
 public function unpublishShouldUnpublishFileVersion()
 {
     $adapter = new CopyFilesystemPublisherAdapter(ROOT_TESTS . '/data/publisher/public', "600", "700", '');
     $publisher = new Publisher($adapter, new UniversalSequentialLinker());
     $publisher->attachTo($this->filelib);
     $file = $this->filelib->uploadFile(ROOT_TESTS . '/data/self-lussing-manatee.jpg');
     $publisher->publishVersion($file, Version::get('original'));
     $path = ROOT_TESTS . '/data/publisher/public/' . $publisher->getUrl($file, Version::get('original'));
     $this->assertFileExists($path);
     $this->assertFalse(is_link($path));
     $publisher->unpublishVersion($file, Version::get('original'));
     $this->assertFileNotExists($path);
 }
 /**
  * @param array $files
  * @param array $type
  * @return CallbackFilterIterator 
  */
 public function filterByType($files, array $type)
 {
     $filesObject = new \ArrayObject($files);
     $fileOperator = $this->filelib->getFileOperator();
     $filteredFiles = array();
     if (version_compare(phpversion(), '5.4.0') >= 0) {
         $filteredFiles = new \CallbackFilterIterator($filesObject->getIterator(), function ($current, $key) use($type, $fileOperator) {
             return in_array($fileOperator->getType($current), $type);
         });
     } else {
         $filteredFiles = new XiCallbackFilterIterator($filesObject->getIterator(), function ($current, $key) use($type, $fileOperator) {
             return in_array($fileOperator->getType($current), $type);
         });
     }
     return $filteredFiles;
 }
Example #9
0
 /**
  * @test
  * @group luszo
  */
 public function deletesExclusiveResource()
 {
     $upload = ROOT_TESTS . '/data/self-lussing-manatee.jpg';
     $file = $this->filelib->getFileRepository()->upload($upload, null, 'tussi');
     $this->filelib->getFileRepository()->delete($file);
     $this->ed->dispatch(Events::FILE_AFTER_DELETE, Argument::type('Xi\\Filelib\\Event\\FileEvent'))->shouldHaveBeenCalled();
     $this->assertFalse($this->filelib->getStorage()->exists($file->getResource()));
 }
Example #10
0
 /**
  * @test
  */
 public function findByFilenameDelegates()
 {
     $param1 = Folder::create();
     $param2 = 'xooxox';
     $expected = 'tus';
     $this->repo->findByFilename($param1, $param2)->shouldBeCalled()->willReturn($expected);
     $ret = $this->filelib->getFileRepository()->findByFilename($param1, $param2);
     $this->assertEquals($expected, $ret);
 }
 /**
  * @test
  */
 public function updates()
 {
     $resource = Resource::create(['id' => 'xoo-xoo-xoo']);
     $res = $this->op->create($resource, ROOT_TESTS . '/data/self-lussing-manatee.jpg');
     $this->assertSame($res, $resource);
     $this->assertNotFalse($this->op->find($res->getId()));
     $this->assertNotFalse($this->filelib->getStorage()->exists($resource));
     $this->op->update($res);
     $this->ed->dispatch(Events::RESOURCE_BEFORE_UPDATE, Argument::type('Xi\\Filelib\\Event\\ResourceEvent'))->shouldHaveBeenCalled();
     $this->ed->dispatch(Events::RESOURCE_AFTER_UPDATE, Argument::type('Xi\\Filelib\\Event\\ResourceEvent'))->shouldHaveBeenCalled();
 }
 /**
  * @param FileLibrary $filelib
  */
 public function attachTo(FileLibrary $filelib)
 {
     $this->storage = $filelib->getStorage();
 }
Example #13
0
 public function attachTo(FileLibrary $filelib)
 {
     $this->eventDispatcher = $filelib->getEventDispatcher();
     $this->adapter->attachTo($filelib);
 }
Example #14
0
 protected function setupCache($enabled)
 {
     if ($enabled) {
         $this->filelib->createCacheFromAdapter(new MemcachedCacheAdapter($this->memcached));
     }
 }
 public function attachTo(FileLibrary $filelib)
 {
     $this->folderRepository = $filelib->getFolderRepository();
 }
Example #16
0
 /**
  * @param FileLibrary $filelib
  */
 public function attachTo(FileLibrary $filelib)
 {
     $this->tempFiles = $filelib->getTemporaryFileManager();
 }
Example #17
0
 public function __construct(FileLibrary $filelib)
 {
     $this->filelib = $filelib;
     $this->eventDispatcher = $filelib->getEventDispatcher();
 }
Example #18
0
 /**
  * @test
  * @dataProvider provideMimetypes
  */
 public function shouldProvideForVideo($expected, $mimetype)
 {
     $file = File::create(array('uuid' => Uuid::uuid4()->toString(), 'profile' => 'default', 'resource' => Resource::create(array('mimetype' => $mimetype))));
     $filelib = new FileLibrary($this->getMockedStorageAdapter(), $this->getMockedBackendAdapter());
     $filelib->addPlugin($this->plugin);
     $this->assertSame($expected, $this->plugin->isApplicableTo($file));
 }
Example #19
0
 public function attachTo(FileLibrary $filelib)
 {
     $this->backend = $filelib->getBackend();
 }
Example #20
0
 /**
  * @test
  */
 public function tempDirAcceptsObject()
 {
     $tfm = new TemporaryFileManager(sys_get_temp_dir());
     $filelib = new FileLibrary($this->prophesize(StorageAdapter::class)->reveal(), $this->prophesize(BackendAdapter::class)->reveal(), $this->prophesize(EventDispatcherInterface::class)->reveal(), $tfm);
     $this->assertSame($tfm, $filelib->getTemporaryFileManager());
 }
 public function setUp()
 {
     $this->ed = $this->prophesize('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->filelib = $this->getFilelib(true);
     $this->op = $this->filelib->getFolderRepository();
 }
Example #22
0
 public function __construct(FileLibrary $filelib)
 {
     $this->filelib = $filelib;
     $filelib->setFileRepository(new FileRepository($filelib->getFileRepository(), $this));
     $this->addStrategy(new SynchronousExecutionStrategy());
 }