Beispiel #1
0
 /**
  * @param bool $canReturnToStock
  * @param bool $manageStock
  * @param bool $result
  * @dataProvider canReturnItemsToStockDataProvider
  */
 public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result)
 {
     $productId = 7;
     $property = new \ReflectionProperty($this->items, '_canReturnToStock');
     $property->setAccessible(true);
     $this->assertNull($property->getValue($this->items));
     $this->scopeConfig->expects($this->once())->method('getValue')->with($this->equalTo(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_CAN_SUBTRACT), $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE))->will($this->returnValue($canReturnToStock));
     if ($canReturnToStock) {
         $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup'], [], '', false);
         $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId));
         $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false);
         $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false);
         $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem]));
         $creditMemoItem->expects($this->once())->method('getOrderItem')->will($this->returnValue($orderItem));
         $this->stockItemMock->expects($this->once())->method('getManageStock')->with($this->equalTo($productId))->will($this->returnValue($manageStock));
         $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf());
         $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false);
         $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf());
         $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order));
         $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo));
     }
     $this->assertSame($result, $this->items->canReturnItemsToStock());
     $this->assertSame($result, $property->getValue($this->items));
     // lazy load test
     $this->assertSame($result, $this->items->canReturnItemsToStock());
 }
Beispiel #2
0
 public function testSuggestItemsQty()
 {
     $data = [[], ['qty' => -2], ['qty' => 3], ['qty' => 3.5], ['qty' => 5], ['qty' => 4]];
     $quote = $this->getMock('Magento\\Sales\\Model\\Quote', [], [], '', false);
     $quote->expects($this->any())->method('getItemById')->will($this->returnValueMap([[2, $this->prepareQuoteItemMock(2)], [3, $this->prepareQuoteItemMock(3)], [4, $this->prepareQuoteItemMock(4)], [5, $this->prepareQuoteItemMock(5)]]));
     $this->stockItemMock->expects($this->any())->method('suggestQty')->will($this->returnValueMap([[4, 3.0, 3.0], [5, 3.5, 3.5]]));
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($quote));
     $this->assertSame([[], ['qty' => -2], ['qty' => 3.0, 'before_suggest_qty' => 3.0], ['qty' => 3.5, 'before_suggest_qty' => 3.5], ['qty' => 5], ['qty' => 4]], $this->cart->suggestItemsQty($data));
 }
Beispiel #3
0
 /**
  * @param int $productId
  * @param int $qtyInc
  * @param bool $isSaleable
  * @param int|bool $result
  * @dataProvider getProductQtyIncrementsDataProvider
  */
 public function testGetProductQtyIncrements($productId, $qtyInc, $isSaleable, $result)
 {
     $this->stockItemService->expects($this->once())->method('getQtyIncrements')->with($this->equalTo($productId))->will($this->returnValue($qtyInc));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
     $product->expects($this->once())->method('isSaleable')->will($this->returnValue($isSaleable));
     $this->registryMock->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product));
     $this->assertSame($result, $this->block->getProductQtyIncrements());
     // test lazy load
     $this->assertSame($result, $this->block->getProductQtyIncrements());
 }
Beispiel #4
0
 public function testBuildWithCurrentProductStockItem()
 {
     $expectedData = array('use_config_min_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'use_config_backorders' => 1, 'use_config_notify_stock_qty' => 1, 'use_config_enable_qty_inc' => 'use_config_enable_qty_inc', 'enable_qty_increments' => 'enable_qty_increments', 'use_config_qty_increments' => 'use_config_qty_increments', 'qty_increments' => 'qty_increments');
     $this->stockItemServiceMock->expects($this->once())->method('getStockItem')->will($this->returnValue($this->stockItemDoMock));
     $this->stockItemDoMock->expects($this->any())->method('getStockId')->will($this->returnValue(50));
     $this->stockItemDoMock->expects($this->any())->method('isUseConfigEnableQtyInc')->will($this->returnValue('use_config_enable_qty_inc'));
     $this->stockItemDoMock->expects($this->any())->method('isEnableQtyIncrements')->will($this->returnValue('enable_qty_increments'));
     $this->stockItemDoMock->expects($this->any())->method('isUseConfigQtyIncrements')->will($this->returnValue('use_config_qty_increments'));
     $this->stockItemDoMock->expects($this->any())->method('getQtyIncrements')->will($this->returnValue('qty_increments'));
     $this->duplicateMock->expects($this->once())->method('setStockData')->with($expectedData);
     $this->model->build($this->productMock, $this->duplicateMock);
 }
Beispiel #5
0
 public function testInitWithNonDecimalQty()
 {
     $quoteItemMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false);
     $this->stockItemServiceMock->expects($this->once())->method('getStockItem')->will($this->returnValue($this->getStockItemDo(false)));
     $this->productMock->expects($this->once())->method('getId')->will($this->returnSelf());
     $this->productMock->expects($this->never())->method('setIsQtyDecimal');
     $this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf());
     $this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10));
     $this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf());
     $this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock));
     $this->assertInstanceOf('Magento\\Sales\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock));
 }
