Exemplo n.º 1
0
 /**
  * @return void
  */
 public function testUpdateItemOptions()
 {
     $cartId = 11;
     $itemId = 5;
     $buyRequest = $this->getMock('Magento\\Framework\\DataObject', [], [], '', false);
     $cartItemProcessorMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item\\CartItemProcessorInterface');
     $this->repository = new \Magento\Quote\Model\Quote\Item\Repository($this->quoteRepositoryMock, $this->productRepositoryMock, $this->itemDataFactoryMock, ['simple' => $cartItemProcessorMock, 'custom_options' => $this->customOptionProcessor]);
     $requestMock = $this->getMock('\\Magento\\Framework\\DataObject', ['setQty', 'getData'], [], '', false);
     $cartItemProcessorMock->expects($this->once())->method('convertToBuyRequest')->willReturn($requestMock);
     $cartItemProcessorMock->expects($this->once())->method('processOptions')->willReturn($this->quoteItemMock);
     $requestMock->expects($this->once())->method('setQty')->with(12)->willReturnSelf();
     $requestMock->expects($this->once())->method('getData')->willReturn([]);
     $this->quoteMock->expects($this->once())->method('updateItem')->with($itemId, $buyRequest)->willReturn($this->quoteItemMock);
     $this->dataMock->expects($this->any())->method('getQty')->will($this->returnValue(12));
     $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId));
     $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
     $this->quoteItemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple');
     $this->productRepositoryMock->expects($this->never())->method('get');
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
     $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
     $this->quoteMock->expects($this->once())->method('getAllItems')->willReturn([$this->quoteItemMock]);
     $this->quoteItemMock->expects($this->any())->method('getId')->willReturn($itemId);
     $this->quoteItemMock->expects($this->any())->method('getQty')->willReturn(12);
     $this->customOptionProcessor->expects($this->once())->method('convertToBuyRequest')->with($this->dataMock)->willReturn($buyRequest);
     $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock));
 }
 public function testProcessCustomOptions()
 {
     $optionId = 23;
     $quoteItemOption = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->cartItem->expects($this->atLeastOnce())->method('getOptionByCode')->with('info_buyRequest')->willReturn($quoteItemOption);
     $quoteItemOption->expects($this->once())->method('getValue')->willReturn('a:1:{s:7:"options";a:1:{i:' . $optionId . ';a:2:{i:0;s:1:"5";i:1;s:1:"6";}}} ');
     $this->customOptionFactory->expects($this->once())->method('create')->willReturn($this->customOption);
     $this->customOption->expects($this->once())->method('setOptionId')->with($optionId);
     $this->customOption->expects($this->once())->method('setOptionValue')->with('5,6');
     $this->cartItem->expects($this->atLeastOnce())->method('getProductOption')->willReturn(false);
     $this->productOptionFactory->expects($this->once())->method('create')->willReturn($this->productOption);
     $this->productOption->expects($this->once())->method('getExtensionAttributes')->willReturn(false);
     $this->extensionFactory->expects($this->once())->method('create')->willReturn($this->extensibleAttribute);
     $this->extensibleAttribute->expects($this->once())->method('setCustomOptions')->with([$optionId => $this->customOption]);
     $this->productOption->expects($this->once())->method('setExtensionAttributes')->with($this->extensibleAttribute);
     $this->cartItem->expects($this->once())->method('setProductOption')->with($this->productOption);
     $this->assertSame($this->cartItem, $this->processor->processOptions($this->cartItem));
 }