Example #1
0
 public function testAssignStatusToProduct()
 {
     $websiteId = 1;
     $status = 'test';
     $stockStatusMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface')->disableOriginalConstructor()->getMock();
     $stockStatusMock->expects($this->any())->method('getStockStatus')->willReturn($status);
     $this->stockRegistryProviderMock->expects($this->any())->method('getStockStatus')->willReturn($stockStatusMock);
     $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn($websiteId);
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['setIsSalable', 'getId'])->getMock();
     $productMock->expects($this->once())->method('setIsSalable')->with($status);
     $this->assertNull($this->stock->assignStatusToProduct($productMock));
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerateSimpleProducts()
 {
     $productsData = [6 => ['image' => 'image.jpg', 'name' => 'config-red', 'configurable_attribute' => '{"new_attr":"6"}', 'sku' => 'config-red', 'quantity_and_stock_status' => ['qty' => ''], 'weight' => '333']];
     $stockData = ['manage_stock' => '0', 'use_config_enable_qty_increments' => '1', 'use_config_qty_increments' => '1', 'use_config_manage_stock' => 0, 'is_decimal_divided' => 0];
     $parentProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getNewVariationsAttributeSetId', 'getStockData', 'getQuantityAndStockStatus', 'getWebsiteIds'])->disableOriginalConstructor()->getMock();
     $newSimpleProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'save', 'getId', 'setStoreId', 'setTypeId', 'setAttributeSetId', 'getTypeInstance', 'getStoreId', 'addData', 'setWebsiteIds', 'setStatus', 'setVisibility'])->disableOriginalConstructor()->getMock();
     $productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type')->setMethods(['getSetAttributes'])->disableOriginalConstructor()->getMock();
     $editableAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['getIsUnique', 'getAttributeCode', 'getFrontend', 'getIsVisible'])->disableOriginalConstructor()->getMock();
     $frontendAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend')->setMethods(['getInputType'])->disableOriginalConstructor()->getMock();
     $parentProductMock->expects($this->once())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
     $newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
     $productTypeMock->expects($this->once())->method('getSetAttributes')->with($newSimpleProductMock)->willReturn([$editableAttributeMock]);
     $editableAttributeMock->expects($this->once())->method('getIsUnique')->willReturn(false);
     $editableAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn('some_code');
     $editableAttributeMock->expects($this->any())->method('getFrontend')->willReturn($frontendAttributeMock);
     $frontendAttributeMock->expects($this->any())->method('getInputType')->willReturn('input_type');
     $editableAttributeMock->expects($this->any())->method('getIsVisible')->willReturn(false);
     $parentProductMock->expects($this->once())->method('getStockData')->willReturn($stockData);
     $parentProductMock->expects($this->once())->method('getQuantityAndStockStatus')->willReturn(['is_in_stock' => 1]);
     $newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
     $this->stockConfiguration->expects($this->once())->method('getManageStock')->with('store_id')->willReturn(1);
     $newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
     $parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
     $newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setVisibility')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('save')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getId')->willReturn('product_id');
     $this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
 }
 /**
  * Run test getDefaultConfigValue method
  *
  * @return void
  */
 public function testGetDefaultConfigValue()
 {
     $field = 'filed-name';
     $this->stockConfigurationMock->expects($this->once())->method('getDefaultConfigValue')->will($this->returnValue('return-value'));
     $result = $this->inventory->getDefaultConfigValue($field);
     $this->assertEquals('return-value', $result);
 }
Example #4
0
 public function testRefundOrderInventory()
 {
     $websiteId = 0;
     $ids = ['1', '14'];
     $items = [];
     $isAutoReturnEnabled = true;
     $itemsToUpdate = [];
     foreach ($ids as $id) {
         $item = $this->getCreditMemoItem($id);
         $items[] = $item;
         $itemsToUpdate[$item->getProductId()] = $item->getQty();
     }
     $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false);
     $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue($items));
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId', '__wakeup'], [], '', false);
     $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $creditMemo->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->stockConfiguration->expects($this->any())->method('isAutoReturnEnabled')->will($this->returnValue($isAutoReturnEnabled));
     $this->stockManagement->expects($this->once())->method('revertProductsSale')->with($itemsToUpdate, $websiteId);
     $this->stockIndexerProcessor->expects($this->once())->method('reindexList')->with($ids);
     $this->priceIndexer->expects($this->once())->method('reindexList')->with($ids);
     $this->event->expects($this->once())->method('getCreditmemo')->will($this->returnValue($creditMemo));
     $this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
     $this->observer->refundOrderInventory($this->eventObserver);
 }
