public function testExecuteObtainsProductDataFromSession() { $this->action->getRequest()->expects($this->any())->method('getParam')->willReturn(true); $this->action->getRequest()->expects($this->any())->method('getFullActionName')->willReturn('catalog_product_new'); $productData = ['name' => 'test-name', 'stock_data' => null]; $this->session->expects($this->any())->method('getProductData')->willReturn(['product' => $productData]); $this->initializationHelper->expects($this->once())->method('initializeFromData')->with($this->product, $productData)->willReturn($this->product); $this->action->execute(); }
/** * @param string $exceptionType * @return void * @dataProvider exceptionTypeDataProvider */ public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError($exceptionType) { $productData = ['product' => ['name' => 'test-name']]; $this->request->expects($this->any())->method('getPostValue')->willReturn($productData); $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($this->product); $this->product->expects($this->any())->method('getSku')->willThrowException(new $exceptionType(__('message'))); $this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/new'); $this->action->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 testInitializeFromData() { $productData = ['name' => 'test-name', 'stock_data' => ['use_config_manage_stock' => 0]]; $this->request->expects($this->any())->method('getPost')->willReturnMap([['product', [], $productData]]); $this->initializationHelper->expects($this->once())->method('initializeFromData')->with($this->product, $productData)->willReturn($this->product); $this->action->execute(); }