本文整理汇总了PHP中Magento\Framework\View\Layout::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Layout::expects方法的具体用法?PHP Layout::expects怎么用?PHP Layout::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\Layout
的用法示例。
在下文中一共展示了Layout::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initContext
/**
* Init context object
*
* @param array $additionalParams
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function initContext(array $additionalParams = [])
{
$productActionMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Action', [], [], '', false);
$objectManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface');
$objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($productActionMock));
$block = $this->getMockBuilder('\\Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass();
$this->layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['getBlock'])->disableOriginalConstructor()->getMock();
$this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($block));
$eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->setMethods(['dispatch'])->disableOriginalConstructor()->getMock();
$eventManager->expects($this->any())->method('dispatch')->will($this->returnSelf());
$title = $this->getMockBuilder('\\Magento\\Framework\\App\\Action\\Title')->setMethods(['add'])->disableOriginalConstructor()->getMock();
$title->expects($this->any())->method('prepend')->withAnyParameters()->will($this->returnSelf());
$requestInterfaceMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->setMethods(['getParam', 'getPost', 'getFullActionName', 'getPostValue'])->disableOriginalConstructor()->getMock();
$responseInterfaceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->setMethods(['setRedirect', 'sendResponse'])->getMock();
$managerInterfaceMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface');
$sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['getProductData', 'setProductData'], [], '', false);
$actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
$helperDataMock = $this->getMock('Magento\\Backend\\Helper\\Data', [], [], '', false);
$this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getResponse', 'getObjectManager', 'getEventManager', 'getMessageManager', 'getSession', 'getActionFlag', 'getHelper', 'getTitle', 'getView', 'getResultRedirectFactory', 'getResultFactory'], [], '', false);
$this->context->expects($this->any())->method('getTitle')->will($this->returnValue($title));
$this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
$this->context->expects($this->any())->method('getRequest')->will($this->returnValue($requestInterfaceMock));
$this->context->expects($this->any())->method('getResponse')->will($this->returnValue($responseInterfaceMock));
$this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($objectManagerMock));
$this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($managerInterfaceMock));
$this->context->expects($this->any())->method('getSession')->will($this->returnValue($sessionMock));
$this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock));
$this->context->expects($this->any())->method('getHelper')->will($this->returnValue($helperDataMock));
foreach ($additionalParams as $property => $object) {
$this->context->expects($this->any())->method('get' . ucfirst($property))->willReturn($object);
}
$this->session = $sessionMock;
$this->request = $requestInterfaceMock;
return $this->context;
}
示例2: setUp
/**
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
{
$this->registryMock = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry', 'register'])->getMock();
$this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
$this->viewMock = $this->getMockBuilder('Magento\\Framework\\App\\View')->disableOriginalConstructor()->setMethods(['loadLayout', 'getLayout', 'getPage', 'renderLayout'])->getMock();
$this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(['getBlock', 'createBlock', 'setChild'])->getMock();
$this->menuBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->setMethods(['setActive', 'getMenuModel', 'getParentItems'])->getMock();
$this->breadcrumbsBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Widget\\Breadcrumbs')->disableOriginalConstructor()->setMethods(['addLink'])->getMock();
$this->editBlockMock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Widget\\Breadcrumbs')->disableOriginalConstructor()->setMethods(['setEditMode'])->getMock();
$this->resultPageMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->setMethods(['setActiveMenu', 'getConfig', 'addBreadcrumb'])->getMock();
$this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
$this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
$this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
$this->layoutMock->expects($this->any())->method('getBlock')->willReturnMap([['menu', $this->menuBlockMock], ['breadcrumbs', $this->breadcrumbsBlockMock], ['edit', $this->editBlockMock]]);
$this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf());
$this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([]));
$this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock);
$this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock);
$this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock);
$this->layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Email\\Block\\Adminhtml\\Template\\Edit', 'template_edit', [])->willReturn($this->editBlockMock);
$this->editBlockMock->expects($this->once())->method('setEditMode')->willReturnSelf();
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$templateMock = $this->getMockBuilder('Magento\\Email\\Model\\Template')->disableOriginalConstructor()->getMock();
$templateMock->expects($this->once())->method('getId')->willReturn(1);
$templateMock->expects($this->any())->method('getTemplateCode')->willReturn('My Template');
$objectManagerMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock();
$objectManagerMock->expects($this->once())->method('create')->with('Magento\\Email\\Model\\BackendTemplate')->willReturn($templateMock);
$this->context = $objectManager->getObject('Magento\\Backend\\App\\Action\\Context', ['request' => $this->requestMock, 'objectManager' => $objectManagerMock, 'view' => $this->viewMock]);
$this->editController = $objectManager->getObject('Magento\\Email\\Controller\\Adminhtml\\Email\\Template\\Edit', ['context' => $this->context, 'coreRegistry' => $this->registryMock]);
}
示例3: testExecute
/**
* @param bool $cacheState
* @param bool $varnishIsEnabled
* @param bool $scopeIsPrivate
* @param int|null $blockTtl
* @param string $expectedOutput
* @dataProvider processLayoutRenderDataProvider
*/
public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput)
{
$eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false);
$this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
$eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock));
$this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
if ($cacheState) {
$eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName'));
$eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport));
$this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
$this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf());
$this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([]));
$this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock));
if ($varnishIsEnabled) {
$this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl));
$this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
}
if ($scopeIsPrivate) {
$this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName'));
$this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate));
}
$this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled));
}
$this->_model->execute($this->_observerMock);
$this->assertEquals($expectedOutput, $this->_transport['output']);
}
示例4: testGetItemPrice
public function testGetItemPrice()
{
$html = '$34.28';
$this->layoutMock->expects($this->once())->method('getBlock')->with('item_price')->will($this->returnValue($this->priceRenderBlock));
$this->priceRenderBlock->expects($this->once())->method('setItem')->with($this->itemMock);
$this->priceRenderBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html));
$this->assertEquals($html, $this->block->getItemPrice($this->itemMock));
}
示例5: testAroundRenderTrue
public function testAroundRenderTrue()
{
$attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
$this->filterMock->expects($this->atLeastOnce())->method('getAttributeModel')->willReturn($attributeMock);
$this->filterMock->expects($this->once())->method('hasAttributeModel')->willReturn(true);
$this->swatchHelperMock->expects($this->once())->method('isSwatchAttribute')->with($attributeMock)->willReturn(true);
$this->layoutMock->expects($this->once())->method('createBlock')->willReturn($this->blockMock);
$this->blockMock->expects($this->once())->method('setSwatchFilter')->will($this->returnSelf());
$this->plugin->aroundRender($this->filterRendererMock, $this->closureMock, $this->filterMock);
}
示例6: setUp
/**
* test setup
*/
public function setUp()
{
$this->pageConfig = $this->getMockBuilder('\\Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->setMethods(['set', 'getTitle'])->getMock();
$this->resultPageFactory = $this->getMockBuilder('\\Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->resultPage = $this->getMockBuilder('\\Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
$this->block = $this->getMockBuilder('\\Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMock();
$this->pageLayout = $this->getMockBuilder('\\Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->getMock();
$this->resultPageFactory->expects($this->once())->method('create')->willReturn($this->resultPage);
$this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->pageLayout);
$this->pageLayout->expects($this->any())->method('getBlock')->willReturn($this->block);
$this->pageConfig->expects($this->once())->method('getTitle')->willReturnSelf();
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig);
}
示例7: testExecute
/**
* Executes the controller action and asserts non exception logic
*/
public function testExecute()
{
$objectManager = new ObjectManagerHelper($this);
$this->vault->expects($this->once())->method('storedCard')->willReturn(true);
$this->request->expects($this->any())->method('getParam')->willReturn('token');
$this->resultRedirectFactory->expects($this->never())->method('create')->willReturn($this->resultRedirect);
$this->resultPageFactory->expects($this->once())->method('create')->willReturn($this->resultPage);
$this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->pageLayout);
$this->pageLayout->expects($this->any())->method('getBlock')->willReturn($this->block);
$this->pageConfig->expects($this->once())->method('getTitle')->willReturnSelf();
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($this->pageConfig);
$notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Delete', ['request' => $this->request, 'resultPageFactory' => $this->resultPageFactory, 'vault' => $this->vault]);
$this->assertSame($this->resultPage, $notification->execute());
}
示例8: testExecute
/**
* @covers \Magento\Email\Controller\Adminhtml\Email\Template\Index::execute
*/
public function testExecute()
{
$this->prepareExecute();
$this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
$this->layoutMock->expects($this->at(0))->method('getBlock')->with('menu')->will($this->returnValue($this->menuBlockMock));
$this->menuBlockMock->expects($this->any())->method('getMenuModel')->will($this->returnSelf());
$this->menuBlockMock->expects($this->any())->method('getParentItems')->will($this->returnValue([]));
$this->viewMock->expects($this->once())->method('getPage')->willReturn($this->resultPageMock);
$this->resultPageMock->expects($this->once())->method('getConfig')->willReturn($this->pageConfigMock);
$this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock);
$this->pageTitleMock->expects($this->once())->method('prepend')->with('Email Templates');
$this->layoutMock->expects($this->at(1))->method('getBlock')->with('breadcrumbs')->will($this->returnValue($this->breadcrumbsBlockMock));
$this->breadcrumbsBlockMock->expects($this->any())->method('addLink')->willReturnSelf();
$this->assertNull($this->indexController->execute());
}
示例9: testExecute
public function testExecute()
{
$this->menuMock->expects($this->once())->method('getParentItems')->willReturn([$this->menuItemMock]);
$this->titleMock->expects($this->atLeastOnce())->method('prepend');
$this->pageConfigMock->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->titleMock);
$this->pageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
$this->blockMock->expects($this->atLeastOnce())->method('addLink');
$this->blockMock->expects($this->once())->method('setActive');
$this->blockMock->expects($this->once())->method('getMenuModel')->willReturn($this->menuMock);
$this->layoutMock->expects($this->atLeastOnce())->method('getBlock')->willReturn($this->blockMock);
$this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
$this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
$this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($this->pageMock);
$this->action->executeInternal();
}
示例10: setUp
public function setUp()
{
$this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface');
$this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface');
$this->categoryHelper = $this->getMock('Magento\\Catalog\\Helper\\Category', [], [], '', false);
$this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false);
$this->eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
$this->update = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface');
$this->layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
$this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->update));
$this->view = $this->getMock('Magento\\Framework\\App\\ViewInterface');
$this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
$this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false);
$this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
$this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response));
$this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManager));
$this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager));
$this->context->expects($this->any())->method('getView')->will($this->returnValue($this->view));
$this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false);
$this->categoryFactory = $this->getMock('Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false);
$this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
$this->catalogDesign = $this->getMock('Magento\\Catalog\\Model\\Design', [], [], '', false);
$this->layoutHelper = $this->getMock('Magento\\Theme\\Helper\\Layout', [], [], '', false);
$this->action = (new ObjectManager($this))->getObject('Magento\\Catalog\\Controller\\Category\\View', ['context' => $this->context, 'catalogDesign' => $this->catalogDesign, 'categoryFactory' => $this->categoryFactory, 'storeManager' => $this->storeManager]);
}
示例11: testExecute
public function testExecute()
{
$blocks = ['block1', 'block2'];
$handles = ['handle1', 'handle2'];
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];
$blockInstance1 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
$blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1']));
$blockInstance2 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
$blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2']));
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
$this->requestMock->expects($this->at(1))->method('getRouteName')->will($this->returnValue('magento_pagecache'));
$this->requestMock->expects($this->at(2))->method('getControllerName')->will($this->returnValue('block'));
$this->requestMock->expects($this->at(3))->method('getActionName')->will($this->returnValue('render'));
$this->requestMock->expects($this->at(4))->method('getRequestUri')->will($this->returnValue('uri'));
$this->requestMock->expects($this->at(5))->method('getParam')->with($this->equalTo('originalRequest'))->will($this->returnValue($originalRequest));
$this->requestMock->expects($this->at(10))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks)));
$this->requestMock->expects($this->at(11))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles)));
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
$this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1));
$this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2));
$this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf();
$this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData)));
$this->action->execute();
}
示例12: testAfterGetOutput
/**
* @param $cacheState
* @param $layoutIsCacheable
* @param $expectedTags
* @param $configCacheType
* @param $ttl
* @dataProvider afterGetOutputDataProvider
*/
public function testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl)
{
$html = 'html';
$this->configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
$blockStub = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', null, [], '', false);
$blockStub->setTtl($ttl);
$this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue($layoutIsCacheable));
$this->layoutMock->expects($this->any())->method('getAllBlocks')->will($this->returnValue([$blockStub]));
$this->configMock->expects($this->any())->method('getType')->will($this->returnValue($configCacheType));
if ($layoutIsCacheable && $cacheState) {
$this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', $expectedTags);
} else {
$this->responseMock->expects($this->never())->method('setHeader');
}
$output = $this->model->afterGetOutput($this->layoutMock, $html);
$this->assertSame($output, $html);
}
示例13: testAddDefaultHandle
public function testAddDefaultHandle()
{
$processor = $this->getMock('Magento\\Framework\\View\\Layout\\ProcessorInterface', [], [], '', false);
$processor->expects($this->once())->method('addHandle')->with('module_controller_action');
$this->layout->expects($this->once())->method('getUpdate')->will($this->returnValue($processor));
$this->request->expects($this->once())->method('getFullActionName')->will($this->returnValue('Module_Controller_Action'));
$this->assertSame($this->resultLayout, $this->resultLayout->addDefaultHandle());
}
示例14: setUp
protected function setUp()
{
$this->layout = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['addHandle', 'getUpdate', 'isLayoutDefined'])->disableOriginalConstructor()->getMock();
$this->layoutFactory = $this->getMockBuilder('Magento\\Framework\\View\\LayoutFactory')->disableOriginalConstructor()->getMock();
$this->layoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->layout));
$this->layoutMerge = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->disableOriginalConstructor()->getMock();
$this->layout->expects($this->any())->method('getUpdate')->will($this->returnValue($this->layoutMerge));
$this->request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
$this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
$this->viewFileSystem = $this->getMockBuilder('Magento\\Framework\\View\\FileSystem')->disableOriginalConstructor()->getMock();
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->context = $objectManagerHelper->getObject('Magento\\Framework\\View\\Element\\Template\\Context', ['layout' => $this->layout, 'request' => $this->request, 'viewFileSystem' => $this->viewFileSystem, 'pageConfig' => $this->pageConfig]);
$this->translateInline = $this->getMock('Magento\\Framework\\Translate\\InlineInterface');
$this->pageConfigRenderer = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\Renderer')->disableOriginalConstructor()->getMock();
$pageConfigRendererFactory = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config\\RendererFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$pageConfigRendererFactory->expects($this->once())->method('create')->with(['pageConfig' => $this->pageConfig])->willReturn($this->pageConfigRenderer);
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->page = $objectManagerHelper->getObject('Magento\\Framework\\View\\Result\\Page', ['isIsolated' => true, 'layoutFactory' => $this->layoutFactory, 'context' => $this->context, 'translateInline' => $this->translateInline, 'pageConfigRendererFactory' => $pageConfigRendererFactory]);
}
示例15: testExecute
public function testExecute()
{
$selectedCategories = '1';
$isAnchorOnly = true;
$hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb';
$content = 'block_content';
$this->request->expects($this->any())->method('getParam')->willReturnMap(
[
['selected', '', $selectedCategories],
['is_anchor_only', 0, $isAnchorOnly]
]
);
$this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash);
$this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf();
$this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf();
$this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf();
$this->chooser->expects($this->once())
->method('setSelectedCategories')
->with(explode(',', $selectedCategories))
->willReturnSelf();
$this->chooser->expects($this->once())->method('toHtml')->willReturn($content);
$this->layout->expects($this->once())
->method('createBlock')
->with($this->blockClass)
->willReturn($this->chooser);
$this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf();
$this->resultFactory->expects($this->once())
->method('create')
->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW)
->willReturn($this->resultRaw);
$this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
$this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory);
/** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */
$this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
->getObject(
'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories',
[
'context' => $this->context,
'mathRandom' => $this->mathRandom,
'layout' => $this->layout
]
);
$this->assertSame($this->resultRaw, $this->controller->executeInternal());
}