public function testExecute() { $this->objectManager->expects($this->once())->method('get')->with('Magento\\Theme\\Helper\\Storage')->willReturn($this->storageHelper); $this->storageHelper->expects($this->once())->method('getRelativeUrl')->willReturn('http://relative.url/'); $this->response->expects($this->once())->method('setBody')->with('http://relative.url/'); $this->controller->execute(); }
public function testExecute() { $this->storageHelper->expects($this->once()) ->method('getCurrentPath') ->willReturn('/current/path/'); $this->objectManager->expects($this->at(0)) ->method('get') ->with('Magento\Theme\Model\Wysiwyg\Storage') ->willReturn($this->storage); $this->storage->expects($this->once()) ->method('deleteDirectory') ->with('/current/path/') ->willThrowException(new \Exception('Message')); $jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false); $jsonData->expects($this->once()) ->method('jsonEncode') ->with(['error' => true, 'message' => 'Message']) ->willReturn('{"error":"true","message":"Message"}'); $this->objectManager->expects($this->at(1)) ->method('get') ->with('Magento\Framework\Json\Helper\Data') ->willReturn($jsonData); $this->controller->executeInternal(); }
public function testGetTreeLoaderUrl() { $requestParams = [\Magento\Theme\Helper\Storage::PARAM_THEME_ID => 1, \Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE, \Magento\Theme\Helper\Storage::PARAM_NODE => 'root']; $expectedUrl = 'some_url'; $this->_helperStorage->expects($this->once())->method('getRequestParams')->will($this->returnValue($requestParams)); $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/*/treeJson', $requestParams)->will($this->returnValue($expectedUrl)); $this->assertEquals($expectedUrl, $this->_filesTree->getTreeLoaderUrl()); }
public function testExecute() { $this->request->expects($this->once())->method('isPost')->willReturn(true); $this->request->expects($this->once())->method('getParam')->with('files')->willReturn('{"files":"file"}'); $jsonData = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', [], [], '', false); $jsonData->expects($this->once())->method('jsonDecode')->with('{"files":"file"}')->willReturn(['files' => 'file']); $this->objectManager->expects($this->at(0))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->willReturn($jsonData); $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Theme\\Model\\Wysiwyg\\Storage')->willReturn($this->storage); $this->storage->expects($this->once())->method('deleteFile')->with('file'); $this->controller->execute(); }
public function testExecute() { $layout = $this->getMockForAbstractClass('Magento\Framework\View\LayoutInterface', [], '', false); $storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false); $block = $this->getMockForAbstractClass( 'Magento\Framework\View\Element\BlockInterface', [], '', false, false, true, ['setStorage'] ); $this->view->expects($this->once()) ->method('loadLayout') ->with('empty'); $this->view->expects($this->once()) ->method('getLayout') ->willReturn($layout); $layout->expects($this->once()) ->method('getBlock') ->with('wysiwyg_files.files') ->willReturn($block); $block->expects($this->once()) ->method('setStorage') ->with($storage); $this->objectManager->expects($this->at(0)) ->method('get') ->with('Magento\Theme\Model\Wysiwyg\Storage') ->willReturn($storage); $this->storage->expects($this->once()) ->method('getCurrentPath') ->willThrowException(new \Exception('Message')); $jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false); $jsonData->expects($this->once()) ->method('jsonEncode') ->with(['error' => true, 'message' => 'Message']) ->willReturn('{"error":"true","message":"Message"}'); $this->objectManager->expects($this->at(1)) ->method('get') ->with('Magento\Framework\Json\Helper\Data') ->willReturn($jsonData); $this->response->expects($this->once()) ->method('representJson'); $this->controller->executeInternal(); }
/** * Return tree node full path based on current path * * @return string */ public function getTreeCurrentPath() { $treePath = '/root'; $path = $this->_storageHelper->getSession()->getCurrentPath(); if ($path) { $path = str_replace($this->_storageHelper->getStorageRoot(), '', $path); $relative = ''; foreach (explode('/', $path) as $dirName) { if ($dirName) { $relative .= '/' . $dirName; $treePath .= '/' . $this->urlEncoder->encode($relative); } } } return $treePath; }
/** * Copy file to tmp theme customization path * * @param string $sourceFile * @return string */ protected function _copyFileToTmpCustomizationPath($sourceFile) { $targetFile = $this->_helperStorage->getStorageRoot() . '/' . basename($sourceFile); $this->directoryTmp->create(pathinfo($targetFile, PATHINFO_DIRNAME)); $this->directoryVar->copyFile($this->directoryVar->getRelativePath($sourceFile), $this->directoryTmp->getRelativePath($targetFile), $this->directoryTmp); return $targetFile; }
/** * Delete directory * * @param string $path * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function deleteDirectory($path) { $rootCmp = rtrim($this->_helper->getStorageRoot(), '/'); $pathCmp = rtrim($path, '/'); if ($rootCmp == $pathCmp) { throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t delete root directory %1 right now.', $path)); } return $this->mediaWriteDirectory->delete($path); }
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(array('ttf', 'otf', 'eot', 'svg', 'woff'), $fontTypes); $imagesTypes = $this->helper->getAllowedExtensionsByType(); $this->assertEquals(array('jpg', 'jpeg', 'gif', 'png', 'xbm', 'wbmp'), $imagesTypes); }
public function testGetContentsUrl() { $expectedUrl = 'some_url'; $expectedRequest = 'some_request'; $requestParams = [\Magento\Theme\Helper\Storage::PARAM_THEME_ID => 1, \Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE, \Magento\Theme\Helper\Storage::PARAM_NODE => 'root']; $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/*/contents', ['type' => $expectedRequest] + $requestParams)->will($this->returnValue($expectedUrl)); $this->_request->expects($this->once())->method('getParam')->with('type')->will($this->returnValue($expectedRequest)); $this->_helperStorage->expects($this->once())->method('getRequestParams')->will($this->returnValue($requestParams)); $this->assertEquals($expectedUrl, $this->_filesContent->getContentsUrl()); }
/** * @test * @return void * @expectedException \InvalidArgumentException * @expectedExceptionMessage Theme was not found */ public function testGetThemeNotFound() { $this->themeFactory->expects($this->once())->method('create')->willReturn(null); $helper = new \Magento\Theme\Helper\Storage($this->contextHelper, $this->filesystem, $this->session, $this->themeFactory); $helper->getStorageRoot(); }
/** * @test * @return void * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid type */ public function testGetStorageTypeNameInvalid() { $this->helper->getStorageTypeName(); }
/** * Insert file action target URL * * @return string */ public function getOnInsertUrl() { return $this->getUrl('adminhtml/*/onInsert', $this->_storageHelper->getRequestParams()); }
/** * Prepare layout * * @return \Magento\Backend\Block\Media\Uploader */ protected function _prepareLayout() { $this->getConfig()->setUrl($this->getUrl('adminhtml/*/upload', $this->_storageHelper->getRequestParams())); return parent::_prepareLayout(); }
/** * cover \Magento\Theme\Model\Wysiwyg\Storage::deleteDirectory * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testDeleteRootDirectory() { $directoryPath = $this->_storageRoot; $this->_helperStorage->expects($this->atLeastOnce())->method('getStorageRoot')->will($this->returnValue($this->_storageRoot)); $this->_storageModel->deleteDirectory($directoryPath); }
/** * @return string */ public function getStorageType() { return __($this->_storageHelper->getStorageType()); }