Example #1
0
 protected function setUp()
 {
     $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
     $this->storageMock = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false);
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $mockedMetaDataRepository = $this->getMock(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class);
     $mockedMetaDataRepository->expects($this->any())->method('findByFile')->will($this->returnValue(array('file' => 1)));
     \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class, $mockedMetaDataRepository);
 }
Example #2
0
 public function setUp()
 {
     $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
     $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $mockedMetaDataRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
     $mockedMetaDataRepository->expects($this->any())->method('findByFile')->will($this->returnValue(array('file' => 1)));
     \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', $mockedMetaDataRepository);
 }
 /**
  * Set up
  *
  * @return void
  */
 public function setUp()
 {
     $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
     $this->fileCollectionMock = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\Resource\\Collection\\AbstractFileCollection', array('loadContents', 'getItems'), array(), '', FALSE);
     $this->fileCollectionMock->expects($this->atLeastOnce())->method('loadContents');
     $this->fileCollectionRepositoryMock = $this->getMock('\\TYPO3\\CMS\\Core\\Resource\\FileCollectionRepository', array('findByUid'), array(), '', FALSE);
     $this->fileCollectionRepositoryMock->expects($this->any())->method('findByUid')->will($this->returnValue($this->fileCollectionMock));
     $this->frontendConfigurationManagerMock = $this->getMock('\\TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('getConfiguration'), array(), '', FALSE);
     $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $this->subject = GeneralUtility::makeInstance('SKYFILLERS\\SfFilecollectionGallery\\Service\\FileCollectionService');
     $this->subject->injectFileCollectionRepository($this->fileCollectionRepositoryMock);
     $this->subject->injectFrontendConfigurationManager($this->frontendConfigurationManagerMock);
 }
Example #4
0
 public function setUp()
 {
     $this->singletonInstances = GeneralUtility::getSingletonInstances();
     // Disable xml2array cache used by ResourceFactory
     GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations(array('cache_hash' => array('frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\TransientMemoryBackend')));
     $this->testDocumentsPath = ExtensionManagementUtility::extPath('tika') . 'Tests/TestDocuments/';
     $driver = $this->createDriverFixture(array('basePath' => $this->testDocumentsPath, 'caseSensitive' => TRUE));
     $storageRecord = array('uid' => $this->storageUid, 'is_public' => TRUE, 'is_writable' => FALSE, 'is_browsable' => TRUE, 'is_online' => TRUE, 'configuration' => $this->convertConfigurationArrayToFlexformXml(array('basePath' => $this->testDocumentsPath, 'pathType' => 'absolute', 'caseSensitive' => '1')));
     $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', NULL, array($driver, $storageRecord));
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue($this->storageUid));
     $mockedMetaDataRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
     $mockedMetaDataRepository->expects($this->any())->method('findByFile')->will($this->returnValue(array('file' => 1)));
     \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', $mockedMetaDataRepository);
 }
 /**
  * @test
  * @group integration
  * @TODO: Rewrite or move to functional suite
  */
 public function setFileContentsUpdatesObjectProperties()
 {
     $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
     $this->initializeVfs();
     $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, array(), '', false);
     $this->subject = $this->getMock(ResourceStorage::class, array('getFileIndexRepository', 'checkFileActionPermission'), array($driverObject, array()));
     $this->subject->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(true));
     $fileInfo = array('storage' => 'A', 'identifier' => 'B', 'mtime' => 'C', 'ctime' => 'D', 'mimetype' => 'E', 'size' => 'F', 'name' => 'G');
     $newProperties = array('storage' => $fileInfo['storage'], 'identifier' => $fileInfo['identifier'], 'tstamp' => $fileInfo['mtime'], 'crdate' => $fileInfo['ctime'], 'mime_type' => $fileInfo['mimetype'], 'size' => $fileInfo['size'], 'name' => $fileInfo['name']);
     $hash = 'asdfg';
     /** @var $mockedDriver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
     $mockedDriver = $this->getMock(LocalDriver::class, array(), array(array('basePath' => $this->getMountRootUrl())));
     $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
     $mockedDriver->expects($this->once())->method('hash')->will($this->returnValue($hash));
     $this->subject->setDriver($mockedDriver);
     $indexFileRepositoryMock = $this->getMock(FileIndexRepository::class);
     $this->subject->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
     /** @var $mockedFile File|\PHPUnit_Framework_MockObject_MockObject */
     $mockedFile = $this->getMock(File::class, array(), array(), '', false);
     $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
     // called by indexer because the properties are updated
     $this->subject->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
     $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->subject));
     $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
     $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
     // do not update directly; that's up to the indexer
     $indexFileRepositoryMock->expects($this->never())->method('update');
     $this->subject->setFileContents($mockedFile, $this->getUniqueId());
 }
 /**
  * @test
  * @group integration
  * @TODO: Rewrite or move to functional suite
  */
 public function setFileContentsUpdatesObjectProperties()
 {
     $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
     $this->initializeVfs();
     $driverObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), '', FALSE);
     $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFileIndexRepository', 'checkFileActionPermission'), array($driverObject, array()));
     $this->fixture->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(TRUE));
     $fileInfo = array('storage' => 'A', 'identifier' => 'B', 'mtime' => 'C', 'ctime' => 'D', 'mimetype' => 'E', 'size' => 'F', 'name' => 'G');
     $newProperties = array('storage' => $fileInfo['storage'], 'identifier' => $fileInfo['identifier'], 'tstamp' => $fileInfo['mtime'], 'crdate' => $fileInfo['ctime'], 'mime_type' => $fileInfo['mimetype'], 'size' => $fileInfo['size'], 'name' => $fileInfo['name']);
     $hash = 'asdfg';
     $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array(), array(array('basePath' => $this->getMountRootUrl())));
     $driver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
     $driver->expects($this->once())->method('hash')->will($this->returnValue($hash));
     $this->fixture->setDriver($driver);
     $indexFileRepositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
     $this->fixture->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
     $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
     $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue($fileInfo['identifier']));
     // called by indexer because the properties are updated
     $this->fixture->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
     $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->fixture));
     $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
     $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
     // do not update directly; that's up to the indexer
     $indexFileRepositoryMock->expects($this->never())->method('update');
     $this->fixture->setFileContents($mockedFile, uniqid());
 }
