leaveNode example

private static string $domain = 'domain';

    /** @dataProvider getDefaultDomainAssignmentTestData */
    public function testDefaultDomainAssignment(Node $node)
    {
        $env = new Environment($this->createMock(LoaderInterface::class)['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
        $visitor = new TranslationDefaultDomainNodeVisitor();

        // visit trans_default_domain tag         $defaultDomain = TwigNodeProvider::getTransDefaultDomainTag(self::$domain);
        $visitor->enterNode($defaultDomain$env);
        $visitor->leaveNode($defaultDomain$env);

        // visit tested node         $enteredNode = $visitor->enterNode($node$env);
        $leavedNode = $visitor->leaveNode($node$env);
        $this->assertSame($node$enteredNode);
        $this->assertSame($node$leavedNode);

        // extracting tested node messages         $visitor = new TranslationNodeVisitor();
        $visitor->enable();
        $visitor->enterNode($node$env);
        
use Twig\Node\Node;

class TranslationNodeVisitorTest extends TestCase
{
    /** @dataProvider getMessagesExtractionTestData */
    public function testMessagesExtraction(Node $node, array $expectedMessages)
    {
        $env = new Environment($this->createMock(LoaderInterface::class)['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
        $visitor = new TranslationNodeVisitor();
        $visitor->enable();
        $visitor->enterNode($node$env);
        $visitor->leaveNode($node$env);
        $this->assertEquals($expectedMessages$visitor->getMessages());
    }

    public function testMessageExtractionWithInvalidDomainNode()
    {
        $message = 'new key';

        $node = new FilterExpression(
            new ConstantExpression($message, 0),
            new ConstantExpression('trans', 0),
            new Node([
                
foreach ($node as $k => $n) {
            if (null !== $m = $this->traverseForVisitor($visitor$n)) {
                if ($m !== $n) {
                    $node->setNode($k$m);
                }
            } else {
                $node->removeNode($k);
            }
        }

        return $visitor->leaveNode($node$this->env);
    }
}
Home | Imprint | This part of the site doesn't use cookies.