Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Adminhtml.php
Go to the documentation of this file.
1 <?php
13 
18 class Adminhtml extends \PHPUnit\Framework\TestCase
19 {
23  protected $_designMock;
24 
28  protected $_sessionMock;
29 
33  protected $_sidResolver;
34 
38  protected $_translatorMock;
39 
43  protected $_layoutMock;
44 
48  protected $_requestMock;
49 
53  protected $_messagesMock;
54 
58  protected $_urlMock;
59 
63  protected $_eventManagerMock;
64 
68  protected $_controllerMock;
69 
73  protected $_context;
74 
78  protected $_loggerMock;
79 
83  protected $_filesystemMock;
84 
88  protected $_cacheMock;
89 
93  protected $_scopeConfigMock;
94 
98  protected $_storeManagerMock;
99 
103  protected $_mathMock;
104 
108  protected $_formKey;
109 
112  protected function setUp()
113  {
114  // These mocks are accessed via context
115  $this->_designMock = $this->_makeMock(\Magento\Framework\View\DesignInterface::class);
116  $this->_sessionMock = $this->_makeMock(\Magento\Framework\Session\Generic::class);
117  $this->_sidResolver = $this->_makeMock(\Magento\Framework\Session\SidResolver::class);
118  $this->_translatorMock = $this->_makeMock(\Magento\Framework\TranslateInterface::class);
119  $this->_layoutMock = $this->_makeMock(\Magento\Framework\View\Layout::class);
120  $this->_requestMock = $this->_makeMock(\Magento\Framework\App\RequestInterface::class);
121  $this->_messagesMock = $this->_makeMock(\Magento\Framework\View\Element\Messages::class);
122  $this->_urlMock = $this->_makeMock(\Magento\Framework\UrlInterface::class);
123  $this->_eventManagerMock = $this->_makeMock(\Magento\Framework\Event\ManagerInterface::class);
124  $this->_controllerMock = $this->_makeMock(\Magento\Framework\App\FrontController::class);
125  $this->_loggerMock = $this->_makeMock(\Psr\Log\LoggerInterface::class);
126  $this->_filesystemMock = $this->_makeMock(\Magento\Framework\Filesystem::class);
127  $this->_cacheMock = $this->_makeMock(\Magento\Framework\App\CacheInterface::class);
128  $this->_scopeConfigMock = $this->_makeMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
129  $this->_storeManagerMock = $this->_makeMock(\Magento\Store\Model\StoreManager::class);
130  $assetRepoMock = $this->_makeMock(\Magento\Framework\View\Asset\Repository::class);
131  $viewConfigMock = $this->_makeMock(\Magento\Framework\View\ConfigInterface::class);
132  $viewFileSystemMock = $this->_makeMock(\Magento\Framework\View\FileSystem::class);
133  $templatePoolMock = $this->_makeMock(\Magento\Framework\View\TemplateEnginePool::class);
134  $authorizationMock = $this->_makeMock(\Magento\Framework\AuthorizationInterface::class);
135  $cacheStateMock = $this->_makeMock(\Magento\Framework\App\Cache\StateInterface::class);
136  $escaperMock = $this->_makeMock(\Magento\Framework\Escaper::class);
137  $filterManagerMock = $this->_makeMock(\Magento\Framework\Filter\FilterManager::class);
138  $backendSessionMock = $this->_makeMock(\Magento\Backend\Model\Session::class);
139  $appState = $this->_makeMock(\Magento\Framework\App\State::class);
140  $this->_mathMock = $this->_makeMock(\Magento\Framework\Math\Random::class);
141  $this->_formKey = $this->_makeMock(\Magento\Framework\Data\Form\FormKey::class);
142 
143  $appState->setAreaCode(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
144 
145  $this->_translatorMock->expects(
146  $this->any()
147  )->method(
148  'translate'
149  )->will(
150  $this->returnCallback([$this, 'translateCallback'])
151  );
152 
153  $this->_context = new \Magento\Backend\Block\Template\Context(
154  $this->_requestMock,
155  $this->_layoutMock,
156  $this->_eventManagerMock,
157  $this->_urlMock,
158  $this->_translatorMock,
159  $this->_cacheMock,
160  $this->_designMock,
161  $this->_sessionMock,
162  $this->_sidResolver,
163  $this->_scopeConfigMock,
164  $this->_controllerMock,
165  $assetRepoMock,
166  $viewConfigMock,
167  $cacheStateMock,
168  $this->_loggerMock,
169  $escaperMock,
170  $filterManagerMock,
171  $this->_filesystemMock,
172  $viewFileSystemMock,
173  $templatePoolMock,
174  $appState,
175  $this->_storeManagerMock,
176  $authorizationMock,
177  $backendSessionMock,
178  $this->_mathMock,
179  $this->_formKey
180  );
181  }
182 
189  protected function _makeMock($className)
190  {
191  return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
192  }
193 
204  protected function _setStub(
205  \PHPUnit_Framework_MockObject_MockObject $object,
206  $stubName,
207  $return = null,
208  $expects = null
209  ) {
210  $expects = isset($expects) ? $expects : $this->any();
211  $return = isset($return) ? $this->returnValue($return) : $this->returnSelf();
212 
213  return $object->expects($expects)->method($stubName)->will($return);
214  }
215 
222  public function translateCallback($args)
223  {
224  return $args[0]->getText();
225  }
226 }
_setStub(\PHPUnit_Framework_MockObject_MockObject $object, $stubName, $return=null, $expects=null)
Definition: Adminhtml.php:204
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31