protected function setUp() { $this->productBuilder = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Builder', ['build'], [], '', false); $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['addData', 'getSku', 'getTypeId', 'getStoreId', '__sleep', '__wakeup', 'getAttributes', 'setAttributeSetId'])->getMock(); $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple')); $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1')); $this->product->expects($this->any())->method('getAttributes')->will($this->returnValue([])); $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product)); $this->resultPage = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage); $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock(); $resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward); $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->layout); $this->resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', ['create'], [], '', false); $this->resultRedirect = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false); $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect); $this->initializationHelper = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper', [], [], '', false); $this->productFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->productFactory->expects($this->any())->method('create')->willReturn($this->product); $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false); $this->resultJsonFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\JsonFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultJsonFactory->expects($this->any())->method('create')->willReturn($this->resultJson); $additionalParams = ['resultRedirectFactory' => $this->resultRedirectFactory]; $this->action = (new ObjectManagerHelper($this))->getObject('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Validate', ['context' => $this->initContext($additionalParams), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, 'resultForwardFactory' => $resultForwardFactory, 'initializationHelper' => $this->initializationHelper, 'resultJsonFactory' => $this->resultJsonFactory, 'productFactory' => $this->productFactory]); }
public function testExecute() { $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock(); $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product); $resultLayout = $this->getMock(\Magento\Framework\View\Result\Layout::class, [], [], '', false); $this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_LAYOUT)->willReturn($resultLayout); $this->assertInstanceOf(\Magento\Framework\View\Result\Layout::class, $this->controller->execute()); }
public function testExecute() { $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock(); $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface'); $block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock(); $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product); $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($product); $this->response->expects($this->once())->method('setBody')->willReturnSelf(); $this->view->expects($this->once())->method('getLayout')->willReturn($layout); $layout->expects($this->once())->method('createBlock')->willReturn($block); $block->expects($this->once())->method('toHtml')->willReturnSelf(); $this->controller->execute(); }
public function testExecute() { $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock(); $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface'); $block = $this->getMockBuilder('Magento\\ConfigurableProduct\\Block\\Adminhtml\\Product\\Attribute\\NewAttribute\\Product\\Created')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock(); $this->view->expects($this->once())->method('loadLayout')->with('popup')->willReturnSelf(); $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product); $this->view->expects($this->any())->method('getLayout')->willReturn($layout); $layout->expects($this->once())->method('createBlock')->willReturn($block); $layout->expects($this->once())->method('setChild')->willReturnSelf(); $this->view->expects($this->any())->method('renderLayout')->willReturnSelf(); $this->controller->execute(); }
protected function setUp() { $this->productBuilder = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Builder', ['build'], [], '', false); $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['addData', 'getTypeId', 'getStoreId', '__sleep', '__wakeup'])->getMock(); $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple')); $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1')); $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product)); $this->resultPage = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock(); $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $resultPageFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->resultPage); $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock(); $resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward); $this->action = new \Magento\Catalog\Controller\Adminhtml\Product\NewAction($this->initContext(), $this->productBuilder, $this->getMockBuilder('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\StockDataFilter')->disableOriginalConstructor()->getMock(), $resultPageFactory, $resultForwardFactory); $this->resultPage->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layout); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock(); $this->layoutMock = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->productBuilderMock = $this->getMockBuilder(Builder::class)->disableOriginalConstructor()->getMock(); $this->resultMock = $this->getMockBuilder(ResultInterface::class)->setMethods(['forward', 'setJsonData', 'getLayout'])->getMockForAbstractClass(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass(); $this->uiComponentMock = $this->getMockBuilder(UiComponent::class)->disableOriginalConstructor()->getMock(); $this->processorMock = $this->getMockBuilder(ProcessorInterface::class)->getMockForAbstractClass(); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->resultFactoryMock->expects($this->any())->method('create')->willReturn($this->resultMock); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock); $this->productBuilderMock->expects($this->any())->method('build')->willReturn($this->productMock); $this->layoutMock->expects($this->any())->method('getBlock')->willReturn($this->uiComponentMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->processorMock); $this->resultMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->model = $this->objectManager->getObject(Reload::class, ['context' => $this->contextMock, 'productBuilder' => $this->productBuilderMock, 'layout' => $this->layoutMock]); }