AbstractIntegrity.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * An ancestor class for integrity tests
  8. */
  9. namespace Magento\TestFramework\TestCase;
  10. abstract class AbstractIntegrity extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Cached index of enabled modules
  14. *
  15. * @var array
  16. */
  17. protected $_enabledModules = null;
  18. /**
  19. * Returns array of enabled modules
  20. *
  21. * @return array
  22. */
  23. protected function _getEnabledModules()
  24. {
  25. if ($this->_enabledModules === null) {
  26. /** @var $helper \Magento\TestFramework\Helper\Config */
  27. $helper = \Magento\TestFramework\Helper\Factory::getHelper(\Magento\TestFramework\Helper\Config::class);
  28. $enabledModules = $helper->getEnabledModules();
  29. $this->_enabledModules = array_combine($enabledModules, $enabledModules);
  30. }
  31. return $this->_enabledModules;
  32. }
  33. /**
  34. * Checks resource file declaration - whether it is for disabled module (e.g. 'Disabled_Module::file.ext').
  35. *
  36. * @param string $file
  37. * @return bool
  38. */
  39. protected function _isFileForDisabledModule($file)
  40. {
  41. $enabledModules = $this->_getEnabledModules();
  42. if (preg_match('/^(.*)::/', $file, $matches)) {
  43. $module = $matches[1];
  44. if (!isset($enabledModules[$module])) {
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. /**
  51. * Returns flat array of themes currently located in system
  52. *
  53. * @return \Magento\Theme\Model\Theme[]
  54. */
  55. protected function _getDesignThemes()
  56. {
  57. $themeItems = [];
  58. /** @var $themeCollection \Magento\Theme\Model\Theme\Collection */
  59. $themeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  60. \Magento\Theme\Model\ResourceModel\Theme\Collection::class
  61. );
  62. /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
  63. foreach ($themeCollection as $theme) {
  64. $themeItems[$theme->getId()] = $theme;
  65. }
  66. return $themeItems;
  67. }
  68. }