Environment example

$this->assertEquals($sourcetrim($compiler->getSource()));
        }
    }

    protected function getCompiler(Environment $environment = null)
    {
        return new Compiler(null === $environment ? $this->getEnvironment() : $environment);
    }

    protected function getEnvironment()
    {
        return new Environment(new ArrayLoader([]));
    }

    protected function getVariableGetter($name$line = false)
    {
        $line = $line > 0 ? "// line $line\n" : '';

        return sprintf('%s($context["%s"] ?? null)', $line$name);
    }

    protected function getAttributeGetter()
    {
        
$this->systemUnderTest = new TwigExtension($this->renderer, $this->urlGenerator, $this->themeManager, $this->dateFormatter, $this->fileUrlGenerator);
  }

  /** * Tests the escaping. * * @dataProvider providerTestEscaping */
  public function testEscaping($template$expected) {
    $loader = new FilesystemLoader();
    $twig = new Environment($loader[
      'debug' => TRUE,
      'cache' => FALSE,
      'autoescape' => 'html',
      'optimizations' => 0,
    ]);
    $twig->addExtension($this->systemUnderTest);

    $name = '__string_template_test__';
    $nodes = $twig->parse($twig->tokenize(new Source($template$name)));

    $this->assertSame($expected$nodes->getNode('body')
      
$this->markTestSkipped($condition);
            }
        }

        $loader = new ArrayLoader($templates);

        foreach ($outputs as $i => $match) {
            $config = array_merge([
                'cache' => false,
                'strict_variables' => true,
            ]$match[2] ? eval($match[2].';') : []);
            $twig = new Environment($loader$config);
            $twig->addGlobal('global', 'global');
            foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
                $twig->addRuntimeLoader($runtimeLoader);
            }

            foreach ($this->getExtensions() as $extension) {
                $twig->addExtension($extension);
            }

            foreach ($this->getTwigFilters() as $filter) {
                $twig->addFilter($filter);
            }


  /** * Tests the twig calls to the Attribute. * @dataProvider providerTestAttributeClassHelpers * * @covers ::removeClass * @covers ::addClass */
  public function testTwigAddRemoveClasses($template$expected$seed_attributes = []) {
    $loader = new StringLoader();
    $twig = new Environment($loader);
    $data = ['attributes' => new Attribute($seed_attributes)];
    $result = $twig->createTemplate($template)->render($data);
    $this->assertEquals($expected$result);
  }

  /** * Provides tests data for testEscaping. * * @return array * An array of test data each containing of a twig template string, * a resulting string of classes and an optional array of attributes. */

  protected $twig;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $loader = new StringLoader();
    $this->twig = new Environment($loader);
    $policy = new TwigSandboxPolicy();
    $sandbox = new SandboxExtension($policy, TRUE);
    $this->twig->addExtension($sandbox);
  }

  /** * Tests that dangerous methods cannot be called in entity objects. * * @dataProvider getTwigEntityDangerousMethods */
  public function testEntityDangerousMethods($template) {
    
Home | Imprint | This part of the site doesn't use cookies.