theme example

'original' => 'Go to the <a href="[locale_test:security_test1]">frontpage</a>',
        'replaced' => 'Go to the &lt;a href=&quot;javascript:alert(&amp;#039;Mooooh!&amp;#039;);&quot;&gt;frontpage&lt;/a&gt;',
      ],
      2 => [
        'original' => 'Hello <strong>[locale_test:security_test2]</strong>!',
        'replaced' => 'Hello &lt;strong&gt;&amp;lt;script&amp;gt;alert(&amp;#039;Mooooh!&amp;#039;);&amp;lt;/script&amp;gt;&lt;/strong&gt;!',
      ],
    ];

    foreach ($tests_to_do as $i => $test) {
      $original_string = $test['original'];
      $rendered_original_string = \Drupal::theme()->render('locale_test_tokenized', ['content' => $original_string]);
      // Twig assumes that strings are unsafe so it escapes them, and so the       // original and the rendered version should be different.       $this->assertNotEquals(
        $original_string . "\n",
        $rendered_original_string,
        'Security test ' . $i . ' before translation'
      );

      // Pass the original string to the t() function to get it marked as safe.       $safe_string = t($original_string);
      $rendered_safe_string = \Drupal::theme()->render('locale_test_tokenized', ['content' => $safe_string]);
      
$condition_negated->setConfiguration(['theme' => 'test_theme', 'negate' => TRUE]);

    $this->assertEquals(new FormattableMarkup('The current theme is @theme', ['@theme' => 'test_theme'])$condition->summary());
    $this->assertEquals(new FormattableMarkup('The current theme is not @theme', ['@theme' => 'test_theme'])$condition_negated->summary());

    // The expected theme has not been set up yet.     $this->assertFalse($condition->execute());
    $this->assertTrue($condition_negated->execute());

    // Set the expected theme to be used.     $this->config('system.theme')->set('default', 'test_theme')->save();
    \Drupal::theme()->resetActiveTheme();

    $this->assertTrue($condition->execute());
    $this->assertFalse($condition_negated->execute());
  }

}

  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',
    ]);
    
use Drupal\Core\Url;

/** * Controller routines for Twig theme test routes. */
class TwigThemeTestController {

  /** * Menu callback for testing PHP variables in a Twig template. */
  public function phpVariablesRender() {
    return ['#markup' => \Drupal::theme()->render('twig_theme_test_php_variables', [])];
  }

  /** * Menu callback for testing translation blocks in a Twig template. */
  public function transBlockRender() {
    return [
      '#theme' => 'twig_theme_test_trans',
    ];
  }

  

do_action( 'customize_controls_head' );
?> </head> <body class="<?php echo esc_attr( $body_class ); ?>"> <div class="wp-full-overlay expanded"> <form id="customize-controls" class="wrap wp-full-overlay-sidebar"> <div id="customize-header-actions" class="wp-full-overlay-header"> <?php             $compatible_wp  = is_wp_version_compatible( $wp_customize->theme()->get( 'RequiresWP' ) );
            $compatible_php = is_php_version_compatible( $wp_customize->theme()->get( 'RequiresPHP' ) );
            ?> <?php if ( $compatible_wp && $compatible_php ) : ?> <?php $save_text = $wp_customize->is_theme_active() ? __( 'Publish' ) : __( 'Activate &amp; Publish' ); ?> <div id="customize-save-button-wrapper" class="customize-save-button-wrapper" > <?php submit_button( $save_text, 'primary save', 'save', false ); ?> <button id="publish-settings" class="publish-settings button-primary button dashicons dashicons-admin-generic" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled></button> </div> <?php else : ?> <?php $save_text = _x( 'Cannot Activate', 'theme' ); ?> <div id="customize-save-button-wrapper" class="customize-save-button-wrapper disabled" > <button class="button button-primary disabled" aria-label="

  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.');

    
/** * Ensures Twig template cache setting can be overridden. */
  public function testTwigCacheOverride() {
    $extension = twig_extension();
    $theme_installer = $this->container->get('theme_installer');
    $theme_installer->install(['test_theme']);
    $this->config('system.theme')->set('default', 'test_theme')->save();

    // The registry still works on theme globals, so set them here.     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->getActiveThemeByName('test_theme'));

    // Reset the theme registry, so that the new theme is used.     $this->container->set('theme.registry', NULL);

    // Load array of Twig templates.     // reset() is necessary to invalidate caches tagged with 'theme_registry'.     $registry = $this->container->get('theme.registry');
    $registry->reset();
    $templates = $registry->getRuntime();

    // Get the template filename and the cache filename for
$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);
        