Beispiel #6
0
 /**
  * @covers \Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid::getItems
  */
 public function testGetItems()
 {
     $productId = 8;
     $itemQty = 23;
     $layoutMock = $this->getMock('Magento\\Framework\\View\\LayoutInterface');
     $blockMock = $this->getMock('Magento\\Framework\\View\\Element\\AbstractBlock', ['getItems'], [], '', false);
     $itemMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Item', array('getProduct', 'setHasError', 'setQty', 'getQty', '__sleep', '__wakeup'), array(), '', false);
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', array('getStockItem', 'getID', '__sleep', '__wakeup'), array(), '', false);
     $checkMock = $this->getMock('Magento\\Framework\\Object', ['getMessage', 'getHasError'], [], '', false);
     $layoutMock->expects($this->once())->method('getParentName')->will($this->returnValue('parentBlock'));
     $layoutMock->expects($this->once())->method('getBlock')->with('parentBlock')->will($this->returnValue($blockMock));
     $blockMock->expects($this->once())->method('getItems')->will($this->returnValue(array($itemMock)));
     $itemMock->expects($this->any())->method('getChildren')->will($this->returnValue(array($itemMock)));
     $itemMock->expects($this->any())->method('getProduct')->will($this->returnValue($productMock));
     $itemMock->expects($this->any())->method('getQty')->will($this->returnValue($itemQty));
     $productMock->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $productMock->expects($this->any())->method('getStatus')->will($this->returnValue(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED));
     $checkMock->expects($this->any())->method('getMessage')->will($this->returnValue('Message'));
     $checkMock->expects($this->any())->method('getHasError')->will($this->returnValue(false));
     $this->stockItemService->expects($this->once())->method('checkQuoteItemQty')->with($this->equalTo($productId), $this->equalTo($itemQty), $this->equalTo($itemQty))->will($this->returnValue($checkMock));
     $this->block->getQuote()->setIsSuperMode(true);
     $items = $this->block->setLayout($layoutMock)->getItems();
     $this->assertEquals('Message', $items[0]->getMessage());
     $this->assertEquals(true, $this->block->getQuote()->getIsSuperMode());
 }
 /**
  * @param string $productSku
  * @param int $productId
  * @param int $websiteId
  * @param array $productStockStatusArray
  * @param int $stockQty
  * @param array $array
  * @dataProvider getProductStockStatusBySkuDataProvider
  */
 public function testGetProductStockStatusBySku($productSku, $productId, $websiteId, $productStockStatusArray, $stockQty, $array)
 {
     // 1. Create mocks
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     /** @var \Magento\Framework\App\ScopeInterface|\PHPUnit_Framework_MockObject_MockObject $scope */
     $scope = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->getMock();
     /**
      * @var \Magento\CatalogInventory\Service\V1\Data\StockStatus|\PHPUnit_Framework_MockObject_MockObject $scope
      */
     $stockStatusDataObject = $this->getMockBuilder('Magento\\CatalogInventory\\Service\\V1\\Data\\StockStatus')->disableOriginalConstructor()->getMock();
     // 2. Set fixtures
     $this->productLoader->expects($this->any())->method('load')->will($this->returnValueMap([[$productSku, $product]]));
     $product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValue($scope));
     $scope->expects($this->any())->method('getId')->will($this->returnValue($websiteId));
     $this->stockStatusBuilder->expects($this->any())->method('create')->will($this->returnValue($stockStatusDataObject));
     // 3. Set expectations
     $this->stockStatus->expects($this->any())->method('getProductStockStatus')->with([$productId], $websiteId)->will($this->returnValue($productStockStatusArray));
     $this->stockItemService->expects($this->any())->method('getStockQty')->will($this->returnValueMap([[$productId, $stockQty]]));
     $this->stockStatusBuilder->expects($this->any())->method('populateWithArray')->with($array);
     // 4. Run tested method
     $result = $this->model->getProductStockStatusBySku($productSku);
     // 5. Compare actual result with expected result
     $this->assertEquals($stockStatusDataObject, $result);
 }
