View source
<?php
namespace Drupal\system\Tests\Theme;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
class EngineTwigTest extends WebTestBase {
public static $modules = array(
'theme_test',
'twig_theme_test',
);
protected function setUp() {
parent::setUp();
\Drupal::service('theme_handler')
->install(array(
'test_theme',
));
}
function testTwigVariableDataTypes() {
$this
->config('system.theme')
->set('default', 'test_theme')
->save();
$this
->drupalGet('twig-theme-test/php-variables');
foreach (_test_theme_twig_php_values() as $type => $value) {
$this
->assertRaw('<li>' . $type . ': ' . $value['expected'] . '</li>');
}
}
public function testTwigUrlGenerator() {
$this
->drupalGet('twig-theme-test/url-generator');
$url_generator = $this->container
->get('url_generator');
$expected = array(
'path (as route) not absolute: ' . $url_generator
->generateFromRoute('user.register'),
'url (as route) absolute: ' . $url_generator
->generateFromRoute('user.register', array(), array(
'absolute' => TRUE,
)),
'path (as route) not absolute with fragment: ' . $url_generator
->generateFromRoute('user.register', array(), array(
'fragment' => 'bottom',
)),
'url (as route) absolute despite option: ' . $url_generator
->generateFromRoute('user.register', array(), array(
'absolute' => TRUE,
)),
'url (as route) absolute with fragment: ' . $url_generator
->generateFromRoute('user.register', array(), array(
'absolute' => TRUE,
'fragment' => 'bottom',
)),
);
$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>');
}
}
public function testTwigLinkGenerator() {
$this
->drupalGet('twig-theme-test/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',
],
],
])),
];
$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>');
}
}
public function testTwigUrlToString() {
$this
->drupalGet('twig-theme-test/url-to-string');
$expected = [
'rendered url: ' . Url::fromRoute('user.register')
->toString(),
];
$content = $this
->getRawContent();
$this
->assertFalse(empty($content), 'Page content is not empty');
foreach ($expected as $string) {
$this
->assertRaw('<div>' . $string . '</div>');
}
}
public function testTwigFileUrls() {
$this
->drupalGet('/twig-theme-test/file-url');
$filepath = file_create_url('core/modules/system/tests/modules/twig_theme_test/twig_theme_test.js');
$this
->assertRaw('<div>file_url: ' . $filepath . '</div>');
}
public function testTwigAttachLibrary() {
$this
->drupalGet('/twig-theme-test/attach-library');
$this
->assertRaw('ckeditor.js');
}
public function testRenderable() {
$this
->drupalGet('/twig-theme-test/renderable');
$this
->assertRaw('<div>Example markup</div>');
}
}