本文整理汇总了PHP中Magento\Framework\View\LayoutFactory::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP LayoutFactory::expects方法的具体用法?PHP LayoutFactory::expects怎么用?PHP LayoutFactory::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\LayoutFactory
的用法示例。
在下文中一共展示了LayoutFactory::expects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUpdate
public function testUpdate()
{
$statusInfo = 'some status info';
$data = ['status' => 'success', 'message' => __('Database(s) successfully updated.'), 'status_info' => $statusInfo];
$this->resultJson->expects($this->once())->method('setData')->with($data)->willReturnSelf();
$this->updaterSelected->expects($this->once())->method('update')->willReturnSelf();
$statusBlock = $this->getMockBuilder('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->disableOriginalConstructor()->getMock();
$layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface');
$this->layoutFactory->expects($this->once())->method('create')->willReturn($layout);
$layout->expects($this->once())->method('createBlock')->with('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->willReturn($statusBlock);
$statusBlock->expects($this->once())->method('getDbStatus')->willReturn($statusInfo);
$this->logger->expects($this->never())->method('critical');
$this->assertSame($this->resultJson, $this->controllerUpdate->execute());
}
示例2: testExecute
/**
* Run test execute method
*
* @param int|bool $categoryId
* @param int $storeId
* @return void
*
* @dataProvider dataProviderExecute
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecute($categoryId, $storeId)
{
$rootCategoryId = 2;
$this->requestMock->expects($this->atLeastOnce())->method('getParam')->will($this->returnValueMap([['id', false, $categoryId], ['store', null, $storeId]]));
$this->requestMock->expects($this->atLeastOnce())->method('getQuery')->with('isAjax')->will($this->returnValue(false));
$this->mockInitCategoryCall();
$this->sessionMock->expects($this->once())->method('__call')->will($this->returnValue([]));
if (!$categoryId) {
if ($storeId) {
$this->storeManagerInterfaceMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnSelf());
} else {
$this->storeManagerInterfaceMock->expects($this->once())->method('getDefaultStoreView')->will($this->returnSelf());
}
$this->storeManagerInterfaceMock->expects($this->once())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
$categoryId = $rootCategoryId;
}
$this->requestMock->expects($this->atLeastOnce())->method('setParam')->with('id', $categoryId)->will($this->returnValue(true));
$this->categoryMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($categoryId));
/**
* @var \Magento\Framework\View\Element\Template
* |\PHPUnit_Framework_MockObject_MockObject $blockMock
*/
$blockMock = $this->getMock('Magento\\Framework\\View\\Element\\Template', ['setStoreId'], [], '', false);
$blockMock->expects($this->once())->method('setStoreId')->with($storeId);
$this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnSelf());
$this->resultPageMock->expects($this->once())->method('getBlock')->willReturn($blockMock);
$this->edit->execute();
}
示例3: 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]);
}
示例4: testExecute
/**
* Run test execute method
*
* @param int|bool $categoryId
* @param int $storeId
* @param int|null $parentId
* @return void
*
* @dataProvider dataProviderExecute
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecute($categoryId, $storeId, $parentId)
{
$rootCategoryId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
$products = [['any_product']];
$postData = ['general-data', 'parent' => $parentId, 'category_products' => json_encode($products)];
if (isset($storeId)) {
$postData['store_id'] = $storeId;
}
/**
* @var \Magento\Backend\Model\View\Result\Redirect
* |\PHPUnit_Framework_MockObject_MockObject $resultRedirectMock
*/
$resultRedirectMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false);
/**
* @var \Magento\Framework\View\Element\Messages
* |\PHPUnit_Framework_MockObject_MockObject $blockMock
*/
$blockMock = $this->getMock('Magento\\Framework\\View\\Element\\Messages', ['setMessages', 'getGroupedHtml'], [], '', false);
/**
* @var \Magento\Catalog\Model\Category
* |\PHPUnit_Framework_MockObject_MockObject $categoryMock
*/
$categoryMock = $this->getMock('Magento\\Catalog\\Model\\Category', ['setStoreId', 'load', 'getPath', 'getResource', 'setPath', 'setParentId', 'setData', 'addData', 'setAttributeSetId', 'getDefaultAttributeSetId', 'getProductsReadonly', 'setPostedProducts', 'getId', 'validate', 'unsetData', 'save', 'toArray'], [], '', false);
/**
* @var \Magento\Catalog\Model\Category
* |\PHPUnit_Framework_MockObject_MockObject $parentCategoryMock
*/
$parentCategoryMock = $this->getMock('Magento\\Catalog\\Model\\Category', ['setStoreId', 'load', 'getPath', 'setPath', 'setParentId', 'setData', 'addData', 'setAttributeSetId', 'getDefaultAttributeSetId', 'getProductsReadonly', 'setPostedProducts', 'getId'], [], '', false);
/**
* @var \Magento\Backend\Model\Auth\Session
* |\PHPUnit_Framework_MockObject_MockObject $sessionMock
*/
$sessionMock = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', [], [], '', false);
/**
* @var \Magento\Framework\Registry
* |\PHPUnit_Framework_MockObject_MockObject $registryMock
*/
$registryMock = $this->getMock('Magento\\Framework\\Registry', ['register'], [], '', false);
/**
* @var \Magento\Cms\Model\Wysiwyg\Config
* |\PHPUnit_Framework_MockObject_MockObject $wysiwygConfigMock
*/
$wysiwygConfigMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Config', ['setStoreId'], [], '', false);
/**
* @var \Magento\Store\Model\StoreManagerInterface
* |\PHPUnit_Framework_MockObject_MockObject $storeManagerMock
*/
$storeManagerMock = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface', [], '', false, true, true, ['getStore', 'getRootCategoryId']);
/**
* @var \Magento\Framework\View\Layout
* |\PHPUnit_Framework_MockObject_MockObject $layoutMock
*/
$layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Layout', [], '', false, true, true, ['getMessagesBlock']);
/**
* @var \Magento\Framework\Controller\Result\Json
* |\PHPUnit_Framework_MockObject_MockObject $resultJsonMock
*/
$resultJsonMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Config', ['setData'], [], '', false);
/**
* @var \Magento\Framework\Message\Collection
* |\PHPUnit_Framework_MockObject_MockObject $messagesMock
*/
$messagesMock = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
$this->resultRedirectFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRedirectMock));
$this->requestMock->expects($this->atLeastOnce())->method('getParam')->will($this->returnValueMap([['id', false, $categoryId], ['store', null, $storeId], ['parent', null, $parentId]]));
$this->objectManagerMock->expects($this->atLeastOnce())->method('create')->will($this->returnValue($categoryMock));
$this->objectManagerMock->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap([['Magento\\Backend\\Model\\Auth\\Session', $sessionMock], ['Magento\\Framework\\Registry', $registryMock], ['Magento\\Cms\\Model\\Wysiwyg\\Config', $wysiwygConfigMock], ['Magento\\Store\\Model\\StoreManagerInterface', $storeManagerMock]]));
$categoryMock->expects($this->once())->method('setStoreId')->with($storeId);
$registryMock->expects($this->any())->method('register')->will($this->returnValueMap([['category', $categoryMock], ['current_category', $categoryMock]]));
$wysiwygConfigMock->expects($this->once())->method('setStoreId')->with($storeId);
$this->requestMock->expects($this->atLeastOnce())->method('getPost')->will($this->returnValueMap([['use_config', ['attribute']], ['use_default', ['default-attribute']], ['return_session_messages_only', true]]));
$this->requestMock->expects($this->atLeastOnce())->method('getPostValue')->willReturn($postData);
$categoryMock->expects($this->once())->method('addData')->with($postData);
$categoryMock->expects($this->at(0))->method('getId')->will($this->returnValue($categoryId));
if (!$parentId) {
if ($storeId) {
$storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnSelf());
$storeManagerMock->expects($this->once())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
$parentId = $rootCategoryId;
}
}
$categoryMock->expects($this->any())->method('load')->will($this->returnValue($parentCategoryMock));
$parentCategoryMock->expects($this->once())->method('getPath')->will($this->returnValue('parent_category_path'));
$categoryMock->expects($this->once())->method('setPath')->with('parent_category_path');
$categoryMock->expects($this->once())->method('setParentId')->with($parentId);
$categoryMock->expects($this->atLeastOnce())->method('setData')->will($this->returnValueMap([['attribute', null, true], ['default-attribute', false, true], ['use_post_data_config', ['attribute'], true]]));
$categoryMock->expects($this->once())->method('getDefaultAttributeSetId')->will($this->returnValue('default-attribute'));
$categoryMock->expects($this->once())->method('setAttributeSetId')->with('default-attribute');
$categoryMock->expects($this->once())->method('getProductsReadonly')->will($this->returnValue(false));
//.........这里部分代码省略.........