Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubstitutionTest.php
Go to the documentation of this file.
1 <?php
8 
12 class SubstitutionTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $layout;
18 
22  protected $block;
23 
27  protected $objectManager;
28 
32  protected function setUp()
33  {
34  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
35 
36  $this->layout = $this->getMockBuilder(
37  \Magento\Framework\View\LayoutInterface::class
38  )->disableOriginalConstructor()->setMethods(
39  []
40  )->getMock();
41 
42  $eventManager = $this->getMockBuilder(
43  \Magento\Framework\Event\ManagerInterface::class
44  )->disableOriginalConstructor()->setMethods(
45  []
46  )->getMock();
47 
48  $scopeConfig = $this->getMockBuilder(
49  \Magento\Framework\App\Config\ScopeConfigInterface::class
50  )->disableOriginalConstructor()->setMethods(
51  []
52  )->getMock();
53  $scopeConfig->expects(
54  $this->any()
55  )->method(
56  'getValue'
57  )->with(
58  $this->stringContains(
59  'advanced/modules_disable_output/'
60  ),
61  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
62  )->will(
63  $this->returnValue(
64  false
65  )
66  );
67 
68  $context = $this->getMockBuilder(
69  \Magento\Framework\View\Element\Template\Context::class
70  )->disableOriginalConstructor()->setMethods(
71  ['getLayout', 'getEventManager', 'getScopeConfig']
72  )->getMock();
73  $context->expects(
74  $this->any()
75  )->method(
76  'getLayout'
77  )->will(
78  $this->returnValue(
79  $this->layout
80  )
81  );
82  $context->expects(
83  $this->any()
84  )->method(
85  'getEventManager'
86  )->will(
87  $this->returnValue(
88  $eventManager
89  )
90  );
91  $context->expects(
92  $this->any()
93  )->method(
94  'getScopeConfig'
95  )->will(
96  $this->returnValue(
97  $scopeConfig
98  )
99  );
100 
101  $this->block = $this->objectManager->getObject(
102  \Magento\Payment\Block\Info\Substitution::class,
103  [
104  'context' => $context,
105  'data' => [
106  'template' => null,
107  ]
108  ]
109  );
110  }
111 
112  public function testBeforeToHtml()
113  {
114  $abstractBlock = $this->getMockBuilder(
115  \Magento\Framework\View\Element\AbstractBlock::class
116  )->disableOriginalConstructor()->setMethods(
117  []
118  )->getMock();
119  $childAbstractBlock = clone($abstractBlock);
120 
121  $abstractBlock->expects($this->any())->method('getParentBlock')->will($this->returnValue($childAbstractBlock));
122 
123  $this->layout->expects($this->any())->method('getParentName')->will($this->returnValue('parentName'));
124  $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($abstractBlock));
125 
126  $infoMock = $this->getMockBuilder(
127  \Magento\Payment\Model\Info::class
128  )->disableOriginalConstructor()->setMethods(
129  []
130  )->getMock();
131  $methodMock = $this->getMockBuilder(
132  \Magento\Payment\Model\MethodInterface::class
133  )->getMockForAbstractClass();
134  $infoMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodMock));
135  $this->block->setInfo($infoMock);
136 
137  $fakeBlock = new \StdClass();
138  $this->layout->expects(
139  $this->any()
140  )->method(
141  'createBlock'
142  )->with(
143  \Magento\Framework\View\Element\Template::class,
144  '',
145  ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']]
146  )->will($this->returnValue($fakeBlock));
147 
148  $childAbstractBlock->expects(
149  $this->any()
150  )->method(
151  'setChild'
152  )->with(
153  'order_payment_additional',
154  $fakeBlock
155  );
156 
157  $this->block->toHtml();
158  }
159 }