SessionTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Model\Auth;
  7. /**
  8. * @magentoAppArea adminhtml
  9. * @magentoAppIsolation enabled
  10. * @magentoDbIsolation enabled
  11. */
  12. class SessionTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Backend\Model\Auth
  16. */
  17. private $auth;
  18. /**
  19. * @var \Magento\Backend\Model\Auth\Session
  20. */
  21. private $authSession;
  22. /**
  23. * @var \Magento\Framework\ObjectManagerInterface
  24. */
  25. private $objectManager;
  26. protected function setUp()
  27. {
  28. parent::setUp();
  29. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  30. $this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class)
  31. ->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
  32. $this->auth = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
  33. $this->authSession = $this->objectManager->create(\Magento\Backend\Model\Auth\Session::class);
  34. $this->auth->setAuthStorage($this->authSession);
  35. $this->auth->logout();
  36. }
  37. protected function tearDown()
  38. {
  39. $this->auth = null;
  40. $this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class)->setCurrentScope(null);
  41. }
  42. /**
  43. * @dataProvider loginDataProvider
  44. */
  45. public function testIsLoggedIn($loggedIn)
  46. {
  47. if ($loggedIn) {
  48. $this->auth->login(
  49. \Magento\TestFramework\Bootstrap::ADMIN_NAME,
  50. \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
  51. );
  52. }
  53. $this->assertEquals($loggedIn, $this->authSession->isLoggedIn());
  54. }
  55. public function loginDataProvider()
  56. {
  57. return [[false], [true]];
  58. }
  59. }