IndexTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Controller\Adminhtml;
  7. use Magento\Framework\App\Request\Http as HttpRequest;
  8. /**
  9. * @magentoAppArea adminhtml
  10. * @magentoDbIsolation enabled
  11. */
  12. class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  13. {
  14. /**
  15. * Check not logged state
  16. * @covers \Magento\Backend\Controller\Adminhtml\Index\Index::execute
  17. */
  18. public function testNotLoggedIndexAction()
  19. {
  20. $this->_auth->logout();
  21. $this->dispatch('backend/admin/index/index');
  22. /** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
  23. $backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  24. \Magento\Backend\Model\UrlInterface::class
  25. );
  26. $backendUrlModel->turnOffSecretKey();
  27. $url = $backendUrlModel->getUrl('admin');
  28. $this->assertRedirect($this->stringStartsWith($url));
  29. }
  30. /**
  31. * Check logged state
  32. * @covers \Magento\Backend\Controller\Adminhtml\Index\Index::execute
  33. *
  34. */
  35. public function testLoggedIndexAction()
  36. {
  37. $this->dispatch('backend/admin/index/index');
  38. $this->assertRedirect();
  39. }
  40. /**
  41. * @covers \Magento\Backend\Controller\Adminhtml\Index\GlobalSearch::execute
  42. */
  43. public function testGlobalSearchAction()
  44. {
  45. $this->getRequest()->setParam('isAjax', 'true');
  46. $this->getRequest()->setMethod(HttpRequest::METHOD_POST);
  47. $this->getRequest()->setPostValue('query', 'dummy');
  48. $this->dispatch('backend/admin/index/globalSearch');
  49. $actual = $this->getResponse()->getBody();
  50. $this->assertEquals([], json_decode($actual));
  51. }
  52. }