SuccessTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Block\Onepage;
  7. use Magento\Sales\Model\Order;
  8. /**
  9. * Class SuccessTest
  10. * @package Magento\Checkout\Block\Onepage
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. class SuccessTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var \Magento\Checkout\Block\Onepage\Success
  17. */
  18. protected $block;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $layout;
  23. /**
  24. * @var \Magento\Sales\Model\Order\Config | \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $orderConfig;
  27. /**
  28. * @var \Magento\Checkout\Model\Session | \PHPUnit_Framework_MockObject_MockObject
  29. */
  30. protected $checkoutSession;
  31. /**
  32. * @var \PHPUnit_Framework_MockObject_MockObject
  33. */
  34. protected $storeManagerMock;
  35. protected function setUp()
  36. {
  37. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  38. $this->orderConfig = $this->createMock(\Magento\Sales\Model\Order\Config::class);
  39. $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  40. $this->layout = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
  41. ->disableOriginalConstructor()
  42. ->setMethods([])
  43. ->getMock();
  44. $this->checkoutSession = $this->getMockBuilder(\Magento\Checkout\Model\Session::class)
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $eventManager = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
  48. ->disableOriginalConstructor()
  49. ->setMethods([])
  50. ->getMock();
  51. $urlBuilder = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
  52. ->disableOriginalConstructor()
  53. ->setMethods([])
  54. ->getMock();
  55. $scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
  56. ->disableOriginalConstructor()
  57. ->setMethods([])
  58. ->getMock();
  59. $scopeConfig->expects($this->any())
  60. ->method('getValue')
  61. ->with(
  62. $this->stringContains(
  63. 'advanced/modules_disable_output/'
  64. ),
  65. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  66. )
  67. ->will($this->returnValue(false));
  68. $context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
  69. ->disableOriginalConstructor()
  70. ->setMethods(['getLayout', 'getEventManager', 'getUrlBuilder', 'getScopeConfig', 'getStoreManager'])
  71. ->getMock();
  72. $context->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
  73. $context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
  74. $context->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilder));
  75. $context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($scopeConfig));
  76. $context->expects($this->any())->method('getStoreManager')->will($this->returnValue($this->storeManagerMock));
  77. $this->block = $objectManager->getObject(
  78. \Magento\Checkout\Block\Onepage\Success::class,
  79. [
  80. 'context' => $context,
  81. 'orderConfig' => $this->orderConfig,
  82. 'checkoutSession' => $this->checkoutSession
  83. ]
  84. );
  85. }
  86. public function testGetAdditionalInfoHtml()
  87. {
  88. $layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
  89. $layout->expects(
  90. $this->once()
  91. )->method(
  92. 'renderElement'
  93. )->with(
  94. 'order.success.additional.info'
  95. )->will(
  96. $this->returnValue('AdditionalInfoHtml')
  97. );
  98. $this->block->setLayout($layout);
  99. $this->assertEquals('AdditionalInfoHtml', $this->block->getAdditionalInfoHtml());
  100. }
  101. /**
  102. * @dataProvider invisibleStatusesProvider
  103. *
  104. * @param array $invisibleStatuses
  105. * @param bool $expectedResult
  106. */
  107. public function testToHtmlOrderVisibleOnFront(array $invisibleStatuses, $expectedResult)
  108. {
  109. $orderId = 5;
  110. $realOrderId = 100003332;
  111. $status = Order::STATE_PENDING_PAYMENT;
  112. $order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
  113. ->disableOriginalConstructor()
  114. ->getMock();
  115. $this->checkoutSession->expects($this->once())
  116. ->method('getLastRealOrder')
  117. ->willReturn($order);
  118. $order->expects($this->atLeastOnce())
  119. ->method('getEntityId')
  120. ->willReturn($orderId);
  121. $order->expects($this->atLeastOnce())
  122. ->method('getIncrementId')
  123. ->willReturn($realOrderId);
  124. $order->expects($this->atLeastOnce())
  125. ->method('getStatus')
  126. ->willReturn($status);
  127. $this->orderConfig->expects($this->any())
  128. ->method('getInvisibleOnFrontStatuses')
  129. ->willReturn($invisibleStatuses);
  130. $this->block->toHtml();
  131. $this->assertEquals($expectedResult, $this->block->getIsOrderVisible());
  132. }
  133. /**
  134. * @return array
  135. */
  136. public function invisibleStatusesProvider()
  137. {
  138. return [
  139. [[Order::STATE_PENDING_PAYMENT, 'status2'], false],
  140. [['status1', 'status2'], true]
  141. ];
  142. }
  143. public function testGetContinueUrl()
  144. {
  145. $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
  146. $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
  147. $storeMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('Expected Result'));
  148. $this->assertEquals('Expected Result', $this->block->getContinueUrl());
  149. }
  150. }