Example #7
0
 /**
  * @test
  */
 public function deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile()
 {
     $this->storageMock->expects($this->never())->method('deleteFile');
     $processedDatabaseRow = $this->databaseRow;
     $processedDatabaseRow['identifier'] = NULL;
     $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
     $processedFile->delete(TRUE);
 }
Example #8
0
 protected function setUpLanguagesStorageMock()
 {
     $this->testLanguagesPath = ExtensionManagementUtility::extPath('tika') . 'Tests/TestLanguages/';
     $languagesDriver = $this->createDriverFixture(array('basePath' => $this->testLanguagesPath, 'caseSensitive' => TRUE));
     $languagesStorageRecord = array('uid' => $this->languagesStorageUid, 'is_public' => TRUE, 'is_writable' => FALSE, 'is_browsable' => TRUE, 'is_online' => TRUE, 'configuration' => $this->convertConfigurationArrayToFlexformXml(array('basePath' => $this->testLanguagesPath, 'pathType' => 'absolute', 'caseSensitive' => '1')));
     $this->languagesStorageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', NULL, array($languagesDriver, $languagesStorageRecord));
     $this->languagesStorageMock->expects($this->any())->method('getUid')->will($this->returnValue($this->languagesStorageUid));
 }
 /**
  * Prepare fixture
  *
  * @param array $configuration
  * @param boolean $mockPermissionChecks
  * @return void
  */
 protected function prepareFixture($configuration, $mockPermissionChecks = FALSE, $driverObject = NULL, array $storageRecord = array())
 {
     $permissionMethods = array('isFileActionAllowed', 'isFolderActionAllowed', 'checkFileActionPermission', 'checkUserActionPermission');
     $mockedMethods = NULL;
     $configuration = $this->convertConfigurationArrayToFlexformXml($configuration);
     $storageRecord = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($storageRecord, array('configuration' => $configuration));
     if ($driverObject == NULL) {
         /** @var $mockedDriver \TYPO3\CMS\Core\Resource\Driver\AbstractDriver */
         $driverObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), '', FALSE);
     }
     if ($mockPermissionChecks) {
         $mockedMethods = $permissionMethods;
     }
     if ($mockedMethods === NULL) {
         $this->fixture = new \TYPO3\CMS\Core\Resource\ResourceStorage($driverObject, $storageRecord);
     } else {
         $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', $mockedMethods, array($driverObject, $storageRecord));
         foreach ($permissionMethods as $method) {
             $this->fixture->expects($this->any())->method($method)->will($this->returnValue(TRUE));
         }
     }
 }