13 class AuthTest extends \PHPUnit\Framework\TestCase
37 $this->_eventManagerMock = $this->createMock(\
Magento\Framework\Event\ManagerInterface::class);
38 $this->_credentialStorage = $this->getMockBuilder(
39 \
Magento\Backend\Model\Auth\Credential\StorageInterface::class
41 ->setMethods([
'getId'])
42 ->getMockForAbstractClass();
43 $this->_modelFactoryMock = $this->createMock(\
Magento\Framework\Data\Collection\ModelFactory::class);
46 \
Magento\Backend\Model\Auth::class,
48 'eventManager' => $this->_eventManagerMock,
49 'credentialStorage' => $this->_credentialStorage,
50 'modelFactory' => $this->_modelFactoryMock
60 $this->_modelFactoryMock
61 ->expects($this->once())
63 ->with(\
Magento\Backend\Model\Auth\Credential\StorageInterface::class)
64 ->will($this->returnValue($this->_credentialStorage));
65 $exceptionMock = new \Magento\Framework\Exception\LocalizedException(
67 'The account sign-in was incorrect or your account is disabled temporarily. ' 68 .
'Please wait and try again later.' 71 $this->_credentialStorage
72 ->expects($this->once())
74 ->with(
'username',
'password')
75 ->will($this->throwException($exceptionMock));
76 $this->_credentialStorage->expects($this->never())->method(
'getId');
77 $this->_eventManagerMock->expects($this->once())->method(
'dispatch')->with(
'backend_auth_user_login_failed');
78 $this->_model->login(
'username',
'password');
80 $this->expectExceptionMessage(
81 'The account sign-in was incorrect or your account is disabled temporarily. ' 82 .
'Please wait and try again later.'