示例#1
0
 /**
  * Redirect user to Google Captcha challenge
  *
  * @param \Zend_Gdata_App_CaptchaRequiredException $e
  * @return void
  */
 protected function _redirectToCaptcha($e)
 {
     $redirectUrl = $this->getUrl('*/*/index', ['store' => $this->_getStore()->getId(), 'captcha_token' => $this->urlEncoder->encode($e->getCaptchaToken()), 'captcha_url' => $this->urlEncoder->encode($e->getCaptchaUrl())]);
     if ($this->getRequest()->isAjax()) {
         $this->getResponse()->representJson($this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode(['redirect' => $redirectUrl]));
     } else {
         $this->_redirect($redirectUrl);
     }
 }
示例#2
0
 /**
  * @covers \Magento\Eav\Model\Attribute\Data\File::outputValue
  *
  * @param string $format
  * @param mixed $value
  * @param mixed $expectedResult
  * @param int $callTimes
  * @dataProvider outputValueDataProvider
  */
 public function testOutputValue($format, $value, $callTimes, $expectedResult)
 {
     $entityMock = $this->getMock('\\Magento\\Framework\\Model\\AbstractModel', [], [], '', false);
     $entityMock->expects($this->once())->method('getData')->will($this->returnValue($value));
     $attributeMock = $this->getMock('\\Magento\\Eav\\Model\\Attribute', [], [], '', false);
     $this->urlEncoder->expects($this->exactly($callTimes))->method('encode')->will($this->returnValue('url_key'));
     $this->model->setEntity($entityMock);
     $this->model->setAttribute($attributeMock);
     $this->assertEquals($expectedResult, $this->model->outputValue($format));
 }
示例#3
0
 public function testGetPreviewFile()
 {
     $value = 'image.jpg';
     $url = 'http://example.com/backend/customer/index/viewfile/' . $value;
     $formMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->disableOriginalConstructor()->getMock();
     $this->image->setForm($formMock);
     $this->image->setValue($value);
     $this->urlEncoder->expects($this->once())->method('encode')->with($value)->will($this->returnArgument(0));
     $this->backendHelperMock->expects($this->once())->method('getUrl')->with('customer/index/viewfile', ['image' => $value])->will($this->returnValue($url));
     $this->assertContains($url, $this->image->getElementHtml());
 }
示例#4
0
 protected function setUp()
 {
     $this->_fixtureCustomerId = 1;
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_customerSession = $this->_objectManager->create('Magento\\Customer\\Model\\Session');
     $this->urlEncoder = $this->_objectManager->create('Magento\\Framework\\Url\\EncoderInterface');
     $this->_contextHelper = $this->_objectManager->create('Magento\\Framework\\App\\Helper\\Context');
     $request = $this->_contextHelper->getRequest();
     $request->setParam('data', $this->urlEncoder->encode($this->_fixtureCustomerId));
     $this->_wishlistHelper = $this->_objectManager->create('Magento\\Wishlist\\Helper\\Rss', ['context' => $this->_contextHelper, 'customerSession' => $this->_customerSession]);
     $this->_customerSession->loginById($this->_fixtureCustomerId);
 }
示例#5
0
文件: Items.php 项目: opexsw/magento2
 /**
  * Redirect user to Google Captcha challenge
  *
  * @param \Zend_Gdata_App_CaptchaRequiredException $e
  * @return \Magento\Framework\Controller\ResultInterface
  */
 protected function _redirectToCaptcha($e)
 {
     $redirectUrl = $this->getUrl('*/*/index', ['store' => $this->_getStore()->getId(), 'captcha_token' => $this->urlEncoder->encode($e->getCaptchaToken()), 'captcha_url' => $this->urlEncoder->encode($e->getCaptchaUrl())]);
     if ($this->getRequest()->isAjax()) {
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
         return $resultJson->setData(['redirect' => $redirectUrl]);
     } else {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
         return $resultRedirect->setUrl($redirectUrl);
     }
 }
