123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Security\Test\Unit\Model\Plugin;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
- /**
- * Test class for \Magento\Security\Model\Plugin\Auth testing
- */
- class AuthTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Security\Model\Plugin\Auth
- */
- protected $model;
- /**
- * @var \Magento\Security\Model\AdminSessionsManager
- */
- protected $sessionsManager;
- /**
- * @var \Magento\Framework\Message\ManagerInterface
- */
- protected $messageManager;
- /**
- * @var \Magento\Security\Model\AdminSessionInfo
- */
- protected $currentSession;
- /**
- * @var \Magento\Backend\Model\Auth
- */
- protected $authMock;
- /**
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
- */
- protected $objectManager;
- /**
- * Init mocks for tests
- * @return void
- */
- public function setUp()
- {
- $this->objectManager = new ObjectManager($this);
- $this->sessionsManager = $this->createPartialMock(
- \Magento\Security\Model\AdminSessionsManager::class,
- ['processLogin', 'processLogout', 'getCurrentSession']
- );
- $this->messageManager = $this->getMockForAbstractClass(
- \Magento\Framework\Message\ManagerInterface::class,
- ['addWarning'],
- '',
- false
- );
- $this->currentSession = $this->createPartialMock(
- \Magento\Security\Model\AdminSessionInfo::class,
- ['isOtherSessionsTerminated']
- );
- $this->authMock = $this->createMock(\Magento\Backend\Model\Auth::class);
- $this->model = $this->objectManager->getObject(
- \Magento\Security\Model\Plugin\Auth::class,
- [
- 'sessionsManager' => $this->sessionsManager,
- 'messageManager' =>$this->messageManager
- ]
- );
- }
- /**
- * @return void
- */
- public function testAfterLogin()
- {
- $warningMessage = __('All other open sessions for this account were terminated.');
- $this->sessionsManager->expects($this->once())
- ->method('processLogin');
- $this->sessionsManager->expects($this->once())
- ->method('getCurrentSession')
- ->willReturn($this->currentSession);
- $this->currentSession->expects($this->once())
- ->method('isOtherSessionsTerminated')
- ->willReturn(true);
- $this->messageManager->expects($this->once())
- ->method('addWarning')
- ->with($warningMessage);
- $this->model->afterLogin($this->authMock);
- }
- /**
- * @return void
- */
- public function testBeforeLogout()
- {
- $this->sessionsManager->expects($this->once())->method('processLogout');
- $this->model->beforeLogout($this->authMock);
- }
- }
|