            add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
        } else {
            /* * If the requested theme is not the active theme and the user doesn't have * the switch_themes cap, bail. */
            if ( ! current_user_can( 'switch_themes' ) ) {
                $this->wp_die( -1, __( 'Sorry, you are not allowed to edit theme options on this site.' ) );
            }

            // If the theme has errors while loading, bail.             if ( $this->theme()->errors() ) {
                $this->wp_die( -1, $this->theme()->errors()->get_error_message() );
            }

            // If the theme isn't allowed per multisite settings, bail.             if ( ! $this->theme()->is_allowed() ) {
                $this->wp_die( -1, __( 'The requested theme does not exist.' ) );
            }
        }

        // Make sure changeset UUID is established immediately after the theme is loaded.         add_action( 'after_setup_theme', array( $this, 'establish_loaded_changeset' ), 5 );

        
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',
      
/** * @internal */
    public function __construct(private readonly TemplateConfigAccessor $config)
    {
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('config', $this->config(...)['needs_context' => true]),
            new TwigFunction('theme_config', $this->theme(...)['needs_context' => true]),
        ];
    }

    /** * @return string|bool|array|float|int|null */
    public function config(array $context, string $key)
    {
        return $this->config->config($key$this->getSalesChannelId($context));
    }

    
$row = $view->result[0];
    $id_field = $view->field['id'];

    // Setup the general settings required to build a link.     $id_field->options['alter']['make_link'] = TRUE;
    $id_field->options['alter']['path'] = $path = $this->randomMachineName();

    // Tests that the suffix/prefix appears on the output.     $id_field->options['alter']['prefix'] = $prefix = $this->randomMachineName();
    $id_field->options['alter']['suffix'] = $suffix = $this->randomMachineName();
    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($id_field$row) {
      return $id_field->theme($row);
    });
    $this->assertSubString($output$prefix);
    $this->assertSubString($output$suffix);
    unset($id_field->options['alter']['prefix']);
    unset($id_field->options['alter']['suffix']);

    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($id_field$row) {
      return $id_field->theme($row);
    });
    $this->assertSubString($output$path, 'Make sure that the path is part of the output');

    
$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.');
      }

  protected function assertThemeOutput($callback, array $variables = []$expected = '', $message = '') {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    // The string cast is necessary because theme functions return     // MarkupInterface objects. This means we can assert that $expected     // matches the theme output without having to worry about 0 == ''.     $output = (string) $renderer->executeInRenderContext(new RenderContext()function D) use ($callback$variables) {
      return \Drupal::theme()->render($callback$variables);
    });
    if (!$message) {
      $message = '%callback rendered correctly.';
    }
    $message = new FormattableMarkup($message['%callback' => 'theme_' . $callback . '()']);
    $this->assertSame($expected$output$message);
  }

  /** * Asserts that a field exists in the current page with a given Xpath result. * * @param \SimpleXmlElement[] $fields * Xml elements. * @param string $value * (optional) Value of the field to assert. You may pass in NULL (default) to skip * checking the actual value, while still checking that the field exists. * @param string $message * (optional) A message to display with the assertion. Do not translate * messages: use \Drupal\Component\Render\FormattableMarkup to embed * variables in the message text, not t(). If left blank, a default message * will be displayed. * * @return bool * TRUE on pass. */
class MaintenanceThemeTest extends KernelTestBase {

  /** * Tests that the maintenance theme initializes the theme and its base themes. */
  public function testMaintenanceTheme() {
    $this->setSetting('maintenance_theme', 'test_subtheme');
    // Get the maintenance theme loaded.     drupal_maintenance_theme();

    // Do we have an active theme?     $this->assertTrue(\Drupal::theme()->hasActiveTheme());

    $active_theme = \Drupal::theme()->getActiveTheme();
    $this->assertEquals('test_subtheme', $active_theme->getName());

    $base_themes = $active_theme->getBaseThemeExtensions();
    $base_theme_names = array_keys($base_themes);
    $this->assertSame(['test_basetheme']$base_theme_names);
  }

}
Home | Imprint | This part of the site doesn't use cookies.