You are here

public function EngineTwigTest::testTwigLinkGenerator in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Theme/EngineTwigTest.php \Drupal\system\Tests\Theme\EngineTwigTest::testTwigLinkGenerator()

Tests the link_generator Twig functions.

File

core/modules/system/src/Tests/Theme/EngineTwigTest.php, line 77
Contains \Drupal\system\Tests\Theme\EngineTwigTest.

Class

EngineTwigTest
Tests Twig-specific theme functionality.

Namespace

Drupal\system\Tests\Theme

Code

public function testTwigLinkGenerator() {
  $this
    ->drupalGet('twig-theme-test/link-generator');

  /** @var \Drupal\Core\Utility\LinkGenerator $link_generator */
  $link_generator = $this->container
    ->get('link_generator');
  $expected = [
    'link via the linkgenerator: ' . $link_generator
      ->generate('register', new Url('user.register', [], [
      'absolute' => TRUE,
    ])),
    'link via the linkgenerator: ' . $link_generator
      ->generate('register', new Url('user.register', [], [
      'absolute' => TRUE,
      'attributes' => [
        'foo' => 'bar',
      ],
    ])),
    'link via the linkgenerator: ' . $link_generator
      ->generate('register', new Url('user.register', [], [
      'attributes' => [
        'foo' => 'bar',
        'id' => 'kitten',
      ],
    ])),
    'link via the linkgenerator: ' . $link_generator
      ->generate('register', new Url('user.register', [], [
      'attributes' => [
        'id' => 'kitten',
      ],
    ])),
    'link via the linkgenerator: ' . $link_generator
      ->generate('register', new Url('user.register', [], [
      'attributes' => [
        'class' => [
          'llama',
          'kitten',
          'panda',
        ],
      ],
    ])),
  ];

  // Verify that link() has the ability to bubble cacheability metadata:
  // absolute URLs should bubble the 'url.site' cache context. (This only
  // needs to test that cacheability metadata is bubbled *at all*; detailed
  // tests for *which* cacheability metadata is bubbled live elsewhere.)
  $this
    ->assertCacheContext('url.site');
  $content = $this
    ->getRawContent();
  $this
    ->assertFalse(empty($content), 'Page content is not empty');
  foreach ($expected as $string) {
    $this
      ->assertRaw('<div>' . $string . '</div>');
  }
}