コード例 #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->stockConfiguration->expects($this->once())->method('canSubtractQty')->will($this->returnValue($canReturnToStock));
     if ($canReturnToStock) {
         $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup', 'getStore'], [], '', false);
         $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
         $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10));
         $orderItem->expects($this->any())->method('getStore')->will($this->returnValue($store));
         $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->any())->method('getOrderItem')->will($this->returnValue($orderItem));
         $this->stockItemMock->expects($this->once())->method('getManageStock')->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());
 }
コード例 #2
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());
 }