public function testExecuteWithItems()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['items', null, '1,2,3'], ['uenc', null, null]]);
     $this->decoderMock->expects($this->never())->method('decode');
     $this->catalogSession->expects($this->never())->method('setBeforeCompareUrl');
     $this->listCompareMock->expects($this->once())->method('addProducts')->with([1, 2, 3]);
     $redirect = $this->getMock('Magento\\Framework\\Controller\\Result\\Redirect', ['setPath'], [], '', false);
     $redirect->expects($this->once())->method('setPath')->with('*/*/*');
     $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($redirect);
     $this->index->execute();
 }
Example #2
0
 /**
  * Customer view file action
  *
  * @return void
  * @throws NotFoundException
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function executeInternal()
 {
     $file = null;
     $plain = false;
     if ($this->getRequest()->getParam('file')) {
         // download file
         $file = $this->urlDecoder->decode($this->getRequest()->getParam('file'));
     } elseif ($this->getRequest()->getParam('image')) {
         // show plain image
         $file = $this->urlDecoder->decode($this->getRequest()->getParam('image'));
         $plain = true;
     } else {
         throw new NotFoundException(__('Page not found.'));
     }
     /** @var \Magento\Framework\Filesystem $filesystem */
     $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
     $fileName = 'customer' . '/' . ltrim($file, '/');
     $path = $directory->getAbsolutePath($fileName);
     if (!$directory->isFile($fileName) && !$this->_objectManager->get('Magento\\MediaStorage\\Helper\\File\\Storage')->processStorageFile($path)) {
         throw new NotFoundException(__('Page not found.'));
     }
     if ($plain) {
         $extension = pathinfo($path, PATHINFO_EXTENSION);
         switch (strtolower($extension)) {
             case 'gif':
                 $contentType = 'image/gif';
                 break;
             case 'jpg':
                 $contentType = 'image/jpeg';
                 break;
             case 'png':
                 $contentType = 'image/png';
                 break;
             default:
                 $contentType = 'application/octet-stream';
                 break;
         }
         $stat = $directory->stat($path);
         $contentLength = $stat['size'];
         $contentModify = $stat['mtime'];
         /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', $contentLength)->setHeader('Last-Modified', date('r', $contentModify));
         $resultRaw->setContents($directory->readFile($fileName));
         return $resultRaw;
     } else {
         $name = pathinfo($path, PATHINFO_BASENAME);
         $this->_fileFactory->create($name, ['type' => 'filename', 'value' => $fileName], DirectoryList::MEDIA);
     }
 }
Example #3
0
 /**
  * Compare index action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $items = $this->getRequest()->getParam('items');
     $beforeUrl = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED);
     if ($beforeUrl) {
         $this->_catalogSession->setBeforeCompareUrl($this->urlDecoder->decode($beforeUrl));
     }
     if ($items) {
         $items = explode(',', $items);
         /** @var \Magento\Catalog\Model\Product\Compare\ListCompare $list */
         $list = $this->_catalogProductCompareList;
         $list->addProducts($items);
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('*/*/*');
     }
     return $this->resultPageFactory->create();
 }
 /**
  * Confirm CAPTCHA
  *
  * @return void
  */
 public function execute()
 {
     $storeId = $this->_getStore()->getId();
     try {
         $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Service')->getClient($storeId, $this->urlDecoder->decode($this->getRequest()->getParam('captcha_token')), $this->getRequest()->getParam('user_confirm'));
         $this->messageManager->addSuccess(__('Captcha has been confirmed.'));
     } catch (\Zend_Gdata_App_CaptchaRequiredException $e) {
         $this->messageManager->addError(__('There was a Captcha confirmation error: %1', $e->getMessage()));
         $this->_redirectToCaptcha($e);
         return;
     } catch (\Zend_Gdata_App_Exception $e) {
         $this->messageManager->addError($this->_objectManager->get('Magento\\GoogleShopping\\Helper\\Data')->parseGdataExceptionMessage($e->getMessage()));
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError(__('Something went wrong during Captcha confirmation.'));
     }
     $this->_redirect('adminhtml/*/index', ['store' => $storeId]);
 }
 /**
  * @cover \Magento\Theme\Model\Wysiwyg\Storage::deleteFile
  */
 public function testDeleteFile()
 {
     $image = 'image.jpg';
     $this->_helperStorage->expects($this->once())->method('getCurrentPath')->will($this->returnValue($this->_storageRoot));
     $this->urlDecoder->expects($this->any())->method('decode')->with($image)->willReturnArgument(0);
     $this->directoryWrite->expects($this->at(0))->method('getRelativePath')->with($this->_storageRoot)->willReturn($this->_storageRoot);
     $this->directoryWrite->expects($this->at(1))->method('getRelativePath')->with($this->_storageRoot . '/' . $image)->willReturn($this->_storageRoot . '/' . $image);
     $this->_helperStorage->expects($this->once())->method('getStorageRoot')->willReturn('/');
     $this->directoryWrite->expects($this->any())->method('delete');
     $this->assertInstanceOf('Magento\\Theme\\Model\\Wysiwyg\\Storage', $this->_storageModel->deleteFile($image));
 }
