本文整理汇总了PHP中Magento\Framework\Escaper类的典型用法代码示例。如果您正苦于以下问题:PHP Escaper类的具体用法?PHP Escaper怎么用?PHP Escaper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Escaper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->methodMock = $this->getMock('Magento\\OfflinePayments\\Model\\Checkmo', [], [], '', false);
$paymentHelperMock = $this->getMock('Magento\\Payment\\Helper\\Data', [], [], '', false);
$paymentHelperMock->expects($this->once())->method('getMethodInstance')->with(Checkmo::PAYMENT_METHOD_CHECKMO_CODE)->willReturn($this->methodMock);
$this->escaperMock = $this->getMock('Magento\\Framework\\Escaper');
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
$this->model = new CheckmoConfigProvider($paymentHelperMock, $this->escaperMock);
}
示例2: setUp
protected function setUp()
{
$this->escaperMock = $this->getMock('Magento\\Framework\\Escaper', [], [], '', false);
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
$this->contextMock = $this->getMock('Magento\\Backend\\Block\\Context', ['getEscaper'], [], '', false);
$this->contextMock->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaperMock));
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->buttonRenderer = $this->objectManagerHelper->getObject('Magento\\Integration\\Block\\Adminhtml\\Widget\\Grid\\Column\\Renderer\\Button', ['context' => $this->contextMock]);
}
示例3: setUp
protected function setUp()
{
$this->methodOneMock = $this->getMock('Magento\\Payment\\Model\\Method\\AbstractMethod', ['isAvailable', 'getInstructions'], [], '', false);
$this->methodTwoMock = $this->getMock('Magento\\Payment\\Model\\Method\\AbstractMethod', ['isAvailable', 'getInstructions'], [], '', false);
$paymentHelperMock = $this->getMock('Magento\\Payment\\Helper\\Data', [], [], '', false);
$paymentHelperMock->expects($this->exactly(2))->method('getMethodInstance')->willReturnMap([[Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE, $this->methodOneMock], [Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE, $this->methodTwoMock]]);
$this->escaperMock = $this->getMock('Magento\\Framework\\Escaper');
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
$this->model = new InstructionsConfigProvider($paymentHelperMock, $this->escaperMock);
}
示例4: testEmulateWelcomeBlock
/**
* @magentoConfigFixture current_store persistent/options/enabled 1
* @magentoConfigFixture current_store persistent/options/remember_enabled 1
* @magentoConfigFixture current_store persistent/options/remember_default 1
* @magentoAppArea frontend
* @magentoAppIsolation enabled
*/
public function testEmulateWelcomeBlock()
{
$this->_customerSession->loginById(1);
$httpContext = new \Magento\Framework\App\Http\Context();
$httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
$block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
$this->_observer->emulateWelcomeBlock($block);
$customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
$translation = __('Welcome, %1!', $customerName);
$this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
$this->_customerSession->logout();
}
示例5: execute
/**
* Register form key in session from cookie value
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->cookieFormKey->get()) {
$this->updateCookieFormKey($this->cookieFormKey->get());
$this->sessionFormKey->set($this->escaper->escapeHtml($this->cookieFormKey->get()));
}
}
示例6: testGetLinkData
public function testGetLinkData()
{
$expectingFileData = ['file' => ['file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'], 'sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']];
$this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable'));
$this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel));
$this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0));
$this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue([$this->downloadableLinkModel]));
$this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
$this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title'));
$this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10'));
$this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6'));
$this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null));
$this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file'));
$this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
$this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
$this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
$this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif'));
$this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title'));
$this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title'));
$this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif'));
$this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true));
$this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1'));
$this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url'));
$linkData = $this->block->getLinkData();
foreach ($linkData as $link) {
$fileSave = $link->getFileSave(0);
$sampleFileSave = $link->getSampleFileSave(0);
$this->assertEquals($expectingFileData['file'], $fileSave);
$this->assertEquals($expectingFileData['sample_file'], $sampleFileSave);
}
}
示例7: getTitle
/**
* get toooltip title
*
* @param bool $escaped
* @return string
*/
public function getTitle($escaped = true)
{
if ($escaped) {
return $this->escaper->escapeHtml($this->title);
}
return $this->title;
}
示例8: generateCurrentOptions
/**
* Generate current options
*
* @return void
*/
protected function generateCurrentOptions()
{
$websiteCollection = $this->systemStore->getWebsiteCollection();
$groupCollection = $this->systemStore->getGroupCollection();
$storeCollection = $this->systemStore->getStoreCollection();
/** @var \Magento\Store\Model\Website $website */
foreach ($websiteCollection as $website) {
$groups = [];
/** @var \Magento\Store\Model\Group $group */
foreach ($groupCollection as $group) {
if ($group->getWebsiteId() == $website->getId()) {
$stores = [];
/** @var \Magento\Store\Model\Store $store */
foreach ($storeCollection as $store) {
if ($store->getGroupId() == $group->getId()) {
$name = $this->escaper->escapeHtml($store->getName());
$stores[$name]['label'] = str_repeat(' ', 8) . $name;
$stores[$name]['value'] = $store->getId();
}
}
if (!empty($stores)) {
$name = $this->escaper->escapeHtml($group->getName());
$groups[$name]['label'] = str_repeat(' ', 4) . $name;
$groups[$name]['value'] = array_values($stores);
}
}
}
if (!empty($groups)) {
$name = $this->escaper->escapeHtml($website->getName());
$this->currentOptions[$name]['label'] = $name;
$this->currentOptions[$name]['value'] = array_values($groups);
}
}
}
示例9: prepareItem
/**
* Get data
*
* @param array $item
* @return string
*/
protected function prepareItem(array $item)
{
$content = '';
$origStores = $item['store_id'];
if (empty($origStores)) {
return '';
}
if (!is_array($origStores)) {
$origStores = [$origStores];
}
if (in_array(0, $origStores) && count($origStores) == 1) {
return __('All Store Views');
}
$data = $this->systemStore->getStoresStructure(false, $origStores);
foreach ($data as $website) {
$content .= $website['label'] . "<br/>";
foreach ($website['children'] as $group) {
$content .= str_repeat(' ', 3) . $this->escaper->escapeHtml($group['label']) . "<br/>";
foreach ($group['children'] as $store) {
$content .= str_repeat(' ', 6) . $this->escaper->escapeHtml($store['label']) . "<br/>";
}
}
}
return $content;
}
示例10: getFormKey
/**
* Retrieve Session Form Key
*
* @return string A 16 bit unique key for forms
*/
public function getFormKey()
{
if (!$this->isPresent()) {
$this->set($this->mathRandom->getRandomString(16));
}
return $this->escaper->escapeHtmlAttr($this->session->getData(self::FORM_KEY));
}
示例11: execute
/**
* Register form key in session from cookie value
*
* @return void
*/
public function execute()
{
$formKeyFromCookie = $this->_formKey->get();
if ($formKeyFromCookie) {
$this->_session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->_escaper->escapeHtml($formKeyFromCookie));
}
}
示例12: execute
/**
* Forgot customer password action
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$email = (string) $this->getRequest()->getPost('email');
if ($email) {
if (!\Zend_Validate::is($email, 'EmailAddress')) {
$this->_getSession()->setForgottenEmail($email);
$this->messageManager->addError(__('Please correct the email address.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
try {
$this->customerAccountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
} catch (NoSuchEntityException $e) {
// Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
} catch (\Exception $exception) {
$this->messageManager->addException($exception, __('Unable to send password reset email.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
$email = $this->escaper->escapeHtml($email);
// @codingStandardsIgnoreStart
$this->messageManager->addSuccess(__('If there is an account associated with %1 you will receive an email with a link to reset your password.', $email));
// @codingStandardsIgnoreEnd
$resultRedirect->setPath('*/*/');
return $resultRedirect;
} else {
$this->messageManager->addError(__('Please enter your email.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
}
示例13: execute
/**
* Add shared wishlist item to shopping cart
*
* If Product has required options - redirect
* to product view page with message about needed defined required options
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
$itemId = (int) $this->getRequest()->getParam('item');
/* @var $item Item */
$item = $this->itemFactory->create()->load($itemId);
$redirectUrl = $this->_redirect->getRefererUrl();
try {
/** @var OptionCollection $options */
$options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]);
$item->setOptions($options->getOptionsByItem($itemId));
$item->addToCart($this->cart);
$this->cart->save();
if (!$this->cart->getQuote()->getHasError()) {
$message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName()));
$this->messageManager->addSuccess($message);
}
if ($this->cartHelper->getShouldRedirectToCart()) {
$redirectUrl = $this->cartHelper->getCartUrl();
}
} catch (ProductException $e) {
$this->messageManager->addError(__('This product(s) is out of stock.'));
} catch (LocalizedException $e) {
$this->messageManager->addNotice($e->getMessage());
$redirectUrl = $item->getProductUrl();
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t add the item to the cart right now.'));
}
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl($redirectUrl);
return $resultRedirect;
}
示例14: getSectionData
/**
* {@inheritdoc}
*/
public function getSectionData()
{
$customerId = $this->currentCustomer->getCustomerId();
if ($this->paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) {
return ['askToCreate' => true, 'confirmUrl' => $this->escaper->escapeUrl($this->urlBuilder->getUrl($this->startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1])), 'confirmMessage' => $this->escaper->escapeJsQuote(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'))];
}
return [];
}
示例15: emulateWelcomeBlock
/**
* Emulate 'welcome' block with persistent data
*
* @param \Magento\Framework\View\Element\AbstractBlock $block
* @return $this
*/
public function emulateWelcomeBlock($block)
{
$escapedName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())), null);
$this->_applyAccountLinksPersistentData();
$welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml();
$block->setWelcome($welcomeMessage);
return $this;
}