Пример #1
0
 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();
 }
Пример #2
0
    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();
    }
Пример #3
0
 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());
 }
Пример #4
0
 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();
 }
Пример #5
0
    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();
    }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 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);
 }
Пример #10
0
 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());
 }
Пример #11
0
 /**
  * @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();
 }
Пример #12
0
 /**
  * @test
  * @return void
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Invalid type
  */
 public function testGetStorageTypeNameInvalid()
 {
     $this->helper->getStorageTypeName();
 }
Пример #13
0
 /**
  * Insert file action target URL
  *
  * @return string
  */
 public function getOnInsertUrl()
 {
     return $this->getUrl('adminhtml/*/onInsert', $this->_storageHelper->getRequestParams());
 }
Пример #14
0
 /**
  * Prepare layout
  *
  * @return \Magento\Backend\Block\Media\Uploader
  */
 protected function _prepareLayout()
 {
     $this->getConfig()->setUrl($this->getUrl('adminhtml/*/upload', $this->_storageHelper->getRequestParams()));
     return parent::_prepareLayout();
 }
Пример #15
0
 /**
  * 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);
 }
Пример #16
0
 /**
  * @return string
  */
 public function getStorageType()
 {
     return __($this->_storageHelper->getStorageType());
 }