/**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithoutQuantityArrayAndConfigurable()
 {
     $itemId = 2;
     $wishlistId = 1;
     $qty = [];
     $productId = 4;
     $indexUrl = 'index_url';
     $configureUrl = 'configure_url';
     $options = [5 => 'option'];
     $params = ['item' => $itemId, 'qty' => $qty];
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock();
     $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId);
     $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf();
     $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId);
     $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0);
     $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf();
     $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl);
     $itemMock->expects($this->once())->method('getProductId')->willReturn($productId);
     $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl);
     $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock);
     $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ResourceModel\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock);
     $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf();
     $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options);
     $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock);
     $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock);
     $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf();
     $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf();
     $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($configureUrl)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }
示例#2
0
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject|DefaultType $group
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option $option
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Object $buyRequest
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product
  */
 protected function parentClass($group, $option, $buyRequest, $product)
 {
     $group->expects($this->once())->method('setOption')->willReturnSelf();
     $group->expects($this->once())->method('setProduct')->willReturnSelf();
     $group->expects($this->once())->method('setRequest')->willReturnSelf();
     $group->expects($this->once())->method('setProcessMode')->willReturnSelf();
     $group->expects($this->once())->method('validateUserValue')->willReturnSelf();
     $group->expects($this->once())->method('prepareForCart')->willReturn('someString');
     $option->expects($this->once())->method('getType');
     $option->expects($this->once())->method('groupFactory')->willReturn($group);
     $option->expects($this->at(0))->method('getId')->willReturn(333);
     $buyRequest->expects($this->once())->method('getData');
     $buyRequest->expects($this->once())->method('getOptions');
     $buyRequest->expects($this->once())->method('getSuperProductConfig')->willReturn([]);
     $buyRequest->expects($this->any())->method('unsetData')->willReturnSelf();
     $buyRequest->expects($this->any())->method('getQty');
     $product->expects($this->once())->method('getOptions')->willReturn([$option]);
     $product->expects($this->once())->method('prepareCustomOptions');
     $product->expects($this->any())->method('addCustomOption')->willReturnSelf();
     $product->expects($this->any())->method('setCartQty')->willReturnSelf();
     $product->expects($this->once())->method('setQty');
     $this->catalogProduct->expects($this->once())->method('getSkipSaleableCheck')->willReturn(false);
 }
 /**
  * @param $productChanged
  * @param $isScheduled
  * @param $productFlatCount
  * @param $categoryIndexerCount
  *
  * @dataProvider getProductReindexProvider
  */
 public function testReindex($productChanged, $isScheduled, $productFlatCount, $categoryIndexerCount)
 {
     $this->model->setData('entity_id', 1);
     $this->_catalogProduct->expects($this->once())->method('isDataForProductCategoryIndexerWasChanged')->willReturn($productChanged);
     if ($productChanged) {
         $this->indexerRegistryMock->expects($this->exactly($productFlatCount))->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)->will($this->returnValue($this->categoryIndexerMock));
         $this->categoryIndexerMock->expects($this->any())->method('isScheduled')->will($this->returnValue($isScheduled));
         $this->categoryIndexerMock->expects($this->exactly($categoryIndexerCount))->method('reindexRow');
     }
     $this->productFlatProcessor->expects($this->exactly($productFlatCount))->method('reindexRow');
     $this->model->reindex();
 }