Example #5
0
 /**
  * @param bool $useConfigMinQty
  * @param float $minQty
  * @dataProvider setMinQtyDataProvider
  */
 public function testSetMinQty($useConfigMinQty, $minQty)
 {
     $this->setDataArrayValue('use_config_min_qty', $useConfigMinQty);
     if ($useConfigMinQty) {
         $this->stockConfiguration->expects($this->any())->method('getMinQty')->will($this->returnValue($minQty));
     } else {
         $this->setDataArrayValue('min_qty', $minQty);
     }
     $this->assertSame($minQty, $this->item->getMinQty());
 }
Example #6
0
 /**
  * @param array $config
  * @param mixed $expected
  * @dataProvider getQtyIncrementsDataProvider(
  */
 public function testGetQtyIncrements($config, $expected)
 {
     $this->setDataArrayValue('qty_increments', $config['qty_increments']);
     $this->setDataArrayValue('enable_qty_increments', $config['enable_qty_increments']);
     $this->setDataArrayValue('use_config_qty_increments', $config['use_config_qty_increments']);
     if ($config['use_config_qty_increments']) {
         $this->stockConfiguration->expects($this->once())->method('getQtyIncrements')->with($this->storeId)->willReturn($config['qty_increments']);
     } else {
         $this->setDataArrayValue('qty_increments', $config['qty_increments']);
     }
     $this->assertEquals($expected, $this->item->getQtyIncrements());
 }
 public function testModifyData()
 {
     $modelId = 1;
     $someData = 1;
     $this->productMock->expects($this->any())->method('getId')->willReturn($modelId);
     $this->stockConfigurationMock->expects($this->any())->method('getDefaultConfigValue')->willReturn("a:0:{}");
     $this->stockItemMock->expects($this->once())->method('getData')->willReturn(['someData']);
     $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getQty')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getMinQty')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getMinSaleQty')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getMaxSaleQty')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getIsDecimalDivided')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getBackorders')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getNotifyStockQty')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getEnableQtyIncrements')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getQtyIncrements')->willReturn($someData);
     $this->stockItemMock->expects($this->once())->method('getIsInStock')->willReturn($someData);
     $this->arrayManagerMock->expects($this->once())->method('set')->with('1/product/stock_data/min_qty_allowed_in_shopping_cart')->willReturnArgument(1);
     $this->assertArrayHasKey($modelId, $this->getModel()->modifyData([]));
 }
Example #8
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->attributeHelper->expects($this->any())->method('getStoreWebsiteId')->will($this->returnValue(1));
     $this->stockConfig->expects($this->any())->method('getConfigItemOptions')->will($this->returnValue([]));
     $this->dataObjectHelperMock->expects($this->any())->method('populateWithArray')->with($this->stockItem, $this->anything(), '\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->willReturnSelf();
     $this->product->expects($this->any())->method('isProductsHasSku')->with([5])->will($this->returnValue(true));
     $this->stockItemService->expects($this->any())->method('getStockItem')->with(5, 1)->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();
 }
 /**
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  */
 public function testSaveException()
 {
     $productId = 1;
     $this->stockItemMock->expects($this->any())->method('getProductId')->willReturn($productId);
     $this->productMock->expects($this->once())->method('load')->with($productId)->willReturnSelf();
     $this->productMock->expects($this->once())->method('getId')->willReturn($productId);
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('typeId');
     $this->stockConfigurationMock->expects($this->once())->method('isQty')->with('typeId')->willReturn(false);
     $this->stockItemMock->expects($this->once())->method('setQty')->with(0)->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('getWebsiteId')->willReturn(1);
     $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with(1)->willReturnSelf();
     $this->stockItemMock->expects($this->once())->method('getStockId')->willReturn(1);
     $this->stockItemMock->expects($this->once())->method('setStockId')->with(1)->willReturnSelf();
     $this->stockItemResourceMock->expects($this->once())->method('save')->with($this->stockItemMock)->willThrowException(new \Exception());
     $this->model->save($this->stockItemMock);
 }
