SubstitutionTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Block\Info;
  7. /**
  8. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  9. */
  10. class SubstitutionTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $layout;
  16. /**
  17. * @var \Magento\Payment\Block\Info\Substitution
  18. */
  19. protected $block;
  20. /**
  21. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  22. */
  23. protected $objectManager;
  24. /**
  25. * @inheritdoc
  26. */
  27. protected function setUp()
  28. {
  29. $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  30. $this->layout = $this->getMockBuilder(
  31. \Magento\Framework\View\LayoutInterface::class
  32. )->disableOriginalConstructor()->setMethods(
  33. []
  34. )->getMock();
  35. $eventManager = $this->getMockBuilder(
  36. \Magento\Framework\Event\ManagerInterface::class
  37. )->disableOriginalConstructor()->setMethods(
  38. []
  39. )->getMock();
  40. $scopeConfig = $this->getMockBuilder(
  41. \Magento\Framework\App\Config\ScopeConfigInterface::class
  42. )->disableOriginalConstructor()->setMethods(
  43. []
  44. )->getMock();
  45. $scopeConfig->expects(
  46. $this->any()
  47. )->method(
  48. 'getValue'
  49. )->with(
  50. $this->stringContains(
  51. 'advanced/modules_disable_output/'
  52. ),
  53. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  54. )->will(
  55. $this->returnValue(
  56. false
  57. )
  58. );
  59. $context = $this->getMockBuilder(
  60. \Magento\Framework\View\Element\Template\Context::class
  61. )->disableOriginalConstructor()->setMethods(
  62. ['getLayout', 'getEventManager', 'getScopeConfig']
  63. )->getMock();
  64. $context->expects(
  65. $this->any()
  66. )->method(
  67. 'getLayout'
  68. )->will(
  69. $this->returnValue(
  70. $this->layout
  71. )
  72. );
  73. $context->expects(
  74. $this->any()
  75. )->method(
  76. 'getEventManager'
  77. )->will(
  78. $this->returnValue(
  79. $eventManager
  80. )
  81. );
  82. $context->expects(
  83. $this->any()
  84. )->method(
  85. 'getScopeConfig'
  86. )->will(
  87. $this->returnValue(
  88. $scopeConfig
  89. )
  90. );
  91. $this->block = $this->objectManager->getObject(
  92. \Magento\Payment\Block\Info\Substitution::class,
  93. [
  94. 'context' => $context,
  95. 'data' => [
  96. 'template' => null,
  97. ]
  98. ]
  99. );
  100. }
  101. public function testBeforeToHtml()
  102. {
  103. $abstractBlock = $this->getMockBuilder(
  104. \Magento\Framework\View\Element\AbstractBlock::class
  105. )->disableOriginalConstructor()->setMethods(
  106. []
  107. )->getMock();
  108. $childAbstractBlock = clone($abstractBlock);
  109. $abstractBlock->expects($this->any())->method('getParentBlock')->will($this->returnValue($childAbstractBlock));
  110. $this->layout->expects($this->any())->method('getParentName')->will($this->returnValue('parentName'));
  111. $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($abstractBlock));
  112. $infoMock = $this->getMockBuilder(
  113. \Magento\Payment\Model\Info::class
  114. )->disableOriginalConstructor()->setMethods(
  115. []
  116. )->getMock();
  117. $methodMock = $this->getMockBuilder(
  118. \Magento\Payment\Model\MethodInterface::class
  119. )->getMockForAbstractClass();
  120. $infoMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodMock));
  121. $this->block->setInfo($infoMock);
  122. $fakeBlock = new \StdClass();
  123. $this->layout->expects(
  124. $this->any()
  125. )->method(
  126. 'createBlock'
  127. )->with(
  128. \Magento\Framework\View\Element\Template::class,
  129. '',
  130. ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']]
  131. )->will($this->returnValue($fakeBlock));
  132. $childAbstractBlock->expects(
  133. $this->any()
  134. )->method(
  135. 'setChild'
  136. )->with(
  137. 'order_payment_additional',
  138. $fakeBlock
  139. );
  140. $this->block->toHtml();
  141. }
  142. }