ToOrderPaymentTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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\Quote\Payment;
  7. use Magento\Payment\Model\Method\Substitution;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. /**
  10. * Class ToOrderPaymentTest tests converter to order payment
  11. */
  12. class ToOrderPaymentTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Sales\Api\OrderPaymentRepositoryInterface | \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $orderPaymentRepositoryMock;
  18. /**
  19. * @var \Magento\Framework\DataObject\Copy | \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $objectCopyMock;
  22. /**
  23. * @var \Magento\Quote\Model\Quote\Payment | \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $paymentMock;
  26. /**
  27. * @var \Magento\Framework\Api\DataObjectHelper
  28. */
  29. protected $dataObjectHelper;
  30. /**
  31. * @var \Magento\Quote\Model\Quote\Payment\ToOrderPayment
  32. */
  33. protected $converter;
  34. protected function setUp()
  35. {
  36. $this->paymentMock = $this->createPartialMock(
  37. \Magento\Quote\Model\Quote\Payment::class,
  38. ['getCcNumber', 'getCcCid', 'getMethodInstance', 'getAdditionalInformation']
  39. );
  40. $this->objectCopyMock = $this->createMock(\Magento\Framework\DataObject\Copy::class);
  41. $this->orderPaymentRepositoryMock = $this->getMockForAbstractClass(
  42. \Magento\Sales\Api\OrderPaymentRepositoryInterface::class,
  43. [],
  44. '',
  45. false,
  46. false
  47. );
  48. $this->dataObjectHelper = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class);
  49. $objectManager = new ObjectManager($this);
  50. $this->converter = $objectManager->getObject(
  51. \Magento\Quote\Model\Quote\Payment\ToOrderPayment::class,
  52. [
  53. 'orderPaymentRepository' => $this->orderPaymentRepositoryMock,
  54. 'objectCopyService' => $this->objectCopyMock,
  55. 'dataObjectHelper' => $this->dataObjectHelper
  56. ]
  57. );
  58. }
  59. /**
  60. * Tests Convert method in payment to order payment converter
  61. */
  62. public function testConvert()
  63. {
  64. $methodInterface = $this->getMockForAbstractClass(\Magento\Payment\Model\MethodInterface::class);
  65. $paymentData = ['test' => 'test2'];
  66. $data = ['some_id' => 1];
  67. $paymentMethodTitle = 'TestTitle';
  68. $additionalInfo = ['token' => 'TOKEN-123'];
  69. $this->paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInterface);
  70. $methodInterface->expects($this->once())->method('getTitle')->willReturn($paymentMethodTitle);
  71. $this->objectCopyMock->expects($this->once())->method('getDataFromFieldset')->with(
  72. 'quote_convert_payment',
  73. 'to_order_payment',
  74. $this->paymentMock
  75. )->willReturn($paymentData);
  76. $this->paymentMock->expects($this->once())
  77. ->method('getAdditionalInformation')
  78. ->willReturn($additionalInfo);
  79. $ccNumber = 123456798;
  80. $ccCid = 1234;
  81. $this->paymentMock->expects($this->once())
  82. ->method('getCcNumber')
  83. ->willReturn($ccNumber);
  84. $this->paymentMock->expects($this->once())
  85. ->method('getCcCid')
  86. ->willReturn($ccCid);
  87. $orderPayment = $this->getMockForAbstractClass(
  88. \Magento\Sales\Api\Data\OrderPaymentInterface::class,
  89. [],
  90. '',
  91. false,
  92. true,
  93. true,
  94. ['setCcNumber', 'setCcCid', 'setAdditionalInformation']
  95. );
  96. $orderPayment->expects($this->once())
  97. ->method('setAdditionalInformation')
  98. ->with(array_merge($additionalInfo, [Substitution::INFO_KEY_TITLE => $paymentMethodTitle]))
  99. ->willReturnSelf();
  100. $orderPayment->expects($this->once())
  101. ->method('setCcNumber')
  102. ->willReturnSelf();
  103. $orderPayment->expects($this->once())
  104. ->method('setCcCid')
  105. ->willReturnSelf();
  106. $this->orderPaymentRepositoryMock->expects($this->once())->method('create')->willReturn($orderPayment);
  107. $this->dataObjectHelper->expects($this->once())
  108. ->method('populateWithArray')
  109. ->with(
  110. $orderPayment,
  111. array_merge($paymentData, $data),
  112. \Magento\Sales\Api\Data\OrderPaymentInterface::class
  113. )
  114. ->willReturnSelf();
  115. $this->assertSame($orderPayment, $this->converter->convert($this->paymentMock, $data));
  116. }
  117. }