GuestShippingMethodManagementTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Quote\Test\Unit\Model\GuestCart;
  8. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  9. use Magento\Quote\Model\QuoteIdMask;
  10. use Magento\Quote\Api\Data\AddressInterface;
  11. use Magento\Quote\Api\ShipmentEstimationInterface;
  12. use Magento\Quote\Api\Data\ShippingMethodInterface;
  13. use Magento\Quote\Model\GuestCart\GuestShippingMethodManagement;
  14. class GuestShippingMethodManagementTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var GuestShippingMethodManagement
  18. */
  19. private $model;
  20. /**
  21. * @var \PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $shippingMethodManagementMock;
  24. /**
  25. * @var \PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $quoteIdMaskFactoryMock;
  28. /**
  29. * @var ShipmentEstimationInterface|MockObject
  30. */
  31. private $shipmentEstimationManagement;
  32. /**
  33. * @var QuoteIdMask|MockObject
  34. */
  35. private $quoteIdMask;
  36. /**
  37. * @var string
  38. */
  39. private $maskedCartId = 'f216207248d65c789b17be8545e0aa73';
  40. /**
  41. * @var int
  42. */
  43. private $cartId = 867;
  44. protected function setUp()
  45. {
  46. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  47. $this->shippingMethodManagementMock =
  48. $this->createMock(\Magento\Quote\Model\ShippingMethodManagement::class);
  49. $guestCartTestHelper = new GuestCartTestHelper($this);
  50. list($this->quoteIdMaskFactoryMock, $this->quoteIdMask) = $guestCartTestHelper->mockQuoteIdMask(
  51. $this->maskedCartId,
  52. $this->cartId
  53. );
  54. $this->shipmentEstimationManagement = $this->getMockForAbstractClass(ShipmentEstimationInterface::class);
  55. $this->model = $objectManager->getObject(
  56. GuestShippingMethodManagement::class,
  57. [
  58. 'shippingMethodManagement' => $this->shippingMethodManagementMock,
  59. 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
  60. ]
  61. );
  62. $refObject = new \ReflectionClass(GuestShippingMethodManagement::class);
  63. $refProperty = $refObject->getProperty('shipmentEstimationManagement');
  64. $refProperty->setAccessible(true);
  65. $refProperty->setValue($this->model, $this->shipmentEstimationManagement);
  66. }
  67. public function testSet()
  68. {
  69. $carrierCode = 'carrierCode';
  70. $methodCode = 'methodCode';
  71. $retValue = 'retValue';
  72. $this->shippingMethodManagementMock->expects($this->once())
  73. ->method('set')
  74. ->with($this->cartId, $carrierCode, $methodCode)
  75. ->will($this->returnValue($retValue));
  76. $this->assertEquals($retValue, $this->model->set($this->maskedCartId, $carrierCode, $methodCode));
  77. }
  78. public function testGetList()
  79. {
  80. $retValue = 'retValue';
  81. $this->shippingMethodManagementMock->expects($this->once())
  82. ->method('getList')
  83. ->with($this->cartId)
  84. ->will($this->returnValue($retValue));
  85. $this->assertEquals($retValue, $this->model->getList($this->maskedCartId));
  86. }
  87. public function testGet()
  88. {
  89. $retValue = 'retValue';
  90. $this->shippingMethodManagementMock->expects($this->once())
  91. ->method('get')
  92. ->with($this->cartId)
  93. ->will($this->returnValue($retValue));
  94. $this->assertEquals($retValue, $this->model->get($this->maskedCartId));
  95. }
  96. /**
  97. * @covers \Magento\Quote\Model\GuestCart\GuestShippingMethodManagement::getShipmentEstimationManagement
  98. */
  99. public function testEstimateByExtendedAddress()
  100. {
  101. $address = $this->getMockForAbstractClass(AddressInterface::class);
  102. $methodObject = $this->getMockForAbstractClass(ShippingMethodInterface::class);
  103. $expectedRates = [$methodObject];
  104. $this->shipmentEstimationManagement->expects(static::once())
  105. ->method('estimateByExtendedAddress')
  106. ->with($this->cartId, $address)
  107. ->willReturn($expectedRates);
  108. $carriersRates = $this->model->estimateByExtendedAddress($this->maskedCartId, $address);
  109. static::assertEquals($expectedRates, $carriersRates);
  110. }
  111. }