Example #6
0
 protected function prepareExecuteTest()
 {
     $directiveParam = 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19';
     $directive = '{{media url="wysiwyg/image.jpg"}}';
     $this->requestMock->expects($this->once())->method('getParam')->with('___directive')->willReturn($directiveParam);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($directiveParam)->willReturn($directive);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Template\\Filter')->willReturn($this->templateFilterMock);
     $this->templateFilterMock->expects($this->once())->method('filter')->with($directive)->willReturn(self::IMAGE_PATH);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Image\\AdapterFactory', $this->imageAdapterFactoryMock], ['Magento\\Cms\\Model\\Wysiwyg\\Config', $this->wysiwygConfigMock], ['Psr\\Log\\LoggerInterface', $this->loggerMock]]);
     $this->imageAdapterFactoryMock->expects($this->once())->method('create')->willReturn($this->imageAdapterMock);
 }
Example #7
0
 /**
  * Manage Items page with two item grids: Magento products and Google Content items
  *
  * @return void
  */
 public function execute()
 {
     if (0 === (int) $this->getRequest()->getParam('store')) {
         $this->_redirect('adminhtml/*/', ['store' => $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId(), '_current' => true]);
         return;
     }
     $this->_initAction();
     $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Google Content Items'));
     $contentBlock = $this->_view->getLayout()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Items')->setStore($this->_getStore());
     if ($this->getRequest()->getParam('captcha_token') && $this->getRequest()->getParam('captcha_url')) {
         $contentBlock->setGcontentCaptchaToken($this->urlDecoder->decode($this->getRequest()->getParam('captcha_token')));
         $contentBlock->setGcontentCaptchaUrl($this->urlDecoder->decode($this->getRequest()->getParam('captcha_url')));
     }
     if (!$this->_objectManager->get('Magento\\GoogleShopping\\Model\\Config')->isValidDefaultCurrencyCode($this->_getStore()->getId())) {
         $_countryInfo = $this->_objectManager->get('Magento\\GoogleShopping\\Model\\Config')->getTargetCountryInfo($this->_getStore()->getId());
         $this->messageManager->addNotice(__("The store's currency should be set to %1 for %2 in system configuration. Otherwise item prices won't be correct in Google Content.", $_countryInfo['currency_name'], $_countryInfo['name']));
     }
     $this->_addBreadcrumb(__('Items'), __('Items'))->_addContent($contentBlock);
     $this->_view->renderLayout();
 }
Example #8
0
 public function testGetRelativeUrl()
 {
     $filename = base64_encode('filename.ext');
     $notRoot = base64_encode('not/a/root');
     $this->request->expects($this->any())->method('getParam')->willReturnMap(['type' => [\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE, null, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE], 'node' => [\Magento\Theme\Helper\Storage::PARAM_NODE, null, $notRoot], 'filenaem' => [\Magento\Theme\Helper\Storage::PARAM_FILENAME, null, $filename]]);
     $decode = function ($value) {
         return base64_decode($value);
     };
     $this->urlDecoder->expects($this->at(0))->method('decode')->with($notRoot)->willReturnCallback($decode);
     $this->urlDecoder->expects($this->at(1))->method('decode')->with($filename)->willReturnCallback($decode);
     $this->assertEquals('../image/not/a/root/filename.ext', $this->helper->getRelativeUrl());
 }
Example #9
0
 /**
  * Delete file
  *
  * @param string $file
  * @return \Magento\Theme\Model\Wysiwyg\Storage
  */
 public function deleteFile($file)
 {
     $file = $this->urlDecoder->decode($file);
     $path = $this->mediaWriteDirectory->getRelativePath($this->_helper->getCurrentPath());
     $filePath = $this->mediaWriteDirectory->getRelativePath($path . '/' . $file);
     $thumbnailPath = $this->_helper->getThumbnailDirectory($filePath) . '/' . $file;
     if (0 === strpos($filePath, $path) && 0 === strpos($filePath, $this->_helper->getStorageRoot())) {
         $this->mediaWriteDirectory->delete($filePath);
         $this->mediaWriteDirectory->delete($thumbnailPath);
     }
     return $this;
 }
Example #10
0
 /**
  * Template directives callback
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $directive = $this->getRequest()->getParam('___directive');
     $directive = $this->urlDecoder->decode($directive);
     $imagePath = $this->_objectManager->create('Stepzerosolutions\\Tbslider\\Model\\Template\\Filter')->filter($directive);
     /** @var \Magento\Framework\Image\Adapter\AdapterInterface $image */
     $image = $this->_objectManager->get('Magento\\Framework\\Image\\AdapterFactory')->create();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     try {
         $image->open($imagePath);
         $resultRaw->setHeader('Content-Type', $image->getMimeType());
         $resultRaw->setContents($image->getImage());
     } catch (\Exception $e) {
         $imagePath = $this->_objectManager->get('Stepzerosolutions\\Tbslider\\Model\\Wysiwyg\\Config')->getSkinImagePlaceholderPath();
         $image->open($imagePath);
         $resultRaw->setHeader('Content-Type', $image->getMimeType());
         $resultRaw->setContents($image->getImage());
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
     }
     return $resultRaw;
 }
