setThemeManager example

parent::setUp();

    $this->cache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->moduleHandler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $this->themeHandler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface');
    $this->themeInitialization = $this->createMock('Drupal\Core\Theme\ThemeInitializationInterface');
    $this->runtimeCache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->themeManager = $this->createMock('Drupal\Core\Theme\ThemeManagerInterface');
    $this->moduleList = $this->createMock(ModuleExtensionList::class);
    $this->registry = new Registry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization, $this->runtimeCache, $this->moduleList);
    $this->registry->setThemeManager($this->themeManager);
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    parent::tearDown();
    static::$functions = [];
  }

  /** * Tests getting the theme registry defined by a module. */
/** * Tests the theme registry with multiple subthemes. */
  public function testMultipleSubThemes() {
    $theme_handler = \Drupal::service('theme_handler');
    \Drupal::service('theme_installer')->install(['test_basetheme', 'test_subtheme', 'test_subsubtheme']);

    $module_list = $this->container->get('extension.list.module');
    assert($module_list instanceof ModuleExtensionList);

    $registry_subsub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap')$module_list, 'test_subsubtheme');
    $registry_subsub_theme->setThemeManager(\Drupal::theme());
    $registry_sub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap')$module_list, 'test_subtheme');
    $registry_sub_theme->setThemeManager(\Drupal::theme());
    $registry_base_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap')$module_list, 'test_basetheme');
    $registry_base_theme->setThemeManager(\Drupal::theme());

    $preprocess_functions = $registry_subsub_theme->get()['theme_test_template_test']['preprocess functions'];
    $this->assertSame([
      'template_preprocess',
      'test_basetheme_preprocess_theme_test_template_test',
      'test_subtheme_preprocess_theme_test_template_test',
      'test_subsubtheme_preprocess_theme_test_template_test',
    ],
$module_installer = $this->container->get('module_installer');
    $module_installer->install($this->allModules);

    $this->installConfig(['system', 'user']);
  }

  /** * Ensures that Stable 9 overrides all relevant core templates. */
  public function testStable9TemplateOverrides() {
    $registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler()$this->themeHandler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), \Drupal::service('extension.list.module'), 'stable9');
    $registry->setThemeManager(\Drupal::theme());

    $registry_full = $registry->get();

    foreach ($registry_full as $hook => $info) {
      if (isset($info['template'])) {
        // Allow skipping templates.         if (in_array($info['template']$this->templatesToSkip)) {
          continue;
        }

        $this->assertEquals('core/themes/stable9', $info['theme path']$info['template'] . '.html.twig overridden in Stable 9.');
      }
Home | Imprint | This part of the site doesn't use cookies.