示例#6
0
 /**
  * Retrieve parameters of customer login url
  *
  * @return array
  */
 public function getLoginUrlParams()
 {
     $params = [];
     $referer = $this->request->getParam(self::REFERER_QUERY_PARAM_NAME);
     if (!$referer && !$this->scopeConfig->isSetFlag(self::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, ScopeInterface::SCOPE_STORE) && !$this->customerSession->getNoReferer()) {
         $referer = $this->urlBuilder->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
         $referer = $this->urlEncoder->encode($referer);
     }
     if ($referer) {
         $params = [self::REFERER_QUERY_PARAM_NAME => $referer];
     }
     return $params;
 }
示例#7
0
 /**
  * @return string
  */
 protected function getLinkParams()
 {
     $params = [];
     $wishlistId = $this->wishlistHelper->getWishlist()->getId();
     $customer = $this->wishlistHelper->getCustomer();
     if ($customer) {
         $key = $customer->getId() . ',' . $customer->getEmail();
         $params = ['type' => 'wishlist', 'data' => $this->urlEncoder->encode($key), '_secure' => false];
     }
     if ($wishlistId) {
         $params['wishlist_id'] = $wishlistId;
     }
     return $params;
 }
示例#8
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;
 }
 /**
  * Get add to wishlist params
  *
  * @param Product $product
  * @return string
  */
 public function getAddToWishlistParams($product)
 {
     $continueUrl = $this->urlEncoder->encode($this->getUrl('customer/account'));
     $urlParamName = Action::PARAM_NAME_URL_ENCODED;
     $continueUrlParams = [$urlParamName => $continueUrl];
     return $this->_wishlistHelper->getAddParams($product, $continueUrlParams);
 }
示例#10
0
 /**
  * Get files collection
  *
  * @return array
  */
 public function getFilesCollection()
 {
     $paths = $this->mediaWriteDirectory->search('.*', $this->_helper->getCurrentPath());
     $files = [];
     $requestParams = $this->_helper->getRequestParams();
     $storageType = $this->_helper->getStorageType();
     foreach ($paths as $path) {
         if (!$this->mediaWriteDirectory->isFile($path)) {
             continue;
         }
         $fileName = pathinfo($path, PATHINFO_BASENAME);
         $file = ['text' => $fileName, 'id' => $this->urlEncoder->encode($fileName)];
         if (self::TYPE_IMAGE == $storageType) {
             $requestParams['file'] = $fileName;
             $file['thumbnailParams'] = $requestParams;
             $size = @getimagesize($path);
             if (is_array($size)) {
                 $file['width'] = $size[0];
                 $file['height'] = $size[1];
             }
         }
         $files[] = $file;
     }
     return $files;
 }
示例#11
0
 /**
  * @param string $baseUrl
  * @param string $fileName
  * @param bool $isUsingStaticUrls
  * @param string $expectedHtml
  * @dataProvider providerGetImageHtmlDeclaration
  */
 public function testGetImageHtmlDeclaration($baseUrl, $fileName, $isUsingStaticUrls, $expectedHtml)
 {
     $directive = '{{media url="/' . $fileName . '"}}';
     $this->generalSettingsGetImageHtmlDeclaration($baseUrl, $isUsingStaticUrls);
     $this->urlEncoderMock->expects($this->any())->method('encode')->with($directive)->willReturn($directive);
     $this->backendDataMock->expects($this->any())->method('getUrl')->with('cms/wysiwyg/directive', ['___directive' => $directive])->willReturn($directive);
     $this->assertEquals($expectedHtml, $this->imagesHelper->getImageHtmlDeclaration($fileName));
 }
示例#12
0
 protected function setUp()
 {
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     /** @var \Magento\Framework\App\Helper\Context $context */
     $context = $objectManagerHelper->getObject('Magento\\Framework\\App\\Helper\\Context', ['httpRequest' => $this->requestMock]);
     $className = 'Magento\\Checkout\\Helper\\Cart';
     $arguments = $objectManagerHelper->getConstructArguments($className, ['context' => $context]);
     $this->urlBuilderMock = $context->getUrlBuilder();
     $this->urlEncoder = $context->getUrlEncoder();
     $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) {
         return strtr(base64_encode($url), '+/=', '-_,');
     });
     $this->scopeConfigMock = $context->getScopeConfig();
     $this->cartMock = $arguments['checkoutCart'];
     $this->checkoutSessionMock = $arguments['checkoutSession'];
     $this->helper = $objectManagerHelper->getObject($className, $arguments);
 }
