initTheme example

protected static $modules = ['user', 'system'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('user');

    // Set up a test theme that prints the user's mail field.     \Drupal::service('theme_installer')->install(['user_test_theme']);
    \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('user_test_theme'));
    // Clear the theme registry.     $this->container->set('theme.registry', NULL);
  }

  /** * Tests account's available fields. */
  public function testUserFields() {
    // Create the user to test the user fields.     $user = User::create([
      'name' => 'foobar',
      

  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installSchema('history', ['history']);
    // Use history_test_theme because its marker is wrapped in a span so it can     // be easily targeted with xpath.     \Drupal::service('theme_installer')->install(['history_test_theme']);
    \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('history_test_theme'));
  }

  /** * Tests the handlers. */
  public function testHandlers() {
    $nodes = [];
    $node = Node::create([
      'title' => 'n1',
      'type' => 'default',
    ]);
    

  public function setThemeRegistry(Registry $theme_registry) {
    $this->themeRegistry = $theme_registry;
    return $this;
  }

  /** * {@inheritdoc} */
  public function getActiveTheme(RouteMatchInterface $route_match = NULL) {
    if (!isset($this->activeTheme)) {
      $this->initTheme($route_match);
    }
    return $this->activeTheme;
  }

  /** * {@inheritdoc} */
  public function hasActiveTheme() {
    return isset($this->activeTheme);
  }

  

  protected $defaultTheme = 'stark';

  /** * Tests if the theme has been altered. */
  public function testDrupalAlter() {
    // This test depends on Olivero, so make sure that it is always the current     // active theme.     \Drupal::service('theme_installer')->install(['olivero']);
    \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('olivero'));

    $array = ['foo' => 'bar'];
    $entity = new \stdClass();
    $entity->foo = 'bar';

    // Verify alteration of a single argument.     $array_copy = $array;
    $array_expected = ['foo' => 'Drupal theme'];
    \Drupal::moduleHandler()->alter('drupal_alter', $array_copy);
    \Drupal::theme()->alter('drupal_alter', $array_copy);
    $this->assertEquals($array_expected$array_copy, 'Single array was altered.');

    
$this->manager->getDefinitions();
  }

  /** * Ensure that components in modules without schema fail validation. * * The theme sdc_theme_test_enforce_schema_invalid is set as enforcing schemas * but provides a component without schema. */
  public function testInvalidDefinitionTheme(): void {
    \Drupal::service('theme_installer')->install(['sdc_theme_test_enforce_schema_invalid']);
    $active_theme = \Drupal::service('theme.initialization')->initTheme('sdc_theme_test_enforce_schema_invalid');
    \Drupal::service('theme.manager')->setActiveTheme($active_theme);
    $this->expectException(InvalidComponentException::class);
    $this->manager->getDefinitions();
  }

}
$styles = [
      'default' => '//div[@class="views-row"]',
      // Olivero does not use the 'views-col' class.       'grid' => '//div[contains(@class, "views-col") or contains(@class, "views-view-grid__item-inner")]',
      'html_list' => '//div[@class="item-list"]//li',
    ];

    $themes = ['olivero', 'stable9', 'stark', 'claro'];

    foreach ($themes as $theme) {
      \Drupal::service('theme_installer')->install([$theme]);
      \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme($theme));
      foreach ($styles as $type => $xpath) {
        $view = Views::getView('test_page_display');
        $view->storage->invalidateCaches();
        $view->initDisplay();
        $view->setDisplay('empty_row');
        $view->displayHandlers->get('empty_row')->default_display->options['style']['type'] = $type;
        $view->initStyle();
        $this->executeView($view);
        $output = $view->preview();
        $output = \Drupal::service('renderer')->renderRoot($output);
        $this->setRawContent($output);
        
// The hash is the second segment of the filename.     if (!isset($file_parts[1])) {
      throw new BadRequestHttpException('Invalid filename');
    }
    $received_hash = $file_parts[1];

    // Now build the asset groups based on the libraries. It requires the full     // set of asset groups to extract and build the aggregate for the group we     // want, since libraries may be split across different asset groups.     $theme = $request->query->get('theme');
    $active_theme = $this->themeInitialization->initTheme($theme);
    $this->themeManager->setActiveTheme($active_theme);

    $attached_assets = new AttachedAssets();
    $include_string = UrlHelper::uncompressQueryParameter($request->query->get('include'));

    if (!$include_string) {
      throw new BadRequestHttpException('The libraries to include are encoded incorrectly.');
    }
    $attached_assets->setLibraries(explode(',', $include_string));

    if ($request->query->has('exclude')) {
      
Home | Imprint | This part of the site doesn't use cookies.