1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
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 Translation\Extractor\Tests\Smoke; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Finder\Finder; |
15
|
|
|
use Translation\Extractor\Extractor; |
16
|
|
|
use Translation\Extractor\FileExtractor\PHPFileExtractor; |
17
|
|
|
use Translation\Extractor\FileExtractor\TwigFileExtractor; |
18
|
|
|
use Translation\Extractor\Model\SourceCollection; |
19
|
|
|
use Translation\Extractor\Tests\Functional\Visitor\Twig\TwigEnvironmentFactory; |
20
|
|
|
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans; |
21
|
|
|
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice; |
22
|
|
|
use Translation\Extractor\Visitor\Php\Symfony\FlashMessage; |
23
|
|
|
use Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices; |
24
|
|
|
use Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit; |
25
|
|
|
use Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit; |
26
|
|
|
use Translation\Extractor\Visitor\Twig\TwigVisitor; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Smoke test to make sure no extractor throws exceptions. |
30
|
|
|
* |
31
|
|
|
* @author Tobias Nyholm <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class AllExtractorsTest extends \PHPUnit_Framework_TestCase |
34
|
|
|
{ |
35
|
1 |
|
public function testNoException() |
36
|
|
|
{ |
37
|
1 |
|
$extractor = new Extractor(); |
38
|
1 |
|
$extractor->addFileExtractor($this->getPHPFileExtractor()); |
39
|
1 |
|
$extractor->addFileExtractor($this->getTwigFileExtractor()); |
40
|
|
|
|
41
|
1 |
|
$finder = new Finder(); |
42
|
1 |
|
$finder->in(dirname(__DIR__)); |
43
|
|
|
|
44
|
1 |
|
$sc = $extractor->extract($finder); |
45
|
1 |
|
$this->translationExists($sc, 'trans.issue_34'); |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Assert that a translation key exists in source collection. |
50
|
|
|
* |
51
|
|
|
* @param SourceCollection $sc |
52
|
|
|
* @param $translationKey |
53
|
|
|
* @param string $message |
54
|
|
|
*/ |
55
|
1 |
|
private function translationExists(SourceCollection $sc, $translationKey, $message = null) |
56
|
|
|
{ |
57
|
1 |
|
if (empty($message)) { |
58
|
1 |
|
$message = sprintf('Tried to find "%s" but failed', $translationKey); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
1 |
|
$found = false; |
62
|
1 |
|
foreach ($sc as $source) { |
63
|
1 |
|
if ($translationKey === $source->getMessage()) { |
64
|
1 |
|
$found = true; |
65
|
1 |
|
break; |
66
|
|
|
} |
67
|
1 |
|
} |
68
|
|
|
|
69
|
1 |
|
$this->assertTrue($found, $message); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return PHPFileExtractor |
74
|
|
|
*/ |
75
|
1 |
|
private function getPHPFileExtractor() |
76
|
|
|
{ |
77
|
1 |
|
$file = new PHPFileExtractor(); |
78
|
1 |
|
$file->addVisitor(new ContainerAwareTrans()); |
79
|
1 |
|
$file->addVisitor(new ContainerAwareTransChoice()); |
80
|
1 |
|
$file->addVisitor(new FlashMessage()); |
81
|
1 |
|
$file->addVisitor(new FormTypeChoices()); |
82
|
1 |
|
$file->addVisitor(new FormTypeLabelExplicit()); |
83
|
1 |
|
$file->addVisitor(new FormTypeLabelImplicit()); |
84
|
|
|
|
85
|
1 |
|
return $file; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return TwigFileExtractor |
90
|
|
|
*/ |
91
|
1 |
|
private function getTwigFileExtractor() |
92
|
|
|
{ |
93
|
1 |
|
$file = new TwigFileExtractor(TwigEnvironmentFactory::create()); |
94
|
1 |
|
$file->addVisitor(TwigVisitor::create()); |
95
|
|
|
|
96
|
1 |
|
return $file; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|