BaseThemeDefaultDeprecationTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace Drupal\KernelTests\Core\Theme;
  3. use Drupal\Core\DependencyInjection\ContainerBuilder;
  4. use Drupal\Core\Extension\ExtensionDiscovery;
  5. use Drupal\Core\Extension\InfoParser;
  6. use Drupal\Core\Extension\InfoParserInterface;
  7. use Drupal\Core\Extension\ThemeExtensionList;
  8. use Drupal\KernelTests\KernelTestBase;
  9. use org\bovigo\vfs\vfsStream;
  10. /**
  11. * Tests the behavior of the Stable theme.
  12. *
  13. * @group Theme
  14. */
  15. class BaseThemeDefaultDeprecationTest extends KernelTestBase {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public static $modules = ['system'];
  20. /**
  21. * The theme installer.
  22. *
  23. * @var \Drupal\Core\Extension\ThemeInstallerInterface
  24. */
  25. protected $themeInstaller;
  26. /**
  27. * The theme manager.
  28. *
  29. * @var \Drupal\Core\Theme\ThemeManagerInterface
  30. */
  31. protected $themeManager;
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function setUp() {
  36. parent::setUp();
  37. $this->themeInstaller = $this->container->get('theme_installer');
  38. $this->themeManager = $this->container->get('theme.manager');
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function register(ContainerBuilder $container) {
  44. parent::register($container);
  45. $container->getDefinition('extension.list.theme')
  46. ->setClass(VfsThemeExtensionList::class);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. protected function setUpFilesystem() {
  52. parent::setUpFilesystem();
  53. $vfs_root = vfsStream::setup('core');
  54. vfsStream::create([
  55. 'themes' => [
  56. 'test_stable' => [
  57. 'test_stable.info.yml' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_stable/test_stable.info.yml'),
  58. 'test_stable.theme' => file_get_contents(DRUPAL_ROOT . '/core/tests/fixtures/test_stable/test_stable.theme'),
  59. ],
  60. 'stable' => [
  61. 'stable.info.yml' => file_get_contents(DRUPAL_ROOT . '/core/themes/stable/stable.info.yml'),
  62. 'stable.theme' => file_get_contents(DRUPAL_ROOT . '/core/themes/stable/stable.theme'),
  63. ],
  64. ],
  65. ], $vfs_root);
  66. }
  67. /**
  68. * Ensures Stable is used by default when no base theme has been defined.
  69. *
  70. * @group legacy
  71. * @expectedDeprecation There is no `base theme` property specified in the test_stable.info.yml file. The optionality of the `base theme` property is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. All Drupal 8 themes must add `base theme: stable` to their *.info.yml file for them to continue to work as-is in future versions of Drupal. Drupal 9 requires the `base theme` property to be specified. See https://www.drupal.org/node/3066038
  72. */
  73. public function testStableIsDefault() {
  74. $this->container->get('extension.list.theme')
  75. ->setExtensionDiscovery(new ExtensionDiscovery('vfs://core'))
  76. ->setInfoParser(new VfsInfoParser('vfs:/'));
  77. $this->themeInstaller->install(['test_stable']);
  78. $this->config('system.theme')->set('default', 'test_stable')->save();
  79. $theme = $this->themeManager->getActiveTheme();
  80. $base_themes = $theme->getBaseThemeExtensions();
  81. $base_theme = reset($base_themes);
  82. $this->assertTrue($base_theme->getName() == 'stable', "Stable theme is the base theme if a theme hasn't decided to opt out.");
  83. }
  84. }
  85. /**
  86. * Test theme extension list class.
  87. */
  88. class VfsThemeExtensionList extends ThemeExtensionList {
  89. /**
  90. * The extension discovery for this extension list.
  91. *
  92. * @var \Drupal\Core\Extension\ExtensionDiscovery
  93. */
  94. protected $extensionDiscovery;
  95. /**
  96. * Sets the extension discovery.
  97. *
  98. * @param \Drupal\Core\Extension\ExtensionDiscovery $discovery
  99. * The extension discovery.
  100. *
  101. * @return self
  102. */
  103. public function setExtensionDiscovery(ExtensionDiscovery $discovery) {
  104. $this->extensionDiscovery = $discovery;
  105. return $this;
  106. }
  107. /**
  108. * Sets the info parser.
  109. *
  110. * @param \Drupal\Core\Extension\InfoParserInterface $info_parser
  111. * The info parser.
  112. *
  113. * @return self
  114. */
  115. public function setInfoParser(InfoParserInterface $info_parser) {
  116. $this->infoParser = $info_parser;
  117. return $this;
  118. }
  119. /**
  120. * {@inheritdoc}
  121. */
  122. public function getExtensionDiscovery() {
  123. return $this->extensionDiscovery;
  124. }
  125. }
  126. class VfsInfoParser extends InfoParser {
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function parse($filename) {
  131. return parent::parse("vfs://core/$filename");
  132. }
  133. }