本文整理汇总了PHP中Magento\Framework\View\LayoutInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP LayoutInterface::expects方法的具体用法?PHP LayoutInterface::expects怎么用?PHP LayoutInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\LayoutInterface
的用法示例。
在下文中一共展示了LayoutInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetBlock
public function testGetBlock()
{
$blockName = 'block.name';
$block = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface');
$this->layout->expects($this->once())->method('getBlock')->with($blockName)->will($this->returnValue($block));
$this->assertEquals($block, $this->model->getBlock($blockName));
}
示例2: 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));
}
示例3: testGetGridHtml
public function testGetGridHtml()
{
$html = '<body></body>';
$this->layoutMock->expects($this->any())->method('getChildName')->willReturn('userGrid');
$this->layoutMock->expects($this->any())->method('renderElement')->willReturn($html);
$this->model->setLayout($this->layoutMock);
$this->assertEquals($html, $this->model->getGridHtml());
}
示例4: testAddBreadcrumbNoBlock
public function testAddBreadcrumbNoBlock()
{
$label = 'label';
$title = 'title';
$this->layoutMock->expects($this->once())->method('getBlock')->with('breadcrumbs')->willReturn(false);
$this->breadcrumbsBlockMock->expects($this->never())->method('addLink');
$this->assertSame($this->resultPage, $this->resultPage->addBreadcrumb($label, $title));
}
示例5: testPrepareLayoutSuccessOnFalseGetId
public function testPrepareLayoutSuccessOnFalseGetId()
{
$tab = 'tab';
$this->registryMock->expects($this->once())->method('registry')->willReturn($this->layoutInterfaceMock);
$this->layoutInterfaceMock->expects($this->any())->method('createBlock')->willReturnSelf();
$this->layoutInterfaceMock->expects($this->once())->method('setRole')->willReturnSelf();
$this->layoutInterfaceMock->expects($this->once())->method('setActive')->willReturn($tab);
$this->layoutInterfaceMock->expects($this->once())->method('getId')->willReturn(false);
$this->assertInstanceOf('Magento\\Backend\\Block\\Widget\\Tabs', $this->invokeMethod($this->model, '_prepareLayout'));
}
示例6: testGetCustomerDepersonalizeCustomerData
/**
* test getCustomer method, method returns depersonalized customer Data
*/
public function testGetCustomerDepersonalizeCustomerData()
{
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false));
$this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
$this->viewMock->expects($this->once())->method('isLayoutLoaded')->will($this->returnValue(true));
$this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true));
$this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroupId));
$this->customerInterfaceFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->customerDataMock));
$this->customerDataMock->expects($this->once())->method('setGroupId')->with($this->equalTo($this->customerGroupId))->will($this->returnSelf());
$this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer());
}
示例7: testGetRenderer
public function testGetRenderer()
{
$this->blockMock->expects($this->any())->method('setRenderedBlock')->will($this->returnValue($this->blockMock));
$this->blockMock->expects($this->any())->method('getTemplate')->will($this->returnValue('template'));
$this->blockMock->expects($this->any())->method('setTemplate')->will($this->returnValue($this->blockMock));
$this->layoutMock->expects($this->any())->method('getChildName')->will($this->returnValue(true));
/** During the first call cache will be generated */
$this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, null));
/** Cached value should be returned during second call */
$this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, 'renderer_template'));
}
示例8: testGetProductPriceHtmlCreateBlock
public function testGetProductPriceHtmlCreateBlock()
{
$priceType = 'wishlist_configured_price';
$expected = 'block content';
$productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
$renderMock = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\Render')->disableOriginalConstructor()->getMock();
$renderMock->expects($this->once())->method('render')->with($priceType, $productMock, ['zone' => Render::ZONE_ITEM_LIST])->willReturn($expected);
$this->layout->expects($this->once())->method('getBlock')->with('product.price.render.default')->willReturn(false);
$this->layout->expects($this->once())->method('createBlock')->with('Magento\\Framework\\Pricing\\Render', 'product.price.render.default', ['data' => ['price_render_handle' => 'catalog_product_prices']])->willReturn($renderMock);
$result = $this->block->getProductPriceHtml($productMock, $priceType, Render::ZONE_ITEM_LIST);
$this->assertEquals($expected, $result);
}
示例9: testExecute
/**
* @param mixed $result
* @param string[] $responseArray
* @dataProvider executeDataProvider
*/
public function testExecute($result, $responseArray)
{
$getParamMap = [['variable_id', null, null], ['store', 0, 0]];
$this->requestMock->expects($this->any())->method('getParam')->willReturnMap($getParamMap);
$this->requestMock->expects($this->any())->method('getPost')->with('variable')->will($this->returnValue([]));
$this->variableMock->expects($this->any())->method('validate')->willReturn($result);
if ($result instanceof \Magento\Framework\Phrase) {
$this->messageManagerMock->expects($this->once())->method('addError')->with($result->getText());
$this->layoutMock->expects($this->once())->method('initMessages');
}
$this->resultJsonMock->expects($this->once())->method('setData')->with($responseArray);
$this->validateMock->execute();
}
示例10: setUp
protected function setUp()
{
$this->_layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
$this->_columnSetMock = $this->_getColumnSetMock();
$returnValueMap = [['grid', 'grid.columnSet', 'grid.columnSet'], ['grid', 'reset_filter_button', 'reset_filter_button'], ['grid', 'search_button', 'search_button']];
$this->_layoutMock->expects($this->any())->method('getChildName')->will($this->returnValueMap($returnValueMap));
$this->_layoutMock->expects($this->any())->method('getBlock')->with('grid.columnSet')->will($this->returnValue($this->_columnSetMock));
$this->_layoutMock->expects($this->any())->method('createBlock')->with('Magento\\Backend\\Block\\Widget\\Button')->will($this->returnValue(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Backend\\Block\\Widget\\Button')));
$this->_layoutMock->expects($this->any())->method('helper')->with('Magento\\Framework\\Json\\Helper\\Data')->will($this->returnValue(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Json\\Helper\\Data')));
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Backend\\Block\\Widget\\Grid');
$this->_block->setLayout($this->_layoutMock);
$this->_block->setNameInLayout('grid');
}
示例11: initLayoutMock
private function initLayoutMock()
{
$this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
$this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
$this->viewMock->expects($this->once())->method('renderLayout')->willReturnSelf();
$this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock));
}
示例12: testGetProductPriceHtml
public function testGetProductPriceHtml()
{
$id = 6;
$expectedHtml = '
<div class="price-box price-final_price">
<span class="regular-price" id="product-price-' . $id . '">
<span class="price">$0.00</span>
</span>
</div>';
$type = 'widget-new-list';
$productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId'], [], '', false, false);
$productMock->expects($this->once())->method('getId')->willReturn($id);
$arguments = ['price_id' => 'old-price-' . $id . '-' . $type, 'display_minimal_price' => true, 'include_container' => true, 'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST];
$priceBoxMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false, false);
$this->layout->expects($this->once())->method('getBlock')->with($this->equalTo('product.price.render.default'))->willReturn($priceBoxMock);
$priceBoxMock->expects($this->once())->method('render')->with($this->equalTo('final_price'), $this->equalTo($productMock), $this->equalTo($arguments))->willReturn($expectedHtml);
$result = $this->block->getProductPriceHtml($productMock, $type);
$this->assertEquals($expectedHtml, $result);
}
示例13: setUp
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->requestMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\RequestInterface', ['isDispatched', 'initForward', 'setDispatched', 'isForwarded']);
$this->breadcrumbsBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['addLink']);
$this->menuBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['setActive', 'getMenuModel']);
$this->viewMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\ViewInterface');
$this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock();
$this->switcherBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\BlockInterface')->disableOriginalConstructor()->getMock();
$this->contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->getMock();
$this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http\\FileFactory')->disableOriginalConstructor()->getMock();
$this->menuModelMock = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock();
$this->abstractBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->setMethods(['getCsvFile', 'getExcelFile', 'setSaveParametersInSession', 'getCsv', 'getExcel'])->disableOriginalConstructor()->getMock();
$this->menuModelMock->expects($this->any())->method('getParentItems')->willReturn([]);
$this->menuBlockMock->expects($this->any())->method('getMenuModel')->willReturn($this->menuModelMock);
$this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
$this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
$this->layoutMock->expects($this->any())->method('getBlock')->will($this->returnValueMap([['breadcrumbs', $this->breadcrumbsBlockMock], ['menu', $this->menuBlockMock], ['store_switcher', $this->switcherBlockMock]]));
$this->layoutMock->expects($this->any())->method('getChildBlock')->willReturn($this->abstractBlockMock);
}
示例14: testToHtml
public function testToHtml()
{
$childNameOne = 'child.1';
$childNameTextOne = 'child.1 text';
$childNameTwo = 'child.2';
$childNames = [$childNameOne, $childNameTwo];
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false);
/**
* @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock
*/
$itemMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->getMock();
$this->model->setItem($itemMock);
$this->layoutMock->expects($this->once())->method('getChildNames')->with($this->model->getNameInLayout())->willReturn($childNames);
/** @var Generic|\PHPUnit_Framework_MockObject_MockObject $childMockOne */
$childMockOne = $this->getMockBuilder('Magento\\Checkout\\Block\\Cart\\Item\\Renderer\\Actions\\Generic')->disableOriginalConstructor()->getMock();
$childMockOne->expects($this->once())->method('setItem')->with($itemMock);
$childMockTwo = false;
$this->layoutMock->expects($this->once())->method('renderElement')->with($childNameOne, false)->willReturn($childNameTextOne);
$this->layoutMock->expects($this->exactly(2))->method('getBlock')->willReturnMap([[$childNameOne, $childMockOne], [$childNameTwo, $childMockTwo]]);
$this->assertEquals($childNameTextOne, $this->model->toHtml());
}
示例15: testCountrySelect
public function testCountrySelect()
{
$html = "<select>";
$default = 'default';
$name = 'US';
$id = '3';
$title = "United States";
$directoryDataMock = $this->getMockBuilder('\\Magento\\Braintree\\Block\\Directory\\Data')->disableOriginalConstructor()->getMock();
$this->layoutMock->expects($this->any())->method('getChildName')->willReturn(true);
$this->layoutMock->expects($this->any())->method('getBlock')->willReturn($directoryDataMock);
$directoryDataMock->expects($this->once())->method('getCountryHtmlSelect')->with($default, $name, $id, $title)->willReturn($html);
$this->assertEquals($html, $this->block->countrySelect($name, $id, $default, $title));
}