Ejemplo n.º 1
0
 public function testGetTotals()
 {
     $cartId = 12;
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock);
     $this->addressMock->expects($this->once())->method('getData')->willReturn(['addressData']);
     $this->quoteMock->expects($this->once())->method('getData')->willReturn(['quoteData']);
     $item = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
     $this->quoteMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$item]));
     $this->model->get($cartId);
 }
 public function testGetTotals()
 {
     $cartId = 12;
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock);
     $this->addressMock->expects($this->once())->method('getData')->willReturn(['addressData']);
     $this->quoteMock->expects($this->once())->method('getData')->willReturn(['quoteData']);
     $item = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
     $this->quoteMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$item]));
     $totals = $this->getMock('Magento\\Quote\\Model\\Cart\\Totals', ['setItems'], [], '', false);
     $this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totals);
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray');
     $totals->expects($this->once())->method('setItems');
     $this->model->get($cartId);
 }
 /**
  * @param bool $isVirtual
  * @param string $getAddressType
  * @dataProvider getDataProvider
  */
 public function testGet($isVirtual, $getAddressType)
 {
     $cartId = 12;
     $itemsQty = 100;
     $coupon = 'coupon';
     $addressTotals = ['address' => 'totals'];
     $itemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
     $visibleItems = [11 => $itemMock];
     $itemArray = ['name' => 'item', 'options' => [4 => ['label' => 'justLabel']]];
     $currencyCode = 'US';
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->willReturn($this->quoteMock);
     $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn($isVirtual);
     $this->quoteMock->expects($this->exactly(2))->method($getAddressType)->willReturn($this->addressMock);
     $this->quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn($visibleItems);
     $this->quoteMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn($currencyCode);
     $this->quoteMock->expects($this->once())->method('getQuoteCurrencyCode')->willReturn($currencyCode);
     $this->quoteMock->expects($this->once())->method('getItemsQty')->willReturn($itemsQty);
     $this->addressMock->expects($this->any())->method('getData')->willReturn($addressTotals);
     $this->addressMock->expects($this->once())->method('getTotals')->willReturn($addressTotals);
     $totalsMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totalsMock);
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray');
     $this->converterMock->expects($this->once())->method('modelToDataObject')->with($itemMock)->willReturn($itemArray);
     $totalSegmentsMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\TotalSegmentInterface');
     $this->totalsConverterMock->expects($this->once())->method('process')->with($addressTotals)->willReturn($totalSegmentsMock);
     $this->couponServiceMock->expects($this->once())->method('get')->with($cartId)->willReturn($coupon);
     $totalsMock->expects($this->once())->method('setItems')->with([11 => $itemArray])->willReturnSelf();
     $totalsMock->expects($this->once())->method('setTotalSegments')->with($totalSegmentsMock)->willReturnSelf();
     $totalsMock->expects($this->once())->method('setCouponCode')->with($coupon)->willReturnSelf();
     $totalsMock->expects($this->once())->method('setGrandTotal')->willReturnSelf();
     $totalsMock->expects($this->once())->method('setItemsQty')->with($itemsQty)->willReturnSelf();
     $totalsMock->expects($this->once())->method('setBaseCurrencyCode')->with($currencyCode)->willReturnSelf();
     $totalsMock->expects($this->once())->method('setQuoteCurrencyCode')->with($currencyCode)->willReturnSelf();
     $this->assertEquals($totalsMock, $this->model->get($cartId));
 }
Ejemplo n.º 4
0
 public function testGet()
 {
     $cartId = 12;
     $itemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
     $visibleItems = [11 => $itemMock];
     $itemArray = ['name' => 'item', 'options' => [4 => ['label' => 'justLabel']]];
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock);
     $this->addressMock->expects($this->once())->method('getData')->willReturn(['addressData']);
     $this->quoteMock->expects($this->once())->method('getData')->willReturn(['quoteData']);
     $this->quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn($visibleItems);
     $totalsMock = $this->getMock('Magento\\Quote\\Model\\Cart\\Totals', ['setItems'], [], '', false);
     $this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totalsMock);
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray');
     $this->converterMock->expects($this->once())->method('modelToDataObject')->with($itemMock)->willReturn($itemArray);
     //back in get()
     $totalsMock->expects($this->once())->method('setItems')->with([11 => $itemArray]);
     $this->assertEquals($totalsMock, $this->model->get($cartId));
 }