EngineTwigTest.php 2.07 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\system\Tests\Theme\EngineTwigTest.
6
7
8
9
10
11
12
 */

namespace Drupal\system\Tests\Theme;

use Drupal\simpletest\WebTestBase;

/**
13
14
15
 * Tests Twig-specific theme functionality.
 *
 * @group Theme
16
 */
17
class EngineTwigTest extends WebTestBase {
18
19
20
21
22
23

  /**
   * Modules to enable.
   *
   * @var array
   */
24
  public static $modules = array('theme_test', 'twig_theme_test');
25

26
  protected function setUp() {
27
    parent::setUp();
28
    theme_enable(array('test_theme'));
29
  }
30
31
32
33
34

  /**
   * Tests that the Twig engine handles PHP data correctly.
   */
  function testTwigVariableDataTypes() {
35
    \Drupal::config('system.theme')
36
      ->set('default', 'test_theme')
37
38
39
40
41
42
43
      ->save();
    $this->drupalGet('twig-theme-test/php-variables');
    foreach (_test_theme_twig_php_values() as $type => $value) {
      $this->assertRaw('<li>' . $type . ': ' . $value['expected'] . '</li>');
    }
  }

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  /**
   * Tests the url and url_generate Twig functions.
   */
  public function testTwigUrlGenerator() {
    $this->drupalGet('twig-theme-test/url-generator');
    // Find the absolute URL of the current site.
    $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')),
    );
    // Make sure we got something.
    $content = $this->drupalGetContent();
    $this->assertFalse(empty($content), 'Page content is not empty');
    foreach ($expected as $string) {
      $this->assertRaw('<div>' . $string . '</div>');
    }
  }

66
}