DeprecatedModulesTestTrait.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Drupal\Tests;
  3. /**
  4. * Provides methods remove deprecated modules from tests.
  5. */
  6. trait DeprecatedModulesTestTrait {
  7. /**
  8. * List of deprecated modules names to not be enabled for tests.
  9. *
  10. * @var array
  11. */
  12. protected $deprecatedModules = ['block_place'];
  13. /**
  14. * Flag to exclude deprecated modules from the tests.
  15. *
  16. * Legacy*Test -test may set this to FALSE to include also deprecated
  17. * modules for tests.
  18. *
  19. * @var bool
  20. */
  21. protected $excludeDeprecated = TRUE;
  22. /**
  23. * Removes deprecated modules from the provided modules.list.
  24. *
  25. * @param array $modules
  26. * Array of modules names.
  27. *
  28. * @return array
  29. * The filtered $modules array.
  30. */
  31. protected function removeDeprecatedModules(array $modules) {
  32. return $this->excludeDeprecated ? array_diff($modules, $this->deprecatedModules) : $modules;
  33. }
  34. /**
  35. * Overrides \Drupal\KernelTests\KernelTestBase::enableModules().
  36. *
  37. * For kernel tests this override will ensure that deprecated modules are not
  38. * enabled if \Drupal\Tests\DeprecatedModulesTestTrait::$excludeDeprecated
  39. * is set to true.
  40. */
  41. protected function enableModules(array $modules) {
  42. parent::enableModules($this->removeDeprecatedModules($modules));
  43. }
  44. }