public function testGetCurrentUrl() { $storeId = 1; $baseUrl = 'http://localhost'; $relativePath = '/../wysiwyg'; $this->imagesHelper->setStoreId($storeId); $this->storeMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)->willReturn($baseUrl); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->directoryWriteMock->expects($this->any())->method('getRelativePath')->willReturn($relativePath); $this->assertEquals($baseUrl . $relativePath . '/', $this->imagesHelper->getCurrentUrl()); }
/** * Return files * * @param string $path Parent directory path * @param string $type Type of storage, e.g. image, media etc. * @return \Magento\Framework\Data\Collection\Filesystem */ public function getFilesCollection($path, $type = null) { if ($this->_coreFileStorageDb->checkDbUsage()) { $files = $this->_storageDatabaseFactory->create()->getDirectoryFiles($path); /** @var \Magento\MediaStorage\Model\File\Storage\File $fileStorageModel */ $fileStorageModel = $this->_storageFileFactory->create(); foreach ($files as $file) { $fileStorageModel->saveFile($file); } } $collection = $this->getCollection($path)->setCollectDirs(false)->setCollectFiles(true)->setCollectRecursively(false)->setOrder('mtime', \Magento\Framework\Data\Collection::SORT_ORDER_ASC); // Add files extension filter if ($allowed = $this->getAllowedExtensions($type)) { $collection->setFilesFilter('/\\.(' . implode('|', $allowed) . ')$/i'); } // prepare items foreach ($collection as $item) { $item->setId($this->_cmsWysiwygImages->idEncode($item->getBasename())); $item->setName($item->getBasename()); $item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename())); $item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename()); if ($this->isImage($item->getBasename())) { $thumbUrl = $this->getThumbnailUrl($item->getFilename(), true); // generate thumbnail "on the fly" if it does not exists if (!$thumbUrl) { $thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]); } $size = @getimagesize($item->getFilename()); if (is_array($size)) { $item->setWidth($size[0]); $item->setHeight($size[1]); } } else { $thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX); } $item->setThumbUrl($thumbUrl); } return $collection; }