IframeTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\Block\Payflow\Link;
  7. /**
  8. * Test for Iframe block
  9. *
  10. */
  11. class IframeTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $contextMock;
  17. /**
  18. * @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $checkoutSessionMock;
  21. /**
  22. * @var \Magento\Sales\Model\OrderFactory|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $orderFactoryMock;
  25. /**
  26. * @var \Magento\Paypal\Helper\Hss|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $hssHelperMock;
  29. /**
  30. * @var \Magento\Payment\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $paymentDataMock;
  33. /**
  34. * @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $quoteMock;
  37. /**
  38. * @var \Magento\Quote\Model\Quote\Payment|\PHPUnit_Framework_MockObject_MockObject
  39. */
  40. protected $paymentMock;
  41. /**
  42. * @var \Magento\Framework\Module\Dir\Reader|\PHPUnit_Framework_MockObject_MockObject
  43. */
  44. protected $reader;
  45. /**
  46. * @var \Magento\Framework\Filesystem\Directory\ReadFactory|\PHPUnit_Framework_MockObject_MockObject
  47. */
  48. protected $readFactory;
  49. public function prepare()
  50. {
  51. $this->contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  52. $this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);
  53. $this->orderFactoryMock = $this->createPartialMock(\Magento\Sales\Model\OrderFactory::class, ['getQuote']);
  54. $this->hssHelperMock = $this->createMock(\Magento\Paypal\Helper\Hss::class);
  55. $this->paymentDataMock = $this->createMock(\Magento\Payment\Helper\Data::class);
  56. $this->quoteMock = $this->createPartialMock(\Magento\Quote\Model\Quote::class, ['getPayment', '__wakeup']);
  57. $this->paymentMock = $this->createMock(\Magento\Quote\Model\Quote\Payment::class);
  58. $this->reader = $this->createMock(\Magento\Framework\Module\Dir\Reader::class);
  59. $this->readFactory = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadFactory::class);
  60. $this->checkoutSessionMock->expects($this->any())
  61. ->method('getQuote')
  62. ->will($this->returnValue($this->quoteMock));
  63. $this->quoteMock->expects($this->any())
  64. ->method('getPayment')
  65. ->will($this->returnValue($this->paymentMock));
  66. $this->hssHelperMock->expects($this->any())
  67. ->method('getHssMethods')
  68. ->will($this->returnValue([]));
  69. }
  70. /**
  71. * Check that isScopePrivate is false
  72. */
  73. public function testCheckIsScopePrivate()
  74. {
  75. $this->prepare();
  76. $block = new \Magento\Paypal\Block\Payflow\Advanced\Iframe(
  77. $this->contextMock,
  78. $this->orderFactoryMock,
  79. $this->checkoutSessionMock,
  80. $this->hssHelperMock,
  81. $this->readFactory,
  82. $this->reader,
  83. $this->paymentDataMock
  84. );
  85. $this->assertFalse($block->isScopePrivate());
  86. }
  87. public function testGetTransactionUrlLive()
  88. {
  89. $this->prepare();
  90. $expected = 'https://live.url';
  91. $methodInstance = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
  92. ->getMockForAbstractClass();
  93. $methodInstance->expects($this->exactly(2))
  94. ->method('getConfigData')
  95. ->willReturnMap([
  96. ['sandbox_flag', null, false],
  97. ['cgi_url', null, $expected]
  98. ]);
  99. $this->paymentDataMock->expects($this->exactly(2))
  100. ->method('getMethodInstance')
  101. ->willReturn($methodInstance);
  102. $block = new \Magento\Paypal\Block\Payflow\Link\Iframe(
  103. $this->contextMock,
  104. $this->orderFactoryMock,
  105. $this->checkoutSessionMock,
  106. $this->hssHelperMock,
  107. $this->readFactory,
  108. $this->reader,
  109. $this->paymentDataMock
  110. );
  111. $this->assertEquals($expected, $block->getTransactionUrl());
  112. }
  113. public function testGetTransactionUrlTest()
  114. {
  115. $this->prepare();
  116. $expected = 'https://test.url';
  117. $methodInstance = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
  118. ->getMockForAbstractClass();
  119. $methodInstance->expects($this->exactly(2))
  120. ->method('getConfigData')
  121. ->willReturnMap([
  122. ['sandbox_flag', null, true],
  123. ['cgi_url_test_mode', null, $expected]
  124. ]);
  125. $this->paymentDataMock->expects($this->exactly(2))
  126. ->method('getMethodInstance')
  127. ->willReturn($methodInstance);
  128. $block = new \Magento\Paypal\Block\Payflow\Link\Iframe(
  129. $this->contextMock,
  130. $this->orderFactoryMock,
  131. $this->checkoutSessionMock,
  132. $this->hssHelperMock,
  133. $this->readFactory,
  134. $this->reader,
  135. $this->paymentDataMock
  136. );
  137. $this->assertEquals($expected, $block->getTransactionUrl());
  138. }
  139. }