AbstractActionTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\App;
  7. /**
  8. * Test class for \Magento\Backend\App\AbstractAction.
  9. * @magentoAppArea adminhtml
  10. */
  11. class AbstractActionTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  12. {
  13. /**
  14. * Check redirection to startup page for logged user
  15. * @magentoConfigFixture current_store admin/security/use_form_key 1
  16. * @magentoAppIsolation enabled
  17. */
  18. public function testPreDispatchWithEmptyUrlRedirectsToStartupPage()
  19. {
  20. $this->markTestSkipped('Session destruction doesn\'t work');
  21. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  22. \Magento\Framework\Config\ScopeInterface::class
  23. )->setCurrentScope(
  24. \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
  25. );
  26. $this->dispatch('backend');
  27. /** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
  28. $backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  29. \Magento\Backend\Model\UrlInterface::class
  30. );
  31. $url = $backendUrlModel->getStartupPageUrl();
  32. $expected = $backendUrlModel->getUrl($url);
  33. $this->assertRedirect($this->stringStartsWith($expected));
  34. }
  35. /**
  36. * Check login redirection
  37. *
  38. * @magentoDbIsolation enabled
  39. */
  40. public function testInitAuthentication()
  41. {
  42. /**
  43. * Logout current session
  44. */
  45. $this->_auth->logout();
  46. /** @var \Magento\Framework\Data\Form\FormKey $formKey */
  47. $formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
  48. $postLogin = [
  49. 'login' => [
  50. 'username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
  51. 'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
  52. ],
  53. 'form_key' => $formKey->getFormKey(),
  54. ];
  55. $this->getRequest()->setPostValue($postLogin);
  56. $this->dispatch('backend/admin/system_account/index');
  57. $expected = 'backend/admin/system_account/index';
  58. $this->assertRedirect($this->stringContains($expected));
  59. }
  60. /**
  61. * Check layout attribute "acl" for check access to
  62. *
  63. * @param string $blockName
  64. * @param string $resource
  65. * @param bool $isLimitedAccess
  66. * @dataProvider nodesWithAcl
  67. */
  68. public function testAclInNodes($blockName, $resource, $isLimitedAccess)
  69. {
  70. /** @var $noticeInbox \Magento\AdminNotification\Model\Inbox */
  71. $noticeInbox = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  72. \Magento\AdminNotification\Model\Inbox::class
  73. );
  74. if (!$noticeInbox->loadLatestNotice()->getId()) {
  75. $noticeInbox->addCritical('Test notice', 'Test description');
  76. }
  77. $this->_auth->login(
  78. \Magento\TestFramework\Bootstrap::ADMIN_NAME,
  79. \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
  80. );
  81. /** @var $acl \Magento\Framework\Acl */
  82. $acl = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  83. ->get(\Magento\Framework\Acl\Builder::class)
  84. ->getAcl();
  85. if ($isLimitedAccess) {
  86. $acl->deny(null, $resource);
  87. }
  88. $this->dispatch('backend/admin/dashboard');
  89. $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  90. \Magento\Framework\View\LayoutInterface::class
  91. );
  92. $actualBlocks = $layout->getAllBlocks();
  93. $this->assertNotEmpty($actualBlocks);
  94. if ($isLimitedAccess) {
  95. $this->assertNotContains($blockName, array_keys($actualBlocks));
  96. } else {
  97. $this->assertContains($blockName, array_keys($actualBlocks));
  98. }
  99. }
  100. /**
  101. * Data provider with expected blocks with acl properties
  102. *
  103. * @return array
  104. */
  105. public function nodesWithAcl()
  106. {
  107. return [
  108. ['notification_window', 'Magento_AdminNotification::show_toolbar', true],
  109. ['notification_window', 'Magento_AdminNotification::show_toolbar', false]
  110. ];
  111. }
  112. }