Beispiel #8
0
 /**
  * @param int $productStockQty
  * @param int|null $productId
  * @param int|null $dataQty
  * @param int $expectedQty
  * @dataProvider getStockQtyDataProvider
  */
 public function testGetStockQty($productStockQty, $productId, $dataQty, $expectedQty)
 {
     $this->assertNull($this->block->getData('product_stock_qty'));
     if ($dataQty) {
         $this->setDataArrayValue('product_stock_qty', $dataQty);
     } else {
         $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', '__wakeup'], [], '', false);
         $product->expects($this->any())->method('getId')->will($this->returnValue($productId));
         $this->registryMock->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product));
         if ($productId) {
             $this->stockItemService->expects($this->once())->method('getStockQty')->with($this->equalTo($productId))->will($this->returnValue($productStockQty));
         }
     }
     $this->assertSame($expectedQty, $this->block->getStockQty());
     $this->assertSame($expectedQty, $this->block->getData('product_stock_qty'));
 }
Beispiel #9
0
 public function testSave()
 {
     $this->item->setData('key', 'value');
     $this->eventManager->expects($this->at(0))->method('dispatch')->with('model_save_before', ['object' => $this->item]);
     $this->eventManager->expects($this->at(1))->method('dispatch')->with('cataloginventory_stock_item_save_before', ['data_object' => $this->item, 'item' => $this->item]);
     $this->resource->expects($this->once())->method('addCommitCallback')->will($this->returnValue($this->resource));
     $this->stockItemService->expects($this->any())->method('isQty')->will($this->returnValue(true));
     $this->assertEquals($this->item, $this->item->save());
 }
Beispiel #10
0
 public function testExecuteThatProductIdsAreObtainedFromAttributeHelper()
 {
     $this->attributeHelper->expects($this->any())->method('getProductIds')->will($this->returnValue([5]));
     $this->attributeHelper->expects($this->any())->method('getSelectedStoreId')->will($this->returnValue([1]));
     $this->inventoryHelper->expects($this->any())->method('getConfigItemOptions')->will($this->returnValue([]));
     $this->product->expects($this->any())->method('isProductsHasSku')->with([5])->will($this->returnValue(true));
     $this->stockItemService->expects($this->any())->method('getStockItem')->with(5)->will($this->returnValue($this->stockItem));
     $this->stockIndexerProcessor->expects($this->any())->method('reindexList')->with([5]);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['inventory', [], [7]]]));
     $this->messageManager->expects($this->never())->method('addError');
     $this->messageManager->expects($this->never())->method('addException');
     $this->object->execute();
 }
Beispiel #11
0
 /**
  * @param int|bool $productId
  * @param bool $result
  * @dataProvider isItemAvailableForReorderDataProvider
  */
 public function testIsItemAvailableForReorder($productId, $result)
 {
     if ($productId) {
         $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', '__wakeup'], [], '', false);
         $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
         $this->stockItemService->expects($this->once())->method('getIsInStock')->with($this->equalTo($productId))->will($this->returnValue($result));
     } else {
         $product = false;
     }
     $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', [], [], '', false);
     $orderItem->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $this->createBlockObject();
     $this->assertSame($result, $this->block->isItemAvailableForReorder($orderItem));
 }