本文整理汇总了PHP中Magento\Framework\Data\Form\Element\AbstractElement::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractElement::expects方法的具体用法?PHP AbstractElement::expects怎么用?PHP AbstractElement::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Data\Form\Element\AbstractElement
的用法示例。
在下文中一共展示了AbstractElement::expects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 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->any())->method('setLabel')->with($title)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
$this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
$this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
}
示例2: testRender
/**
* Run test for render method
*
* @return void
*/
public function testRender()
{
$formMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['getFieldNameSuffix'])->disableOriginalConstructor()->getMock();
$this->elementMock->expects($this->any())->method('getHtmlId')->willReturn('test-html-id');
$this->elementMock->expects($this->once())->method('getTooltip')->willReturn('');
$this->elementMock->expects($this->any())->method('getForm')->willReturn($formMock);
$formMock->expects($this->any())->method('getFieldNameSuffix')->willReturn('');
$this->assertContains(self::EXPECTED_ATTRIBUTE, $this->abstractEnable->render($this->elementMock));
}
示例3: testRender
public function testRender()
{
$rule = $this->getMockBuilder('Magento\\Rule\\Model\\AbstractModel')->setMethods(['getConditions', '__sleep', '__wakeup'])->disableOriginalConstructor()->getMockForAbstractClass();
$conditions = $this->getMock('\\Magento\\Rule\\Model\\Condition\\Combine', ['asHtmlRecursive'], [], '', false);
$this->_element->expects($this->any())->method('getRule')->will($this->returnValue($rule));
$rule->expects($this->any())->method('getConditions')->will($this->returnValue($conditions));
$conditions->expects($this->once())->method('asHtmlRecursive')->will($this->returnValue('conditions html'));
$this->assertEquals('conditions html', $this->conditions->render($this->_element));
}
示例4: testRender
public function testRender()
{
$rule = $this->getMock('\\Magento\\Rule\\Model\\Rule', ['getActions', '__sleep', '__wakeup'], [], '', false);
$actions = $this->getMock('\\Magento\\Rule\\Model\\Action\\Collection', ['asHtmlRecursive'], [], '', false);
$this->_element->expects($this->any())->method('getRule')->will($this->returnValue($rule));
$rule->expects($this->any())->method('getActions')->will($this->returnValue($actions));
$actions->expects($this->once())->method('asHtmlRecursive')->will($this->returnValue('action html'));
$this->assertEquals('action html', $this->actions->render($this->_element));
}
示例5: setUp
protected function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_element = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false, true, true, ['getHtmlId', 'getElementHtml', 'getName']);
$this->_element->expects($this->any())->method('getHtmlId')->will($this->returnValue('html id'));
$this->_element->expects($this->any())->method('getElementHtml')->will($this->returnValue('element html'));
$this->_element->expects($this->any())->method('getName')->will($this->returnValue('name'));
$this->_request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface');
$this->_jsHelper = $this->getMock('Magento\\Framework\\View\\Helper\\Js', [], [], '', false);
$this->_url = $this->getMock('Magento\\Backend\\Model\\Url', [], [], '', false);
$this->_model = $helper->getObject('Magento\\Paypal\\Block\\Adminhtml\\System\\Config\\Field\\Country', ['request' => $this->_request, 'jsHelper' => $this->_jsHelper, 'url' => $this->_url]);
}
示例6: setUp
protected function setUp()
{
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
$this->_group = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Group', [], [], '', false);
$this->_element = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false, true, true, ['getHtmlId', 'getElementHtml', 'getName', 'getElements', 'getId']);
$this->_element->expects($this->any())->method('getHtmlId')->will($this->returnValue('html id'));
$this->_element->expects($this->any())->method('getElementHtml')->will($this->returnValue('element html'));
$this->_element->expects($this->any())->method('getName')->will($this->returnValue('name'));
$this->_element->expects($this->any())->method('getElements')->will($this->returnValue([]));
$this->_element->expects($this->any())->method('getId')->will($this->returnValue('id'));
$this->_backendConfig = $this->getMock('Magento\\Backend\\Model\\Config', [], [], '', false);
$this->_model = $helper->getObject('Magento\\Paypal\\Block\\Adminhtml\\System\\Config\\Fieldset\\Payment', ['backendConfig' => $this->_backendConfig]);
$this->_model->setGroup($this->_group);
}
示例7: testPrepareElementHtml
/**
* @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
*
* @param string $elementValue
* @param integer|null $cmsPageId
*
* @dataProvider prepareElementHtmlDataProvider
*/
public function testPrepareElementHtml($elementValue, $cmsPageId)
{
//$elementValue = 12345;
//$cmsPageId = 1;
$elementId = 1;
$uniqId = '126hj4h3j73hk7b347jhkl37gb34';
$sourceUrl = 'cms/page_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/page_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->pageFactoryMock->expects($this->any())->method('create')->willReturn($this->cmsPageMock);
$this->cmsPageMock->expects($this->any())->method('load')->with((int) $elementValue)->willReturnSelf();
$this->cmsPageMock->expects($this->any())->method('getId')->willReturn($cmsPageId);
$this->cmsPageMock->expects($this->any())->method('getTitle')->willReturn($title);
$this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
if (!empty($elementValue) && !empty($cmsPageId)) {
$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));
}