Source example

use Twig\Source;

class FormThemeTokenParserTest extends TestCase
{
    /** * @dataProvider getTestsForFormTheme */
    public function testCompile($source$expected)
    {
        $env = new Environment($this->createMock(LoaderInterface::class)['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
        $env->addTokenParser(new FormThemeTokenParser());
        $source = new Source($source, '');
        $stream = $env->tokenize($source);
        $parser = new Parser($env);

        $expected->setSourceContext($source);

        $this->assertEquals($expected$parser->parse($stream)->getNode('body')->getNode(0));
    }

    public static function getTestsForFormTheme()
    {
        return [
            [


        throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
    }

    private function validate(string $template, string $file): array
    {
        $realLoader = $this->twig->getLoader();
        try {
            $temporaryLoader = new ArrayLoader([$file => $template]);
            $this->twig->setLoader($temporaryLoader);
            $nodeTree = $this->twig->parse($this->twig->tokenize(new Source($template$file)));
            $this->twig->compile($nodeTree);
            $this->twig->setLoader($realLoader);
        } catch (Error $e) {
            $this->twig->setLoader($realLoader);

            return ['template' => $template, 'file' => $file, 'line' => $e->getTemplateLine(), 'valid' => false, 'exception' => $e];
        }

        return ['template' => $template, 'file' => $file, 'valid' => true];
    }

    
class TwigNodeProvider
{
    public static function getModule($content)
    {
        return new ModuleNode(
            new ConstantExpression($content, 0),
            null,
            new ArrayExpression([], 0),
            new ArrayExpression([], 0),
            new ArrayExpression([], 0),
            null,
            new Source('', '')
        );
    }

    public static function getTransFilter($message$domain = null, $arguments = null)
    {
        if (!$arguments) {
            $arguments = $domain ? [
                new ArrayExpression([], 0),
                new ConstantExpression($domain, 0),
            ] : [];
        }

        
$this->prefix = $prefix;
    }

    /** * @return void */
    protected function extractTemplate(string $template, MessageCatalogue $catalogue)
    {
        $visitor = $this->twig->getExtension(TranslationExtension::class)->getTranslationNodeVisitor();
        $visitor->enable();

        $this->twig->parse($this->twig->tokenize(new Source($template, '')));

        foreach ($visitor->getMessages() as $message) {
            $catalogue->set(trim($message[0])$this->prefix.trim($message[0])$message[1] ?: $this->defaultDomain);
        }

        $visitor->disable();
    }

    protected function canBeExtracted(string $file): bool
    {
        return $this->isFile($file) && 'twig' === pathinfo($file, \PATHINFO_EXTENSION);
    }
class RoutingExtensionTest extends TestCase
{
    /** * @dataProvider getEscapingTemplates */
    public function testEscaping($template$mustBeEscaped)
    {
        $twig = new Environment($this->createMock(LoaderInterface::class)['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);
        $twig->addExtension(new RoutingExtension($this->createMock(UrlGeneratorInterface::class)));

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

        $this->assertSame($mustBeEscaped$nodes->getNode('body')->getNode(0)->getNode('expr') instanceof FilterExpression);
    }

    public static function getEscapingTemplates()
    {
        return [
            ['{{ path("foo") }}', false],
            ['{{ path("foo", {}) }}', false],
            ['{{ path("foo", { foo: "foo" }) }}', false],
            ['{{ path("foo", foo) }}', true],
            [

        return 'foo.twig';
    }

    public function getDebugInfo()
    {
        return [33 => 1, 34 => 2];
    }

    public function getSourceContext()
    {
        return new Twig\Source(" foo bar\n twig source\n\n", 'foo.twig', $this->path ?: __FILE__);
    }
}
Home | Imprint | This part of the site doesn't use cookies.