3487dd62489ee2071349253b2f7541356f06df1d
[yaffs-website] / vendor / symfony / translation / Tests / Extractor / PhpExtractorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Translation\Tests\Extractor;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\Extractor\PhpExtractor;
16 use Symfony\Component\Translation\MessageCatalogue;
17
18 class PhpExtractorTest extends TestCase
19 {
20     /**
21      * @dataProvider resourcesProvider
22      *
23      * @param array|string $resource
24      */
25     public function testExtraction($resource)
26     {
27         // Arrange
28         $extractor = new PhpExtractor();
29         $extractor->setPrefix('prefix');
30         $catalogue = new MessageCatalogue('en');
31
32         // Act
33         $extractor->extract($resource, $catalogue);
34
35         $expectedHeredoc = <<<EOF
36 heredoc key with whitespace and escaped \$\n sequences
37 EOF;
38         $expectedNowdoc = <<<'EOF'
39 nowdoc key with whitespace and nonescaped \$\n sequences
40 EOF;
41         // Assert
42         $expectedCatalogue = array(
43             'messages' => array(
44                 'single-quoted key' => 'prefixsingle-quoted key',
45                 'double-quoted key' => 'prefixdouble-quoted key',
46                 'heredoc key' => 'prefixheredoc key',
47                 'nowdoc key' => 'prefixnowdoc key',
48                 "double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences",
49                 'single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \$\n\' sequences',
50                 'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"',
51                 $expectedHeredoc => 'prefix'.$expectedHeredoc,
52                 $expectedNowdoc => 'prefix'.$expectedNowdoc,
53                 '{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples' => 'prefix{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
54             ),
55             'not_messages' => array(
56                 'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',
57                 'other-domain-test-no-params-long-array' => 'prefixother-domain-test-no-params-long-array',
58                 'other-domain-test-params-short-array' => 'prefixother-domain-test-params-short-array',
59                 'other-domain-test-params-long-array' => 'prefixother-domain-test-params-long-array',
60                 'other-domain-test-trans-choice-short-array-%count%' => 'prefixother-domain-test-trans-choice-short-array-%count%',
61                 'other-domain-test-trans-choice-long-array-%count%' => 'prefixother-domain-test-trans-choice-long-array-%count%',
62                 'typecast' => 'prefixtypecast',
63                 'msg1' => 'prefixmsg1',
64                 'msg2' => 'prefixmsg2',
65             ),
66         );
67         $actualCatalogue = $catalogue->all();
68
69         $this->assertEquals($expectedCatalogue, $actualCatalogue);
70     }
71
72     public function resourcesProvider()
73     {
74         $directory = __DIR__.'/../fixtures/extractor/';
75         $splFiles = array();
76         foreach (new \DirectoryIterator($directory) as $fileInfo) {
77             if ($fileInfo->isDot()) {
78                 continue;
79             }
80             if ('translation.html.php' === $fileInfo->getBasename()) {
81                 $phpFile = $fileInfo->getPathname();
82             }
83             $splFiles[] = $fileInfo->getFileInfo();
84         }
85
86         return array(
87             array($directory),
88             array($phpFile),
89             array(glob($directory.'*')),
90             array($splFiles),
91             array(new \ArrayObject(glob($directory.'*'))),
92             array(new \ArrayObject($splFiles)),
93         );
94     }
95 }