public function testCollect() { $this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping); $this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address); $this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate'); $this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]); $this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true); $this->address->expects($this->once())->method('setFreeShipping')->with(true); $this->total->expects($this->atLeastOnce())->method('setTotalAmount'); $this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount'); $this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf(); $this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false); $this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false); $this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false); $this->cartItem->expects($this->once())->method('getWeight')->willReturn(2); $this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2); $this->address->expects($this->once())->method('getFreeShipping')->willReturn(true); $this->cartItem->expects($this->once())->method('setRowWeight')->with(0); $this->address->expects($this->once())->method('setItemQty')->with(2); $this->address->expects($this->atLeastOnce())->method('setWeight'); $this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight'); $this->address->expects($this->once())->method('collectShippingRates'); $this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]); $this->rate->expects($this->once())->method('getCode')->willReturn('flatrate'); $this->quote->expects($this->once())->method('getStore')->willReturn($this->store); $this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5); $this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5); $this->total->expects($this->once())->method('setShippingAmount')->with(5); $this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title'); $this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title'); $this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title'); $this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total); }
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)); }
public function testSave() { $this->quoteRepositoryMock->expects($this->any())->method('get')->willReturn($this->quoteMock); $this->quoteItemMock->expects($this->once())->method('getItemId')->willReturn($this->itemId); $this->quoteItemMock->expects($this->once())->method('getProductType')->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock); $this->messageMock->expects($this->any())->method('setCustomerId'); $this->messageMock->expects($this->any())->method('setGiftMessageId'); $this->cacheMock->expects($this->once())->method('save'); $this->assertTrue($this->itemRepository->save($this->cartId, $this->messageMock, $this->itemId)); }
protected function freeShippingAssertions() { $this->address->expects($this->at(0))->method('getFreeShipping')->willReturn(false); $this->address->expects($this->at(1))->method('getFreeShipping')->willReturn(true); $this->cartItem->expects($this->atLeastOnce())->method('getFreeShipping')->willReturn(true); }