Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractBackendController.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Request\Http as HttpRequest;
9 
16 {
20  protected $_session;
21 
25  protected $_auth;
26 
32  protected $resource = null;
33 
39  protected $uri = null;
40 
44  protected $httpMethod;
45 
51  protected function setUp()
52  {
53  parent::setUp();
54 
55  $this->_objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
56 
57  $this->_auth = $this->_objectManager->get(\Magento\Backend\Model\Auth::class);
58  $this->_session = $this->_auth->getAuthStorage();
59  $credentials = $this->_getAdminCredentials();
60  $this->_auth->login($credentials['user'], $credentials['password']);
61  $this->_objectManager->get(\Magento\Security\Model\Plugin\Auth::class)->afterLogin($this->_auth);
62  }
63 
69  protected function _getAdminCredentials()
70  {
71  return [
74  ];
75  }
76 
80  protected function tearDown()
81  {
82  $this->_auth->getAuthStorage()->destroy(['send_expire_cookie' => false]);
83  $this->_auth = null;
84  $this->_session = null;
85  $this->_objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOnSecretKey();
86  parent::tearDown();
87  }
88 
96  public function assertSessionMessages(
97  \PHPUnit\Framework\Constraint\Constraint $constraint,
98  $messageType = null,
99  $messageManagerClass = \Magento\Framework\Message\Manager::class
100  ) {
101  parent::assertSessionMessages($constraint, $messageType, $messageManagerClass);
102  }
103 
107  public function testAclHasAccess()
108  {
109  if ($this->uri === null) {
110  $this->markTestIncomplete('AclHasAccess test is not complete');
111  }
112  if ($this->httpMethod) {
113  $this->getRequest()->setMethod($this->httpMethod);
114  }
115  $this->dispatch($this->uri);
116  $this->assertNotSame(403, $this->getResponse()->getHttpResponseCode());
117  $this->assertNotSame(404, $this->getResponse()->getHttpResponseCode());
118  }
119 
123  public function testAclNoAccess()
124  {
125  if ($this->resource === null) {
126  $this->markTestIncomplete('Acl test is not complete');
127  }
128  if ($this->httpMethod) {
129  $this->getRequest()->setMethod($this->httpMethod);
130  }
131  $this->_objectManager->get(\Magento\Framework\Acl\Builder::class)
132  ->getAcl()
133  ->deny(null, $this->resource);
134  $this->dispatch($this->uri);
135  $this->assertSame(403, $this->getResponse()->getHttpResponseCode());
136  }
137 }
assertSessionMessages(\PHPUnit\Framework\Constraint\Constraint $constraint, $messageType=null, $messageManagerClass=\Magento\Framework\Message\Manager::class)