getThemePath example

/** * @internal * * @covers \Shopware\Storefront\Theme\Message\DeleteThemeFilesMessage */
class DeleteThemeFilesMessageTest extends TestCase
{
    public function testStruct(): void
    {
        $message = new DeleteThemeFilesMessage('path', 'salesChannel', 'theme');

        static::assertEquals('path', $message->getThemePath());
        static::assertEquals('salesChannel', $message->getSalesChannelId());
        static::assertEquals('theme', $message->getThemeId());
    }
}

  public function testWhiteListChaining() {
    /** @var \Drupal\Core\Template\TwigEnvironment $environment */
    $environment = \Drupal::service('twig');
    $node = Node::create([
      'type' => 'page',
      'title' => 'Some node mmk',
      'status' => 1,
      'field_term' => $this->term->id(),
    ]);
    $node->save();
    $template = $environment->load($this->getThemePath('test_theme') . '/templates/node.html.twig');
    $markup = $template->render(['node' => $node]);
    $this->setRawContent($markup);
    $this->assertText('Sometimes people are just jerks');
  }

}


  /** * Tests libraries-override. */
  public function testStylesheets() {
    $this->themeInstaller->install(['test_basetheme', 'test_subtheme']);
    $this->config('system.theme')
      ->set('default', 'test_subtheme')
      ->save();

    $base = $this->getThemePath('test_basetheme');
    $sub = $this->getThemePath('test_subtheme') . '/css';

    // All removals are expected to be based on a file's path and name and     // should work nevertheless.     $this->drupalGet('theme-test/info/stylesheets');

    $this->assertSession()->elementsCount('xpath', '//link[contains(@href, "' . $base . '/base-add.css")]', 1);
    $this->assertSession()->elementNotExists('xpath', '//link[contains(@href, "base-remove.css")]');

    $this->assertSession()->elementsCount('xpath', '//link[contains(@href, "' . $sub . '/sub-add.css")]', 1);
    $this->assertSession()->elementNotExists('xpath', '//link[contains(@href, "sub-remove.css")]');
    

    public function __construct(
        private readonly FilesystemOperator $filesystem,
        private readonly AbstractThemePathBuilder $pathBuilder
    ) {
    }

    public function __invoke(DeleteThemeFilesMessage $message): void
    {
        $currentPath = $this->pathBuilder->assemblePath($message->getSalesChannelId()$message->getThemeId());

        if ($currentPath === $message->getThemePath()) {
            return;
        }

        $this->filesystem->deleteDirectory($message->getThemePath());
    }
}
$this->config('system.theme')->set('default', 'test_theme')->save();
    $this->drupalCreateContentType(['type' => 'page']);
    // Enable debug, rebuild the service container, and clear all caches.     $parameters = $this->container->getParameter('twig.config');
    $parameters['debug'] = TRUE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();
    $this->resetAll();

    $cache = $this->container->get('theme.registry')->get();
    // Create array of Twig templates.     $templates = drupal_find_theme_templates($cache$extension$this->getThemePath('test_theme'));
    $templates += drupal_find_theme_templates($cache$extension$this->getModulePath('node'));

    // Create a node and test different features of the debug markup.     $node = $this->drupalCreateNode();
    $builder = \Drupal::entityTypeManager()->getViewBuilder('node');
    $build = $builder->view($node);
    $output = $renderer->renderRoot($build);
    $this->assertStringContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup found in theme output when debug is enabled.');
    $this->assertStringContainsString("THEME HOOK: 'node'", $output, 'Theme call information found.');
    $this->assertStringContainsString('* node--1--full' . $extension . PHP_EOL . ' x node--1' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' * node' . $extension$output, 'Suggested template files found in order and node ID specific template shown as current template.');
    $this->assertStringContainsString(Html::escape('node--<script type="text/javascript">alert(\'yo\');</script>')(string) $output);
    
'#markup' => 'Foo',
      ],
    ];
    $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', "\Drupal::service('renderer')->render() avoids #theme_wrappers recursion loop when rendering a render element.");
  }

  /** * Tests drupal_find_theme_templates(). */
  public function testFindThemeTemplates() {
    $registry = $this->container->get('theme.registry')->get();
    $templates = drupal_find_theme_templates($registry, '.html.twig', $this->getThemePath('test_theme'));
    $this->assertEquals('node--1', $templates['node__1']['template'], 'Template node--1.html.twig was found in test_theme.');
  }

  /** * Tests the update registry is correct during theme install and uninstall. */
  public function testThemeUpdateManagement() {
    // Install modules the theme is dependent on and enable the post update     // function.     \Drupal::state()->set('test_theme_depending_on_modules.post_update', TRUE);
    \Drupal::service('module_installer')->install([
      
Home | Imprint | This part of the site doesn't use cookies.