示例#13
0
 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->urlEncoder->encode($this->getUrl('*/*/*', ['_current' => true]) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', [Url::REFERER_QUERY_PARAM_NAME => $queryParam]));
     }
     $this->setTemplate('form.phtml');
 }
 protected function setUp()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['getId', 'getSharingCode'], [], '', false);
     $wishlist->expects($this->any())->method('getId')->will($this->returnValue(5));
     $wishlist->expects($this->any())->method('getSharingCode')->will($this->returnValue('somesharingcode'));
     $customer = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $customer->expects($this->any())->method('getId')->will($this->returnValue(8));
     $customer->expects($this->any())->method('getEmail')->will($this->returnValue('*****@*****.**'));
     $this->wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['getWishlist', 'getCustomer', 'urlEncode'], [], '', false);
     $this->urlEncoder = $this->getMock('Magento\\Framework\\Url\\EncoderInterface', ['encode'], [], '', false);
     $this->wishlistHelper->expects($this->any())->method('getWishlist')->will($this->returnValue($wishlist));
     $this->wishlistHelper->expects($this->any())->method('getCustomer')->will($this->returnValue($customer));
     $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) {
         return strtr(base64_encode($url), '+/=', '-_,');
     });
     $this->urlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->link = $this->objectManagerHelper->getObject('Magento\\Wishlist\\Block\\Rss\\EmailLink', ['wishlistHelper' => $this->wishlistHelper, 'rssUrlBuilder' => $this->urlBuilder, 'urlEncoder' => $this->urlEncoder]);
 }
示例#15
0
 protected function setUp()
 {
     $this->urlBuilderMock = $this->getMock('Magento\\Framework\\UrlInterface');
     $this->urlEncoder = $this->getMockBuilder('Magento\\Framework\\Url\\EncoderInterface')->getMock();
     $this->urlEncoder->expects($this->any())->method('encode')->willReturnCallback(function ($url) {
         return strtr(base64_encode($url), '+/=', '-_,');
     });
     $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\RequestInterface', ['getRouteName', 'getControllerName', 'getParam', 'setActionName', 'getActionName', 'setModuleName', 'getModuleName', 'getCookie']);
     $contextMock = $this->getMock('\\Magento\\Framework\\App\\Helper\\Context', [], [], '', false);
     $contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($this->urlBuilderMock));
     $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
     $contextMock->expects($this->any())->method('getUrlEncoder')->will($this->returnValue($this->urlEncoder));
     $this->storeManagerMock = $this->getMock('\\Magento\\Framework\\Store\\StoreManagerInterface');
     $this->coreHelperMock = $this->getMock('\\Magento\\Core\\Helper\\Data', [], [], '', false);
     $this->scopeConfigMock = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->cartMock = $this->getMock('\\Magento\\Checkout\\Model\\Cart', [], [], '', false);
     $this->checkoutSessionMock = $this->getMock('\\Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->helper = new Cart($contextMock, $this->storeManagerMock, $this->scopeConfigMock, $this->cartMock, $this->checkoutSessionMock);
 }
示例#16
0
 /**
  * {@inheritdoc}
  */
 public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
 {
     $output = '';
     if ($this->_value) {
         switch ($format) {
             case \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_JSON:
                 $output = ['value' => $this->_value, 'url_key' => $this->urlEncoder->encode($this->_value)];
                 break;
         }
     }
     return $output;
 }
示例#17
0
 /**
  * Retrieve url for direct adding product to cart
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $additional
  * @return string
  */
 public function getAddToCartUrl($product, $additional = [])
 {
     if ($this->hasCustomAddToCartUrl()) {
         return $this->getCustomAddToCartUrl();
     }
     if ($this->getRequest()->getParam('wishlist_next')) {
         $additional['wishlist_next'] = 1;
     }
     $addUrlKey = \Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED;
     $addUrlValue = $this->_urlBuilder->getUrl('*/*/*', ['_use_rewrite' => true, '_current' => true]);
     $additional[$addUrlKey] = $this->urlEncoder->encode($addUrlValue);
     return $this->_cartHelper->getAddUrl($product, $additional);
 }
