Chris@0: install(['test_theme']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that the Twig engine handles PHP data correctly. Chris@0: */ Chris@0: public function testTwigVariableDataTypes() { Chris@0: $this->config('system.theme') Chris@0: ->set('default', 'test_theme') Chris@0: ->save(); Chris@0: $this->drupalGet('twig-theme-test/php-variables'); Chris@0: foreach (_test_theme_twig_php_values() as $type => $value) { Chris@0: $this->assertRaw('
  • ' . $type . ': ' . $value['expected'] . '
  • '); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the url and url_generate Twig functions. Chris@0: */ Chris@0: public function testTwigUrlGenerator() { Chris@0: $this->drupalGet('twig-theme-test/url-generator'); Chris@0: // Find the absolute URL of the current site. Chris@0: $url_generator = $this->container->get('url_generator'); Chris@0: $expected = [ Chris@0: 'path (as route) not absolute: ' . $url_generator->generateFromRoute('user.register'), Chris@0: 'url (as route) absolute: ' . $url_generator->generateFromRoute('user.register', [], ['absolute' => TRUE]), Chris@0: 'path (as route) not absolute with fragment: ' . $url_generator->generateFromRoute('user.register', [], ['fragment' => 'bottom']), Chris@0: 'url (as route) absolute despite option: ' . $url_generator->generateFromRoute('user.register', [], ['absolute' => TRUE]), Chris@0: 'url (as route) absolute with fragment: ' . $url_generator->generateFromRoute('user.register', [], ['absolute' => TRUE, 'fragment' => 'bottom']), Chris@0: ]; Chris@0: Chris@0: // Verify that url() has the ability to bubble cacheability metadata: Chris@0: // absolute URLs should bubble the 'url.site' cache context. (This only Chris@0: // needs to test that cacheability metadata is bubbled *at all*; detailed Chris@0: // tests for *which* cacheability metadata is bubbled live elsewhere.) Chris@0: $this->assertCacheContext('url.site'); Chris@0: Chris@0: // Make sure we got something. Chris@0: $content = $this->getRawContent(); Chris@0: $this->assertFalse(empty($content), 'Page content is not empty'); Chris@0: foreach ($expected as $string) { Chris@0: $this->assertRaw('
    ' . $string . '
    '); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the link_generator Twig functions. Chris@0: */ Chris@0: public function testTwigLinkGenerator() { Chris@0: $this->drupalGet('twig-theme-test/link-generator'); Chris@0: Chris@0: /** @var \Drupal\Core\Utility\LinkGenerator $link_generator */ Chris@0: $link_generator = $this->container->get('link_generator'); Chris@0: Chris@0: $generated_url = Url::fromRoute('user.register', [], ['absolute' => TRUE])->toString(TRUE)->getGeneratedUrl(); Chris@0: $expected = [ Chris@0: 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register', [], ['absolute' => TRUE])), Chris@0: 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register', [], ['absolute' => TRUE, 'attributes' => ['foo' => 'bar']])), Chris@0: 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register', [], ['attributes' => ['foo' => 'bar', 'id' => 'kitten']])), Chris@0: 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register', [], ['attributes' => ['id' => 'kitten']])), Chris@0: 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register', [], ['attributes' => ['class' => ['llama', 'kitten', 'panda']]])), Chris@0: 'link via the linkgenerator: ' . $link_generator->generate(Markup::create('register'), new Url('user.register', [], ['absolute' => TRUE])), Chris@0: 'link via the linkgenerator: register', Chris@0: 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register', [], ['attributes' => ['foo' => 'bar']])) . ' ' . $link_generator->generate('register', new Url('user.register', [], ['attributes' => ['foo' => 'bar']])), Chris@0: ]; Chris@0: Chris@0: // Verify that link() has the ability to bubble cacheability metadata: Chris@0: // absolute URLs should bubble the 'url.site' cache context. (This only Chris@0: // needs to test that cacheability metadata is bubbled *at all*; detailed Chris@0: // tests for *which* cacheability metadata is bubbled live elsewhere.) Chris@0: $this->assertCacheContext('url.site'); Chris@0: Chris@0: $content = $this->getRawContent(); Chris@0: $this->assertFalse(empty($content), 'Page content is not empty'); Chris@0: foreach ($expected as $string) { Chris@0: $this->assertRaw('
    ' . $string . '
    '); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the magic url to string Twig functions. Chris@0: * Chris@0: * @see \Drupal\Core\Url Chris@0: */ Chris@0: public function testTwigUrlToString() { Chris@0: $this->drupalGet('twig-theme-test/url-to-string'); Chris@0: Chris@0: $expected = [ Chris@0: 'rendered url: ' . Url::fromRoute('user.register')->toString(), Chris@0: ]; Chris@0: Chris@0: $content = $this->getRawContent(); Chris@0: $this->assertFalse(empty($content), 'Page content is not empty'); Chris@0: foreach ($expected as $string) { Chris@0: $this->assertRaw('
    ' . $string . '
    '); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the automatic/magic calling of toString() on objects, if exists. Chris@0: */ Chris@0: public function testTwigFileUrls() { Chris@0: $this->drupalGet('/twig-theme-test/file-url'); Chris@0: $filepath = file_url_transform_relative(file_create_url('core/modules/system/tests/modules/twig_theme_test/twig_theme_test.js')); Chris@0: $this->assertRaw('
    file_url: ' . $filepath . '
    '); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the attach of asset libraries. Chris@0: */ Chris@0: public function testTwigAttachLibrary() { Chris@0: $this->drupalGet('/twig-theme-test/attach-library'); Chris@0: $this->assertRaw('ckeditor.js'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the rendering of renderables. Chris@0: */ Chris@0: public function testRenderable() { Chris@0: $this->drupalGet('/twig-theme-test/renderable'); Chris@0: $this->assertRaw('
    Example markup
    '); Chris@0: } Chris@0: Chris@0: }