Example #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->attributeHelper->expects($this->any())->method('getStoreWebsiteId')->will($this->returnValue(1));
     $this->stockConfig->expects($this->any())->method('getConfigItemOptions')->will($this->returnValue([]));
     $itemToSave = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->disableOriginalConstructor()->setMethods(['setItemId', 'save'])->getMockForAbstractClass();
     $this->stockItemBuilder->expects($this->any())->method('mergeDataObjectWithArray')->withAnyParameters()->willReturnSelf();
     $this->stockItemBuilder->expects($this->any())->method('create')->willReturn($itemToSave);
     $this->product->expects($this->any())->method('isProductsHasSku')->with([5])->will($this->returnValue(true));
     $this->stockItemService->expects($this->any())->method('getStockItem')->with(5, 1)->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();
 }
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Invalid stock item id: 35. Assigned stock item id is 40
  */
 public function testAroundSaveWithNotAssignedStockItemId()
 {
     $stockId = 80;
     $stockItemId = 35;
     $defaultScopeId = 100;
     $defaultStockId = 80;
     $storedStockitemId = 40;
     $this->stockItem->expects($this->once())->method('getStockId')->willReturn($stockId);
     $this->stockRegistry->expects($this->once())->method('getStock')->with($defaultScopeId)->willReturn($this->defaultStock);
     $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn($defaultScopeId);
     $this->defaultStock->expects($this->once())->method('getStockId')->willReturn($defaultStockId);
     $this->product->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtension);
     $this->productExtension->expects($this->once())->method('getStockItem')->willReturn($this->stockItem);
     $this->stockItem->expects($this->once())->method('getItemId')->willReturn($stockItemId);
     $storedStockItem = $this->getMockBuilder(StockItemInterface::class)->setMethods(['getItemId'])->getMockForAbstractClass();
     $storedStockItem->expects($this->once())->method('getItemId')->willReturn($storedStockitemId);
     $this->stockRegistry->expects($this->once())->method('getStockItem')->willReturn($storedStockItem);
     $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product);
 }
 public function testBuildWithoutOutOfStock()
 {
     $scopeId = '113';
     $tableSuffix = 'scope113_someNamesomeValue';
     $index = 'test_index_name';
     $dimensions = [$this->createDimension('scope', $scopeId), $this->createDimension('someName', 'someValue')];
     $this->request->expects($this->exactly(2))->method('getDimensions')->willReturn($dimensions);
     $this->dimensionScopeResolver->expects($this->once())->method('getScope')->willReturn($this->scopeInterface);
     $this->scopeInterface->expects($this->once())->method('getId')->willReturn('someValue');
     $this->mockBuild($index, $tableSuffix, false);
     $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn(1);
     $this->config->expects($this->once())->method('isSetFlag')->with('cataloginventory/options/show_out_of_stock')->will($this->returnValue(false));
     $this->connection->expects($this->once())->method('quoteInto')->with(' AND stock_index.website_id = ?', 1)->willReturn(' AND stock_index.website_id = 1');
     $this->select->expects($this->at(2))->method('where')->with('(someName=someValue)')->willReturnSelf();
     $this->select->expects($this->at(3))->method('joinLeft')->with(['stock_index' => 'cataloginventory_stock_status'], 'search_index.entity_id = stock_index.product_id' . ' AND stock_index.website_id = 1', [])->willReturnSelf();
     $this->select->expects($this->at(4))->method('where')->with('stock_index.stock_status = ?', 1)->will($this->returnSelf());
     $result = $this->target->build($this->request);
     $this->assertSame($this->select, $result);
 }