示例#18
0
 public function testGetRemoveParamsWithReferer()
 {
     $url = 'result url';
     $wishlistItemId = 1;
     $referer = 'referer';
     $refererEncoded = 'referer_encoded';
     $this->wishlistItem->expects($this->once())->method('getWishlistItemId')->willReturn($wishlistItemId);
     $this->requestMock->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer);
     $this->urlEncoderMock->expects($this->once())->method('encode')->with($referer)->willReturn($refererEncoded);
     $this->urlBuilder->expects($this->once())->method('getUrl')->with('wishlist/index/remove', [])->willReturn($url);
     $this->postDataHelper->expects($this->once())->method('getPostData')->with($url, ['item' => $wishlistItemId, ActionInterface::PARAM_NAME_URL_ENCODED => $refererEncoded])->willReturn($url);
     $this->assertEquals($url, $this->model->getRemoveParams($this->wishlistItem, true));
 }
示例#19
0
 /**
  * Return formated attribute value from entity model
  *
  * @param string $format
  * @return string|array
  */
 public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT)
 {
     $output = '';
     $value = $this->getEntity()->getData($this->getAttribute()->getAttributeCode());
     if ($value) {
         switch ($format) {
             case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON:
                 $output = ['value' => $value, 'url_key' => $this->urlEncoder->encode($value)];
                 break;
         }
     }
     return $output;
 }
示例#20
0
 /**
  * @covers \Magento\Theme\Helper\Storage::convertPathToId
  * @covers \Magento\Theme\Helper\Storage::convertIdToPath
  */
 public function testConvertPathToIdAndIdToPath()
 {
     $path = '/image/path/to';
     $this->urlEncoder->expects($this->once())->method('encode')->with('/path/to')->willReturnCallback(function ($path) {
         return base64_encode($path);
     });
     $this->urlDecoder->expects($this->once())->method('decode')->with(base64_encode('/path/to'))->willReturnCallback(function ($path) {
         return base64_decode($path);
     });
     $value = $this->helper->convertPathToId($path);
     $this->assertEquals(base64_encode('/path/to'), $value);
     $this->assertEquals($path, $this->helper->convertIdToPath($value));
 }
示例#21
0
文件: Form.php 项目: opexsw/magento2
 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $data = $this->_reviewSession->getFormData(true);
     $data = new \Magento\Framework\Object((array) $data);
     // add logged in customer name as nickname
     if (!$data->getNickname()) {
         $customer = $this->_customerSession->getCustomerDataObject();
         if ($customer && $customer->getId()) {
             $data->setNickname($customer->getFirstname());
         }
     }
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->urlEncoder->encode($this->getUrl('*/*/*', ['_current' => true]) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', [Url::REFERER_QUERY_PARAM_NAME => $queryParam]));
     }
     $this->setTemplate('form.phtml')->assign('data', $data);
 }
示例#22
0
 /**
  * @param array $params
  * @return string
  */
 public function getPagerEncodedUrl($params = [])
 {
     return $this->urlEncoder->encode($this->getPagerUrl($params));
 }
示例#23
0
 /**
  * Get url to download CSS file
  *
  * @param string $fileId
  * @param int $themeId
  * @return string
  */
 public function getDownloadUrl($fileId, $themeId)
 {
     return $this->getUrl('adminhtml/system_design_theme/downloadCss', ['theme_id' => $themeId, 'file' => $this->urlEncoder->encode($fileId)]);
 }
示例#24
0
 /**
  * Return Preview/Download URL
  *
  * @return string
  */
 protected function _getPreviewUrl()
 {
     return $this->_adminhtmlData->getUrl('customer/index/viewfile', ['file' => $this->urlEncoder->encode($this->getValue())]);
 }
示例#25
0
 /**
  * Return encoded current URL for after auth redirection
  * @return string
  */
 public function getLoginUrl()
 {
     $referer = $this->urlEncoder->encode($this->_urlBuilder->getCurrentUrl());
     return $this->getUrl('facebookfree/index/index', array('referer' => $referer));
 }
示例#26
0
 /**
  * Encode list of widget types into query param
  *
  * @param string[]|string $widgets List of widgets
  * @return string Query param value
  */
 public function encodeWidgetsToQuery($widgets)
 {
     $widgets = is_array($widgets) ? $widgets : [$widgets];
     $param = implode(',', $widgets);
     return $this->urlEncoder->encode($param);
 }