GuestPaymentMethodManagementTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Test\Unit\Model\GuestCart;
  7. class GuestPaymentMethodManagementTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement
  11. */
  12. protected $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $quoteIdMaskFactoryMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $quoteIdMaskMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $paymentMethodManagementMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $paymentMock;
  29. /**
  30. * @var string
  31. */
  32. protected $maskedCartId;
  33. /**
  34. * @var int
  35. */
  36. protected $cartId;
  37. protected function setUp()
  38. {
  39. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  40. $this->paymentMethodManagementMock = $this->createMock(
  41. \Magento\Quote\Api\PaymentMethodManagementInterface::class
  42. );
  43. $this->paymentMock = $this->createMock(\Magento\Quote\Model\Quote\Payment::class);
  44. $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
  45. $this->cartId = 11;
  46. $guestCartTestHelper = new GuestCartTestHelper($this);
  47. list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask(
  48. $this->maskedCartId,
  49. $this->cartId
  50. );
  51. $this->model = $objectManager->getObject(
  52. \Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement::class,
  53. [
  54. 'paymentMethodManagement' => $this->paymentMethodManagementMock,
  55. 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
  56. ]
  57. );
  58. }
  59. public function testGet()
  60. {
  61. $this->paymentMethodManagementMock->expects($this->once())->method('get')->willReturn($this->paymentMock);
  62. $this->assertEquals($this->paymentMock, $this->model->get($this->maskedCartId));
  63. }
  64. public function testGetList()
  65. {
  66. $paymentMethod = $this->createMock(\Magento\Quote\Api\Data\PaymentMethodInterface::class);
  67. $this->paymentMethodManagementMock->expects($this->once())->method('getList')->willReturn([$paymentMethod]);
  68. $this->assertEquals([$paymentMethod], $this->model->getList($this->maskedCartId));
  69. }
  70. public function testSetSimpleProduct()
  71. {
  72. $paymentId = 20;
  73. $this->paymentMethodManagementMock->expects($this->once())->method('set')->willReturn($paymentId);
  74. $this->assertEquals($paymentId, $this->model->set($this->maskedCartId, $this->paymentMock));
  75. }
  76. }