You are here

class TwigTestExtension in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/test/Twig/Tests/IntegrationTest.php \TwigTestExtension

Hierarchy

Expanded class hierarchy of TwigTestExtension

File

vendor/twig/twig/test/Twig/Tests/IntegrationTest.php, line 127

View source
class TwigTestExtension extends Twig_Extension {
  public function getTokenParsers() {
    return array(
      new TwigTestTokenParser_§(),
    );
  }
  public function getFilters() {
    return array(
      new Twig_SimpleFilter('§', array(
        $this,
        '§Filter',
      )),
      new Twig_SimpleFilter('escape_and_nl2br', array(
        $this,
        'escape_and_nl2br',
      ), array(
        'needs_environment' => true,
        'is_safe' => array(
          'html',
        ),
      )),
      new Twig_SimpleFilter('nl2br', array(
        $this,
        'nl2br',
      ), array(
        'pre_escape' => 'html',
        'is_safe' => array(
          'html',
        ),
      )),
      new Twig_SimpleFilter('escape_something', array(
        $this,
        'escape_something',
      ), array(
        'is_safe' => array(
          'something',
        ),
      )),
      new Twig_SimpleFilter('preserves_safety', array(
        $this,
        'preserves_safety',
      ), array(
        'preserves_safety' => array(
          'html',
        ),
      )),
      new Twig_SimpleFilter('*_path', array(
        $this,
        'dynamic_path',
      )),
      new Twig_SimpleFilter('*_foo_*_bar', array(
        $this,
        'dynamic_foo',
      )),
    );
  }
  public function getFunctions() {
    return array(
      new Twig_SimpleFunction('§', array(
        $this,
        '§Function',
      )),
      new Twig_SimpleFunction('safe_br', array(
        $this,
        'br',
      ), array(
        'is_safe' => array(
          'html',
        ),
      )),
      new Twig_SimpleFunction('unsafe_br', array(
        $this,
        'br',
      )),
      new Twig_SimpleFunction('*_path', array(
        $this,
        'dynamic_path',
      )),
      new Twig_SimpleFunction('*_foo_*_bar', array(
        $this,
        'dynamic_foo',
      )),
    );
  }
  public function getTests() {
    return array(
      new Twig_SimpleTest('multi word', array(
        $this,
        'is_multi_word',
      )),
    );
  }
  public function §Filter($value) {
    return "§{$value}§";
  }
  public function §Function($value) {
    return "§{$value}§";
  }

  /**
   * nl2br which also escapes, for testing escaper filters.
   */
  public function escape_and_nl2br($env, $value, $sep = '<br />') {
    return $this
      ->nl2br(twig_escape_filter($env, $value, 'html'), $sep);
  }

  /**
   * nl2br only, for testing filters with pre_escape.
   */
  public function nl2br($value, $sep = '<br />') {

    // not secure if $value contains html tags (not only entities)
    // don't use
    return str_replace("\n", "{$sep}\n", $value);
  }
  public function dynamic_path($element, $item) {
    return $element . '/' . $item;
  }
  public function dynamic_foo($foo, $bar, $item) {
    return $foo . '/' . $bar . '/' . $item;
  }
  public function escape_something($value) {
    return strtoupper($value);
  }
  public function preserves_safety($value) {
    return strtoupper($value);
  }
  public function br() {
    return '<br />';
  }
  public function is_multi_word($value) {
    return false !== strpos($value, ' ');
  }
  public function getName() {
    return 'integration_test';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TwigTestExtension::br public function
TwigTestExtension::dynamic_foo public function
TwigTestExtension::dynamic_path public function
TwigTestExtension::escape_and_nl2br public function nl2br which also escapes, for testing escaper filters.
TwigTestExtension::escape_something public function
TwigTestExtension::getFilters public function
TwigTestExtension::getFunctions public function
TwigTestExtension::getName public function
TwigTestExtension::getTests public function
TwigTestExtension::getTokenParsers public function
TwigTestExtension::is_multi_word public function
TwigTestExtension::nl2br public function nl2br only, for testing filters with pre_escape.
TwigTestExtension::preserves_safety public function
TwigTestExtension::§Filter public function
TwigTestExtension::§Function public function