本文整理汇总了PHP中Magento\Framework\Escaper::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Escaper::expects方法的具体用法?PHP Escaper::expects怎么用?PHP Escaper::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Escaper
的用法示例。
在下文中一共展示了Escaper::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: 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]);
}
示例4: testGetHtml
public function testGetHtml()
{
$resultHtml = '<input type="text" name="escapedHtml" ' . 'id="escapedHtml" value="escapedHtml" ' . 'class="input-text admin__control-text no-changes" data-ui-id="filter-escapedhtml" />';
$column = $this->getMockBuilder('Magento\\Backend\\Block\\Widget\\Grid\\Column')->setMethods(['getId', 'getHtmlId'])->disableOriginalConstructor()->getMock();
$this->block->setColumn($column);
$this->escaper->expects($this->any())->method('escapeHtml')->willReturn('escapedHtml');
$column->expects($this->any())->method('getId')->willReturn('id');
$column->expects($this->once())->method('getHtmlId')->willReturn('htmlId');
$this->assertEquals($resultHtml, $this->block->getHtml());
}
示例5: 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);
}
示例6: testPrepareDataSource
/**
* @dataProvider prepareDataSourceDataProvider
*/
public function testPrepareDataSource($dataSource, $expectedResult)
{
$website = 'website';
$group = 'group';
$store = 'store';
$storeStructure = [1 => ['value' => 1, 'label' => $website, 'children' => [1 => ['value' => 1, 'label' => $group, 'children' => [1 => ['value' => 1, 'label' => $store]]]]]];
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnMap([[$group, null, $group], [$store, null, $store]]);
$this->systemStoreMock->expects($this->any())->method('getStoresStructure')->willReturn($storeStructure);
$this->assertEquals($this->model->prepareDataSource($dataSource), $expectedResult);
}
示例7: testGetHeaderText
/**
* @covers \Magento\Cms\Block\Adminhtml\Block\Edit::getHeaderText
* @param integer|null $modelBlockId
*
* @dataProvider getHeaderTextDataProvider
*/
public function testGetHeaderText($modelBlockId)
{
$title = 'some title';
$escapedTitle = 'escaped title';
$this->registryMock->expects($this->atLeastOnce())->method('registry')->with('cms_block')->willReturn($this->modelBlockMock);
$this->modelBlockMock->expects($this->atLeastOnce())->method('getId')->willReturn($modelBlockId);
$this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title);
$this->escaperMock->expects($this->any())->method('escapeHtml')->with($title)->willReturn($escapedTitle);
$this->assertInstanceOf('Magento\\Framework\\Phrase', $this->this->getHeaderText());
}
示例8: testExecute
public function testExecute()
{
//Data
$formKey = '<asdfaswqrwqe12>';
$escapedFormKey = 'asdfaswqrwqe12';
//Verification
$this->_formKey->expects($this->once())->method('get')->will($this->returnValue($formKey));
$this->_escaper->expects($this->once())->method('escapeHtml')->with($formKey)->will($this->returnValue($escapedFormKey));
$this->_session->expects($this->once())->method('setData')->with(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $escapedFormKey);
$this->_model->execute();
}
示例9: testGetEscapedQueryText
/**
* @dataProvider queryTextDataProvider
*/
public function testGetEscapedQueryText($queryText, $maxQueryLength, $expected)
{
$this->requestMock->expects($this->once())->method('getParam')->willReturn($queryText);
$this->stringMock->expects($this->any())->method('cleanString')->willReturnArgument(0);
$this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($maxQueryLength);
$this->stringMock->expects($this->any())->method('strlen')->will($this->returnCallback(function ($queryText) {
return strlen($queryText);
}));
$this->stringMock->expects($this->any())->method('substr')->with($queryText, 0, $maxQueryLength)->willReturn($expected);
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
$this->assertEquals($expected, $this->model->getEscapedQueryText());
}
示例10: setUp
protected function setUp()
{
$this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
$this->assetMergeServiceMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\MergeService')->disableOriginalConstructor()->getMock();
$this->urlBuilderMock = $this->getMockForAbstractClass('Magento\\Framework\\UrlInterface');
$this->escaperMock = $this->getMockBuilder('Magento\\Framework\\Escaper')->disableOriginalConstructor()->getMock();
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
$this->stringMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\StringUtils')->disableOriginalConstructor()->getMock();
$this->loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
$this->assetsCollection = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\GroupedCollection')->setMethods(['getGroups'])->disableOriginalConstructor()->getMock();
$this->assetInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\AssetInterface');
$this->titleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->setMethods(['set', 'get'])->disableOriginalConstructor()->getMock();
$this->objectManagerHelper = new ObjectManager($this);
$this->renderer = $this->objectManagerHelper->getObject('Magento\\Framework\\View\\Page\\Config\\Renderer', ['pageConfig' => $this->pageConfigMock, 'assetMergeService' => $this->assetMergeServiceMock, 'urlBuilder' => $this->urlBuilderMock, 'escaper' => $this->escaperMock, 'string' => $this->stringMock, 'logger' => $this->loggerMock]);
}
示例11: testGetSampleData
public function testGetSampleData()
{
$expectingFileData = array('sample_file' => array('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('getSamples')->will($this->returnValue(array($this->downloadableSampleModel)));
$this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
$this->downloadableSampleModel->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->downloadableSampleModel->expects($this->any())->method('getTitle')->will($this->returnValue('Sample Title'));
$this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')->will($this->returnValue(null));
$this->downloadableSampleModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
$this->downloadableSampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
$this->downloadableSampleModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
$this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Sample Title'));
$this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/sample.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'));
$sampleData = $this->block->getSampleData();
foreach ($sampleData as $sample) {
$fileSave = $sample->getFileSave(0);
$this->assertEquals($expectingFileData['sample_file'], $fileSave);
}
}
示例12: testGetItemDefault
public function testGetItemDefault()
{
$this->escaper->expects($this->once())->method('escapeHtml')->with('value', null);
$item = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', [], [], '', false);
$item->expects($this->exactly(2))->method('getData')->with('default')->willReturn('value');
$this->block->getItemValue($item, 'default');
}
示例13: testExecute
/**
* @param bool $noDiscount
* @param string $couponCode
* @param string $errorMessage
* @param string $actualCouponCode
* @dataProvider isApplyDiscountDataProvider
*/
public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
{
$quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCouponCode', 'isVirtual', 'getAllItems'], [], '', false);
$create = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', [], [], '', false);
$paramReturnMap = [['customer_id', null, null], ['store_id', null, null], ['currency_id', null, null]];
$this->request->expects($this->atLeastOnce())->method('getParam')->willReturnMap($paramReturnMap);
$objectManagerParamMap = [['Magento\\Sales\\Model\\AdminOrder\\Create', $create], ['Magento\\Backend\\Model\\Session\\Quote', $this->session]];
$this->objectManager->expects($this->atLeastOnce())->method('get')->willReturnMap($objectManagerParamMap);
$this->eventManager->expects($this->any())->method('dispatch');
$data = ['coupon' => ['code' => $couponCode]];
$postReturnMap = [['order', $data], ['reset_shipping', false], ['collect_shipping_rates', false], ['sidebar', false], ['add_product', false], ['', false], ['update_items', false], ['remove_item', 1], ['from', 2], ['move_item', 1], ['to', 2], ['qty', 3], ['payment', false], [null, 'request'], ['payment', false], ['giftmessage', false], ['add_products', false], ['update_items', false]];
$this->request->expects($this->atLeastOnce())->method('getPost')->willReturnMap($postReturnMap);
$create->expects($this->once())->method('importPostData')->willReturnSelf();
$create->expects($this->once())->method('initRuleData')->willReturnSelf();
$create->expects($this->any())->method('getQuote')->willReturn($quote);
$address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$create->expects($this->once())->method('getBillingAddress')->willReturn($address);
$quote->expects($this->any())->method('isVirtual')->willReturn(true);
$this->request->expects($this->once())->method('has')->with('item')->willReturn(false);
$create->expects($this->once())->method('saveQuote')->willReturnSelf();
$this->session->expects($this->any())->method('getQuote')->willReturn($quote);
$item = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['getNoDiscount']);
$quote->expects($this->any())->method('getAllItems')->willReturn([$item]);
$item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount);
if (!$noDiscount) {
$quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode);
}
$errorMessageManager = __($errorMessage, $couponCode);
$this->escaper->expects($this->once())->method('escapeHtml')->with($couponCode)->willReturn($couponCode);
$this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf();
$this->resultForward->expects($this->once())->method('forward')->with('index')->willReturnSelf();
$this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->processData->execute());
}
示例14: testPrepareElementHtml
/**
* @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
* @param string $elementValue
* @param integer|null $modelBlockId
*
* @dataProvider prepareElementHtmlDataProvider
*/
public function testPrepareElementHtml($elementValue, $modelBlockId)
{
$elementId = 1;
$uniqId = '126hj4h3j73hk7b347jhkl37gb34';
$sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
$config = ['key1' => 'value1'];
$fieldsetId = 2;
$html = 'some html';
$title = 'some "><img src=y onerror=prompt(document.domain)>; title';
$titleEscaped = 'some "><img src=y onerror=prompt(document.domain)>; title';
$this->this->setConfig($config);
$this->this->setFieldsetId($fieldsetId);
$this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
$this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
$this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
$this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
$this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
$this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
$this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock);
$this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf();
$this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId);
$this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title);
$this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
if (!empty($elementValue) && !empty($modelBlockId)) {
$this->escaper->expects($this->atLeastOnce())->method('escapeHtml')->willReturn($titleEscaped);
$this->chooserMock->expects($this->atLeastOnce())->method('setLabel')->with($titleEscaped)->willReturnSelf();
}
$this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
$this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
}
示例15: testEscapeHtmlWithLinks
/**
* @param string $data
* @param string $expected
* @param null|array $allowedTags
* @dataProvider escapeHtmlWithLinksDataProvider
*/
public function testEscapeHtmlWithLinks($data, $expected, $allowedTags = null)
{
$this->escaperMock
->expects($this->any())
->method('escapeHtml')
->will($this->returnValue($expected));
$actual = $this->adminHelper->escapeHtmlWithLinks($data, $allowedTags);
$this->assertEquals($expected, $actual);
}