|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\Component\Translation\Tests\Extractor\Visitor; |
| 4 | + |
| 5 | +use PhpParser\NodeVisitor; |
| 6 | +use Symfony\Component\Translation\Extractor\Visitor\TransMethodVisitor; |
| 7 | +use Symfony\Component\Translation\MessageCatalogue; |
| 8 | + |
| 9 | +class TransMethodVisitorTest extends AbstractVisitorTest |
| 10 | +{ |
| 11 | + private const FIXTURES_FOLDER = __DIR__ . '/../../Fixtures/extractor-php-ast/trans-method-visitor/'; |
| 12 | + public const OTHER_DOMAIN = 'not_messages'; |
| 13 | + |
| 14 | + public function getVisitor(): NodeVisitor |
| 15 | + { |
| 16 | + return new TransMethodVisitor(); |
| 17 | + } |
| 18 | + |
| 19 | + public function getResource(): iterable|string |
| 20 | + { |
| 21 | + return self::FIXTURES_FOLDER; |
| 22 | + } |
| 23 | + |
| 24 | + public function assertCatalogue(MessageCatalogue $catalogue): void |
| 25 | + { |
| 26 | + $expectedHeredoc = <<<EOF |
| 27 | +heredoc key with whitespace and escaped \$\n sequences |
| 28 | +EOF; |
| 29 | + $expectedNowdoc = <<<'EOF' |
| 30 | +nowdoc key with whitespace and nonescaped \$\n sequences |
| 31 | +EOF; |
| 32 | + |
| 33 | + $this->assertEquals( |
| 34 | + [ |
| 35 | + 'messages' => [ |
| 36 | + 'single-quoted key' => 'prefixsingle-quoted key', |
| 37 | + 'double-quoted key' => 'prefixdouble-quoted key', |
| 38 | + 'heredoc key' => 'prefixheredoc key', |
| 39 | + 'nowdoc key' => 'prefixnowdoc key', |
| 40 | + "double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences", |
| 41 | + 'single-quoted key with whitespace and nonescaped \\$\\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \\$\\n\' sequences', |
| 42 | + $expectedHeredoc => 'prefix'.$expectedHeredoc, |
| 43 | + $expectedNowdoc => 'prefix'.$expectedNowdoc, |
| 44 | + 'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"', |
| 45 | + 'concatenated message with heredoc and nowdoc' => 'prefixconcatenated message with heredoc and nowdoc', |
| 46 | + 'default domain' => 'prefixdefault domain', |
| 47 | + 'mix-named-arguments' => 'prefixmix-named-arguments', |
| 48 | + 'mix-named-arguments-locale' => 'prefixmix-named-arguments-locale', |
| 49 | + 'mix-named-arguments-without-domain' => 'prefixmix-named-arguments-without-domain', |
| 50 | + "heredoc\nindented\n further" => "prefixheredoc\nindented\n further", |
| 51 | + "nowdoc\nindented\n further" => "prefixnowdoc\nindented\n further", |
| 52 | + 'translatable-short single-quoted key' => 'prefixtranslatable-short single-quoted key', |
| 53 | + 'translatable-short double-quoted key' => 'prefixtranslatable-short double-quoted key', |
| 54 | + 'translatable-short heredoc key' => 'prefixtranslatable-short heredoc key', |
| 55 | + 'translatable-short nowdoc key' => 'prefixtranslatable-short nowdoc key', |
| 56 | + "translatable-short double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixtranslatable-short double-quoted key with whitespace and escaped \$\n\" sequences", |
| 57 | + 'translatable-short single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixtranslatable-short single-quoted key with whitespace and nonescaped \$\n\' sequences', |
| 58 | + 'translatable-short single-quoted key with "quote mark at the end"' => 'prefixtranslatable-short single-quoted key with "quote mark at the end"', |
| 59 | + 'translatable-short '.$expectedHeredoc => 'prefixtranslatable-short '.$expectedHeredoc, |
| 60 | + 'translatable-short '.$expectedNowdoc => 'prefixtranslatable-short '.$expectedNowdoc, |
| 61 | + 'translatable-short concatenated message with heredoc and nowdoc' => 'prefixtranslatable-short concatenated message with heredoc and nowdoc', |
| 62 | + 'translatable-short default domain' => 'prefixtranslatable-short default domain', |
| 63 | + 'translatable-short-fqn single-quoted key' => 'prefixtranslatable-short-fqn single-quoted key', |
| 64 | + 'translatable-short-fqn double-quoted key' => 'prefixtranslatable-short-fqn double-quoted key', |
| 65 | + 'translatable-short-fqn heredoc key' => 'prefixtranslatable-short-fqn heredoc key', |
| 66 | + 'translatable-short-fqn nowdoc key' => 'prefixtranslatable-short-fqn nowdoc key', |
| 67 | + "translatable-short-fqn double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixtranslatable-short-fqn double-quoted key with whitespace and escaped \$\n\" sequences", |
| 68 | + 'translatable-short-fqn single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixtranslatable-short-fqn single-quoted key with whitespace and nonescaped \$\n\' sequences', |
| 69 | + 'translatable-short-fqn single-quoted key with "quote mark at the end"' => 'prefixtranslatable-short-fqn single-quoted key with "quote mark at the end"', |
| 70 | + 'translatable-short-fqn '.$expectedHeredoc => 'prefixtranslatable-short-fqn '.$expectedHeredoc, |
| 71 | + 'translatable-short-fqn '.$expectedNowdoc => 'prefixtranslatable-short-fqn '.$expectedNowdoc, |
| 72 | + 'translatable-short-fqn concatenated message with heredoc and nowdoc' => 'prefixtranslatable-short-fqn concatenated message with heredoc and nowdoc', |
| 73 | + 'translatable-short-fqn default domain' => 'prefixtranslatable-short-fqn default domain', |
| 74 | + ], |
| 75 | + 'not_messages' => [ |
| 76 | + 'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array', |
| 77 | + 'other-domain-test-no-params-long-array' => 'prefixother-domain-test-no-params-long-array', |
| 78 | + 'other-domain-test-params-short-array' => 'prefixother-domain-test-params-short-array', |
| 79 | + 'other-domain-test-params-long-array' => 'prefixother-domain-test-params-long-array', |
| 80 | + 'typecast' => 'prefixtypecast', |
| 81 | + 'ordered-named-arguments-in-trans-method' => 'prefixordered-named-arguments-in-trans-method', |
| 82 | + 'disordered-named-arguments-in-trans-method' => 'prefixdisordered-named-arguments-in-trans-method', |
| 83 | + 'variable-assignation-inlined-in-trans-method-call1' => 'prefixvariable-assignation-inlined-in-trans-method-call1', |
| 84 | + 'variable-assignation-inlined-in-trans-method-call2' => 'prefixvariable-assignation-inlined-in-trans-method-call2', |
| 85 | + 'variable-assignation-inlined-in-trans-method-call3' => 'prefixvariable-assignation-inlined-in-trans-method-call3', |
| 86 | + 'variable-assignation-inlined-with-named-arguments-in-trans-method' => 'prefixvariable-assignation-inlined-with-named-arguments-in-trans-method', |
| 87 | + 'mix-named-arguments-without-parameters' => 'prefixmix-named-arguments-without-parameters', |
| 88 | + 'mix-named-arguments-disordered' => 'prefixmix-named-arguments-disordered', |
| 89 | + 'const-domain' => 'prefixconst-domain', |
| 90 | + 'translatable-short other-domain-test-no-params-short-array' => 'prefixtranslatable-short other-domain-test-no-params-short-array', |
| 91 | + 'translatable-short other-domain-test-no-params-long-array' => 'prefixtranslatable-short other-domain-test-no-params-long-array', |
| 92 | + 'translatable-short other-domain-test-params-short-array' => 'prefixtranslatable-short other-domain-test-params-short-array', |
| 93 | + 'translatable-short other-domain-test-params-long-array' => 'prefixtranslatable-short other-domain-test-params-long-array', |
| 94 | + 'translatable-short typecast' => 'prefixtranslatable-short typecast', |
| 95 | + 'translatable-short-fqn other-domain-test-no-params-short-array' => 'prefixtranslatable-short-fqn other-domain-test-no-params-short-array', |
| 96 | + 'translatable-short-fqn other-domain-test-no-params-long-array' => 'prefixtranslatable-short-fqn other-domain-test-no-params-long-array', |
| 97 | + 'translatable-short-fqn other-domain-test-params-short-array' => 'prefixtranslatable-short-fqn other-domain-test-params-short-array', |
| 98 | + 'translatable-short-fqn other-domain-test-params-long-array' => 'prefixtranslatable-short-fqn other-domain-test-params-long-array', |
| 99 | + 'translatable-short-fqn typecast' => 'prefixtranslatable-short-fqn typecast', |
| 100 | + ], |
| 101 | + ], |
| 102 | + $catalogue->all(), |
| 103 | + ); |
| 104 | + |
| 105 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translation.html.php:2']], $catalogue->getMetadata('single-quoted key')); |
| 106 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translation.html.php:37']], $catalogue->getMetadata('other-domain-test-no-params-short-array', 'not_messages')); |
| 107 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translation-73.html.php:8']], $catalogue->getMetadata("nowdoc\nindented\n further")); |
| 108 | + |
| 109 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translatable-short.html.php:2']], $catalogue->getMetadata('translatable-short single-quoted key')); |
| 110 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translatable-short.html.php:37']], $catalogue->getMetadata('translatable-short other-domain-test-no-params-short-array', 'not_messages')); |
| 111 | + |
| 112 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translatable-short-fqn.html.php:2']], $catalogue->getMetadata('translatable-short-fqn single-quoted key')); |
| 113 | + $this->assertEquals(['sources' => [self::FIXTURES_FOLDER . 'translatable-short-fqn.html.php:37']], $catalogue->getMetadata('translatable-short-fqn other-domain-test-no-params-short-array', 'not_messages')); |
| 114 | + } |
| 115 | +} |
0 commit comments