GuestCouponManagementTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. class GuestCouponManagementTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Quote\Model\GuestCart\GuestCouponManagement
  12. */
  13. protected $model;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $quoteIdMaskFactoryMock;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $quoteIdMaskMock;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $couponManagementMock;
  26. /**
  27. * @var string
  28. */
  29. protected $maskedCartId;
  30. /**
  31. * @var int
  32. */
  33. protected $cartId;
  34. /**
  35. * @var string
  36. */
  37. protected $couponCode;
  38. protected function setUp()
  39. {
  40. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  41. $this->couponManagementMock = $this->createMock(\Magento\Quote\Api\CouponManagementInterface::class);
  42. $this->couponCode = 'test_coupon_code';
  43. $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
  44. $this->cartId = 123;
  45. $guestCartTestHelper = new GuestCartTestHelper($this);
  46. list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask(
  47. $this->maskedCartId,
  48. $this->cartId
  49. );
  50. $this->model = $objectManager->getObject(
  51. \Magento\Quote\Model\GuestCart\GuestCouponManagement::class,
  52. [
  53. 'couponManagement' => $this->couponManagementMock,
  54. 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
  55. ]
  56. );
  57. }
  58. public function testGet()
  59. {
  60. $this->couponManagementMock->expects($this->once())->method('get')->willReturn($this->couponCode);
  61. $this->assertEquals($this->couponCode, $this->model->get($this->maskedCartId));
  62. }
  63. public function testSet()
  64. {
  65. $this->couponManagementMock->expects($this->once())->method('set')->willReturn(true);
  66. $this->assertTrue($this->model->set($this->maskedCartId, $this->couponCode));
  67. }
  68. public function testRemove()
  69. {
  70. $this->couponManagementMock->expects($this->once())->method('remove')->willReturn(true);
  71. $this->assertTrue($this->model->remove($this->maskedCartId));
  72. }
  73. }