Ejemplo n.º 1
0
 /**
  * @dataProvider fetchDataProvider
  */
 public function testFetch($shippingAmount, $shippingDescription, $expectedTotal)
 {
     $address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['getShippingAmount', 'getShippingDescription', 'addTotal', '__wakeup'], [], '', false);
     $address->expects($this->once())->method('getShippingAmount')->will($this->returnValue($shippingAmount));
     $address->expects($this->once())->method('getShippingDescription')->will($this->returnValue($shippingDescription));
     $address->expects($this->once())->method('addTotal')->with($this->equalTo($expectedTotal))->will($this->returnSelf());
     $this->assertEquals($this->shippingModel, $this->shippingModel->fetch($address));
 }
Ejemplo n.º 2
0
 public function testFetch()
 {
     $shippingAmount = 100;
     $shippingDescription = 100;
     $expectedResult = ['code' => 'shipping', 'value' => 100, 'title' => __('Shipping & Handling (%1)', $shippingDescription)];
     $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
     $totalMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address\\Total', ['getShippingAmount', 'getShippingDescription'], [], '', false);
     $totalMock->expects($this->once())->method('getShippingAmount')->willReturn($shippingAmount);
     $totalMock->expects($this->once())->method('getShippingDescription')->willReturn($shippingDescription);
     $this->assertEquals($expectedResult, $this->shippingModel->fetch($quoteMock, $totalMock));
 }
Ejemplo n.º 3
0
 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);
 }