public function testGetAllowedExtensionsByType() { $this->request->expects($this->at(0))->method('getParam')->with(\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE)->will($this->returnValue(\Magento\Theme\Model\Wysiwyg\Storage::TYPE_FONT)); $this->request->expects($this->at(1))->method('getParam')->with(\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE)->will($this->returnValue(\Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE)); $fontTypes = $this->helper->getAllowedExtensionsByType(); $this->assertEquals(['ttf', 'otf', 'eot', 'svg', 'woff'], $fontTypes); $imagesTypes = $this->helper->getAllowedExtensionsByType(); $this->assertEquals(['jpg', 'jpeg', 'gif', 'png', 'xbm', 'wbmp'], $imagesTypes); }
/** * Upload file * * @param string $targetPath * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function uploadFile($targetPath) { /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */ $uploader = $this->_objectManager->create('Magento\\MediaStorage\\Model\\File\\Uploader', ['fileId' => 'file']); $uploader->setAllowedExtensions($this->_helper->getAllowedExtensionsByType()); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $result = $uploader->save($targetPath); if (!$result) { throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t upload the file right now.')); } $this->_createThumbnail($targetPath . '/' . $uploader->getUploadedFileName()); $result['cookie'] = ['name' => $this->_helper->getSession()->getName(), 'value' => $this->_helper->getSession()->getSessionId(), 'lifetime' => $this->_helper->getSession()->getCookieLifetime(), 'path' => $this->_helper->getSession()->getCookiePath(), 'domain' => $this->_helper->getSession()->getCookieDomain()]; return $result; }