Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AuthTest Class Reference
Inheritance diagram for AuthTest:

Public Member Functions

 testLoginFailed ($userName, $password)
 
 getLoginDataProvider ()
 
 testSetGetAuthStorage ()
 
 testGetCredentialStorageList ()
 
 testLoginSuccessful ()
 
 testLogout ()
 
 testIsLoggedIn ()
 
 testGetUser ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $_model
 

Detailed Description

Test class for \Magento\Backend\Model\Auth.

@magentoAppArea adminhtml @magentoAppIsolation enabled @magentoDbIsolation enabled

Definition at line 18 of file AuthTest.php.

Member Function Documentation

◆ getLoginDataProvider()

getLoginDataProvider ( )

Definition at line 46 of file AuthTest.php.

47  {
48  return [
49  'Invalid credentials' => ['not_exists', 'not_exists'],
50  'Empty credentials' => ['', 'not_exists']
51  ];
52  }

◆ setUp()

setUp ( )
protected

Definition at line 25 of file AuthTest.php.

26  {
27  parent::setUp();
28 
30  ->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
32  ->create(\Magento\Backend\Model\Auth::class);
33  }

◆ testGetCredentialStorageList()

testGetCredentialStorageList ( )

Definition at line 73 of file AuthTest.php.

74  {
75  $storage = $this->_model->getCredentialStorage();
76  $this->assertInstanceOf(\Magento\Backend\Model\Auth\Credential\StorageInterface::class, $storage);
77  }

◆ testGetUser()

testGetUser ( )

Definition at line 132 of file AuthTest.php.

133  {
134  $this->_model->login(
135  \Magento\TestFramework\Bootstrap::ADMIN_NAME,
136  \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
137  );
138 
139  $this->assertNotNull($this->_model->getUser());
140  $this->assertGreaterThan(0, $this->_model->getUser()->getId());
141  $this->assertInstanceOf(
142  \Magento\Backend\Model\Auth\Credential\StorageInterface::class,
143  $this->_model->getUser()
144  );
145  }

◆ testIsLoggedIn()

testIsLoggedIn ( )

Disabled form security in order to prevent exit from the app @magentoAdminConfigFixture admin/security/session_lifetime 100

Definition at line 123 of file AuthTest.php.

124  {
125  $this->_model->login(
126  \Magento\TestFramework\Bootstrap::ADMIN_NAME,
127  \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
128  );
129  $this->assertTrue($this->_model->isLoggedIn());
130  }

◆ testLoginFailed()

testLoginFailed (   $userName,
  $password 
)

@dataProvider getLoginDataProvider

Parameters
string$userName
string$password@expectedException \Magento\Framework\Exception\AuthenticationException

Definition at line 41 of file AuthTest.php.

42  {
43  $this->_model->login($userName, $password);
44  }

◆ testLoginSuccessful()

testLoginSuccessful ( )

Definition at line 79 of file AuthTest.php.

80  {
81  $this->_model->login(
82  \Magento\TestFramework\Bootstrap::ADMIN_NAME,
83  \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
84  );
85  $this->assertInstanceOf(
86  \Magento\Backend\Model\Auth\Credential\StorageInterface::class,
87  $this->_model->getUser()
88  );
89  $this->assertGreaterThan(time() - 10, $this->_model->getAuthStorage()->getUpdatedAt());
90  }

◆ testLogout()

testLogout ( )

@magentoAppIsolation enabled

Definition at line 108 of file AuthTest.php.

109  {
110  $this->_model->login(
111  \Magento\TestFramework\Bootstrap::ADMIN_NAME,
112  \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
113  );
114  $this->assertNotEmpty($this->_model->getAuthStorage()->getData());
115  $this->_model->logout();
116  $this->assertEmpty($this->_model->getAuthStorage()->getData());
117  }

◆ testSetGetAuthStorage()

testSetGetAuthStorage ( )

Definition at line 54 of file AuthTest.php.

55  {
56  // by default \Magento\Backend\Model\Auth\Session class will instantiate as a Authentication Storage
57  $this->assertInstanceOf(\Magento\Backend\Model\Auth\Session::class, $this->_model->getAuthStorage());
58 
59  $mockStorage = $this->createMock(\Magento\Backend\Model\Auth\StorageInterface::class);
60  $this->_model->setAuthStorage($mockStorage);
61  $this->assertInstanceOf(\Magento\Backend\Model\Auth\StorageInterface::class, $this->_model->getAuthStorage());
62 
63  $incorrectStorage = new \StdClass();
64  try {
65  $this->_model->setAuthStorage($incorrectStorage);
66  $this->fail('Incorrect authentication storage setted.');
67  } catch (AuthenticationException $e) {
68  // in case of exception - Auth works correct
69  $this->assertNotEmpty($e->getMessage());
70  }
71  }

Field Documentation

◆ $_model

$_model
protected

Definition at line 23 of file AuthTest.php.


The documentation for this class was generated from the following file: