CacheTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  8. * @magentoAppArea adminhtml
  9. */
  10. class CacheTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  11. {
  12. /**
  13. * @magentoDataFixture Magento/Backend/controllers/_files/cache/application_cache.php
  14. * @magentoDataFixture Magento/Backend/controllers/_files/cache/non_application_cache.php
  15. */
  16. public function testFlushAllAction()
  17. {
  18. /** @var $cache \Magento\Framework\App\Cache */
  19. $cache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  20. \Magento\Framework\App\Cache::class
  21. );
  22. $this->assertNotEmpty($cache->load('APPLICATION_FIXTURE'));
  23. $this->dispatch('backend/admin/cache/flushAll');
  24. /** @var $cachePool \Magento\Framework\App\Cache\Frontend\Pool */
  25. $this->assertFalse($cache->load('APPLICATION_FIXTURE'));
  26. $cachePool = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  27. \Magento\Framework\App\Cache\Frontend\Pool::class
  28. );
  29. /** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */
  30. foreach ($cachePool as $cacheFrontend) {
  31. $this->assertFalse($cacheFrontend->getBackend()->load('NON_APPLICATION_FIXTURE'));
  32. }
  33. }
  34. /**
  35. * @magentoDataFixture Magento/Backend/controllers/_files/cache/application_cache.php
  36. * @magentoDataFixture Magento/Backend/controllers/_files/cache/non_application_cache.php
  37. */
  38. public function testFlushSystemAction()
  39. {
  40. $this->dispatch('backend/admin/cache/flushSystem');
  41. /** @var $cache \Magento\Framework\App\Cache */
  42. $cache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  43. \Magento\Framework\App\Cache::class
  44. );
  45. /** @var $cachePool \Magento\Framework\App\Cache\Frontend\Pool */
  46. $this->assertFalse($cache->load('APPLICATION_FIXTURE'));
  47. $cachePool = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  48. \Magento\Framework\App\Cache\Frontend\Pool::class
  49. );
  50. /** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */
  51. foreach ($cachePool as $cacheFrontend) {
  52. $this->assertSame(
  53. 'non-application cache data',
  54. $cacheFrontend->getBackend()->load('NON_APPLICATION_FIXTURE')
  55. );
  56. }
  57. }
  58. /**
  59. * @dataProvider massActionsInvalidTypesDataProvider
  60. * @param $action
  61. */
  62. public function testMassActionsInvalidTypes($action)
  63. {
  64. $this->getRequest()->setParams(['types' => ['invalid_type_1', 'invalid_type_2', 'config']]);
  65. $this->dispatch('backend/admin/cache/' . $action);
  66. $this->assertSessionMessages(
  67. $this->contains("These cache type(s) don&#039;t exist: invalid_type_1, invalid_type_2"),
  68. \Magento\Framework\Message\MessageInterface::TYPE_ERROR
  69. );
  70. }
  71. /**
  72. * @return array
  73. */
  74. public function massActionsInvalidTypesDataProvider()
  75. {
  76. return [
  77. 'enable' => ['massEnable'],
  78. 'disable' => ['massDisable'],
  79. 'refresh' => ['massRefresh']
  80. ];
  81. }
  82. }