Example #11
0
 /**
  * Manage Items page with two item grids: Magento products and Google Content items
  *
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     if (0 === (int) $this->getRequest()->getParam('store')) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
         return $resultRedirect->setPath('adminhtml/*/', ['store' => $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId(), '_current' => true]);
     }
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
     $resultPage->setActiveMenu('Magento_GoogleShopping::catalog_googleshopping_items')->addBreadcrumb(__('Catalog'), __('Catalog'))->addBreadcrumb(__('Google Content'), __('Google Content'));
     $resultPage->getConfig()->getTitle()->prepend(__('Google Content Items'));
     $contentBlock = $resultPage->getLayout()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Items')->setStore($this->_getStore());
     if ($this->getRequest()->getParam('captcha_token') && $this->getRequest()->getParam('captcha_url')) {
         $contentBlock->setGcontentCaptchaToken($this->urlDecoder->decode($this->getRequest()->getParam('captcha_token')));
         $contentBlock->setGcontentCaptchaUrl($this->urlDecoder->decode($this->getRequest()->getParam('captcha_url')));
     }
     if (!$this->_objectManager->get('Magento\\GoogleShopping\\Model\\Config')->isValidDefaultCurrencyCode($this->_getStore()->getId())) {
         $_countryInfo = $this->_objectManager->get('Magento\\GoogleShopping\\Model\\Config')->getTargetCountryInfo($this->_getStore()->getId());
         $this->messageManager->addNotice(__("The store's currency should be set to %1 for %2 in system configuration." . " Otherwise item prices won't be correct in Google Content.", $_countryInfo['currency_name'], $_countryInfo['name']));
     }
     return $resultPage->addBreadcrumb(__('Items'), __('Items'))->addContent($contentBlock);
 }
Example #12
0
 public function testGetCustomerWithSession()
 {
     $customerId = 1;
     $data = $customerId . ',2';
     $this->urlDecoderMock->expects($this->any())->method('decode')->willReturnArgument(0);
     $this->requestMock->expects($this->once())->method('getParam')->with('data', null)->willReturn($data);
     $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->customerFactoryMock->expects($this->never())->method('create');
     $this->assertEquals($customer, $this->model->getCustomer());
     // Check that customer is cached
     $this->assertSame($customer, $this->model->getCustomer());
 }
 /**
  * Prepare redirect URL for logged in customer
  *
  * Redirect customer to the last page visited after logging in.
  *
  * @return void
  */
 protected function processLoggedCustomer()
 {
     // Set default redirect URL for logged in customer
     $this->applyRedirect($this->customerUrl->getAccountUrl());
     if (!$this->scopeConfig->isSetFlag(CustomerUrl::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, ScopeInterface::SCOPE_STORE)) {
         $referer = $this->request->getParam(CustomerUrl::REFERER_QUERY_PARAM_NAME);
         if ($referer) {
             $referer = $this->urlDecoder->decode($referer);
             if ($this->url->isOwnOriginUrl()) {
                 $this->applyRedirect($referer);
             }
         }
     } elseif ($this->session->getAfterAuthUrl()) {
         $this->applyRedirect($this->session->getAfterAuthUrl(true));
     }
 }
Example #14
0
 public function testExecuteGetParamImage()
 {
     $decodedFile = 'decoded_file';
     $file = 'file';
     $fileName = 'customer/' . $file;
     $path = 'path';
     $stat = ['size' => 10, 'mtime' => 10];
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['file', null, null], ['image', null, $decodedFile]]);
     $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
     $this->directoryMock->expects($this->once())->method('stat')->with($path)->willReturn($stat);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->willReturn($this->directoryMock);
     $this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
     $this->objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Filesystem', $this->fileSystemMock], ['Magento\\MediaStorage\\Helper\\File\\Storage', $this->storage]]);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
     $this->resultRawMock->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->resultRawMock->expects($this->any())->method('setHeader')->willReturnMap([['Pragma', 'public', true, $this->resultRawMock], ['Content-type', 'application/octet-stream', true, $this->resultRawMock], ['Content-Length', $stat['size'], false, $this->resultRawMock], ['Pragma', 'public', true, $this->resultRawMock]]);
     $this->resultRawFactoryMock = $this->getMock('Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     /** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
     $controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Viewfile', ['context' => $this->contextMock, 'urlDecoder' => $this->urlDecoderMock, 'resultRawFactory' => $this->resultRawFactoryMock]);
     $this->assertSame($this->resultRawMock, $controller->execute());
 }
Example #15
0
 /**
  * Decode URL query param and return list of widgets
  *
  * @param string $queryParam Query param value to decode
  * @return string[] Array of widget types
  */
 public function decodeWidgetsFromQuery($queryParam)
 {
     $param = $this->urlDecoder->decode($queryParam);
     return preg_split('/\\s*\\,\\s*/', $param, 0, PREG_SPLIT_NO_EMPTY);
 }