QuoteAdapterTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Gateway\Data\Quote;
  7. use Magento\Payment\Gateway\Data\Quote\QuoteAdapter;
  8. use Magento\Quote\Api\Data\CartInterface;
  9. use Magento\Payment\Gateway\Data\AddressAdapterInterface;
  10. /**
  11. * Class QuoteAdapterTest
  12. */
  13. class QuoteAdapterTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /** @var QuoteAdapter */
  16. protected $model;
  17. /**
  18. * @var CartInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $quoteMock;
  21. /**
  22. * @var \Magento\Payment\Gateway\Data\Quote\AddressAdapterFactory|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $addressAdapterFactoryMock;
  25. protected function setUp()
  26. {
  27. $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
  28. $this->addressAdapterFactoryMock =
  29. $this->getMockBuilder(\Magento\Payment\Gateway\Data\Quote\AddressAdapterFactory::class)
  30. ->setMethods(['create'])
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $this->model = new QuoteAdapter($this->quoteMock, $this->addressAdapterFactoryMock);
  34. }
  35. public function testGetCurrencyCode()
  36. {
  37. $expected = 'USD';
  38. /** @var \Magento\Quote\Api\Data\CurrencyInterface $currencyMock */
  39. $currencyMock = $this->getMockBuilder(
  40. \Magento\Quote\Api\Data\CurrencyInterface::class
  41. )->getMockForAbstractClass();
  42. $currencyMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn($expected);
  43. $this->quoteMock->expects($this->once())->method('getCurrency')->willReturn($currencyMock);
  44. $this->assertEquals($expected, $this->model->getCurrencyCode());
  45. }
  46. public function testGetOrderIncrementId()
  47. {
  48. $expected = '1';
  49. $this->quoteMock->expects($this->once())->method('getReservedOrderId')->willReturn($expected);
  50. $this->assertEquals($expected, $this->model->getOrderIncrementId());
  51. }
  52. public function testGetCustomerId()
  53. {
  54. $expected = 1;
  55. /** @var \Magento\Customer\Api\Data\CustomerInterface $customerMock */
  56. $customerMock = $this->getMockBuilder(
  57. \Magento\Customer\Api\Data\CustomerInterface::class
  58. )->getMockForAbstractClass();
  59. $customerMock->expects($this->once())->method('getId')->willReturn($expected);
  60. $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
  61. $this->assertEquals($expected, $this->model->getCustomerId());
  62. }
  63. public function testGetBillingAddressIsNull()
  64. {
  65. $this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(null);
  66. $this->assertSame(null, $this->model->getBillingAddress());
  67. }
  68. public function testGetBillingAddress()
  69. {
  70. /** @var AddressAdapterInterface $addressAdapterMock */
  71. $addressAdapterMock = $this->getMockBuilder(\Magento\Payment\Gateway\Data\AddressAdapterInterface::class)
  72. ->getMockForAbstractClass();
  73. /** @var \Magento\Quote\Api\Data\AddressInterface $quoteAddressMock */
  74. $quoteAddressMock = $this->getMockBuilder(\Magento\Quote\Api\Data\AddressInterface::class)
  75. ->getMockForAbstractClass();
  76. $this->addressAdapterFactoryMock->expects($this->once())
  77. ->method('create')
  78. ->with(['address' => $quoteAddressMock])
  79. ->willReturn($addressAdapterMock);
  80. $this->quoteMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($quoteAddressMock);
  81. $this->assertSame($addressAdapterMock, $this->model->getBillingAddress());
  82. }
  83. public function testGetShippingAddressIsNull()
  84. {
  85. $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn(null);
  86. $this->assertSame(null, $this->model->getShippingAddress());
  87. }
  88. public function testGetShippingAddress()
  89. {
  90. /** @var AddressAdapterInterface $addressAdapterMock */
  91. $addressAdapterMock = $this->getMockBuilder(\Magento\Payment\Gateway\Data\AddressAdapterInterface::class)
  92. ->getMockForAbstractClass();
  93. /** @var \Magento\Quote\Api\Data\AddressInterface $quoteAddressMock */
  94. $quoteAddressMock = $this->getMockBuilder(\Magento\Quote\Api\Data\AddressInterface::class)
  95. ->getMockForAbstractClass();
  96. $this->addressAdapterFactoryMock->expects($this->once())
  97. ->method('create')
  98. ->with(['address' => $quoteAddressMock])
  99. ->willReturn($addressAdapterMock);
  100. $this->quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($quoteAddressMock);
  101. $this->assertSame($addressAdapterMock, $this->model->getShippingAddress());
  102. }
  103. }