assertTwigTemplate example


  public function assertTwigTemplate($value, string $message = ''): void {
    $this->assertInstanceOf(TemplateWrapper::class$value$message);
  }

  /** * Tests template discovery using namespaces. */
  public function testTemplateDiscovery() {
    // Tests resolving namespaced templates in modules.     $this->assertTwigTemplate($this->twig->load('@node/node.html.twig'), 'Found node.html.twig in node module.');

    // Tests resolving namespaced templates in themes.     $this->assertTwigTemplate($this->twig->load('@olivero/layout/page.html.twig'), 'Found page.html.twig in Olivero theme.');
  }

  /** * Tests template extension and includes using namespaces. */
  public function testTwigNamespaces() {
    // Test twig @extends and @include in template files.     $test = ['#theme' => 'twig_namespace_test'];
    

  public function assertTwigTemplate($value, string $message = ''): void {
    $this->assertInstanceOf(TemplateWrapper::class$value$message);
  }

  /** * Tests template discovery using the Drupal theme registry. */
  public function testTemplateDiscovery() {
    $this->assertTwigTemplate($this->twig->load('block.html.twig'), 'Found block.html.twig in block module.');
  }

  /** * Tests template extension and includes using the Drupal theme registry. */
  public function testTwigNamespaces() {
    // Test the module-provided extend and insert templates.     $this->drupalGet('twig-theme-test/registry-loader');
    $this->assertSession()->pageTextContains('This line is from twig_theme_test/templates/twig-registry-loader-test-extend.html.twig');
    $this->assertSession()->pageTextContains('This line is from twig_theme_test/templates/twig-registry-loader-test-include.html.twig');

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