_objectManager->get('Magento\Backend\Model\UrlInterface')->turnOffSecretKey(); $this->_auth = $this->_objectManager->get('Magento\Backend\Model\Auth'); $this->_session = $this->_auth->getAuthStorage(); $credentials = $this->_getAdminCredentials(); $this->_auth->login($credentials['user'], $credentials['password']); $this->_objectManager->get('Magento\Security\Model\Plugin\Auth')->afterLogin($this->_auth); } /** * Get credentials to login admin user * * @return array */ protected function _getAdminCredentials() { return [ 'user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, 'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD ]; } protected function tearDown() { $this->_auth->getAuthStorage()->destroy(['send_expire_cookie' => false]); $this->_auth = null; $this->_session = null; $this->_objectManager->get('Magento\Backend\Model\UrlInterface')->turnOnSecretKey(); parent::tearDown(); } /** * Utilize backend session model by default * * @param \PHPUnit_Framework_Constraint $constraint * @param string|null $messageType * @param string $messageManagerClass */ public function assertSessionMessages( \PHPUnit_Framework_Constraint $constraint, $messageType = null, $messageManagerClass = 'Magento\Framework\Message\Manager' ) { parent::assertSessionMessages($constraint, $messageType, $messageManagerClass); } public function testAclHasAccess() { if ($this->uri === null) { $this->markTestIncomplete('AclHasAccess test is not complete'); } $this->dispatch($this->uri); $this->assertNotSame(403, $this->getResponse()->getHttpResponseCode()); $this->assertNotSame(404, $this->getResponse()->getHttpResponseCode()); } public function testAclNoAccess() { if ($this->resource === null) { $this->markTestIncomplete('Acl test is not complete'); } $this->_objectManager->get('Magento\Framework\Acl\Builder') ->getAcl() ->deny(null, $this->resource); $this->dispatch($this->uri); $this->assertSame(403, $this->getResponse()->getHttpResponseCode()); } }