Skip to content

Commit 7620bf4

Browse files
committed
added tests
1 parent 4d35bf3 commit 7620bf4

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"symfony/translation": "^3.4 || ^4.3 || ^5.0",
2121
"symfony/validator": "^3.4 || ^4.3 || ^5.0",
2222
"symfony/twig-bridge": "^3.4 || ^4.3 || ^5.0",
23-
"phpunit/phpunit": "^8.4"
23+
"phpunit/phpunit": "^8.4",
24+
"knplabs/knp-menu": "^3.1"
2425
},
2526
"autoload": {
2627
"psr-4": {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\Functional\Visitor\Php\Knp;
13+
14+
use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest;
15+
use Translation\Extractor\Tests\Resources;
16+
use Translation\Extractor\Visitor\Php\Knp\Menu\ItemLabel;
17+
use Translation\Extractor\Visitor\Php\Knp\Menu\LinkTitle;
18+
19+
final class MenuTest extends BasePHPVisitorTest
20+
{
21+
public function testExtractOne()
22+
{
23+
$collection = $this->getSourceLocations(new ItemLabel(),
24+
Resources\Php\Knp\Menu::class);
25+
26+
$this->assertCount(4, $collection);
27+
$this->assertEquals('my.first.label', $collection->get(0)->getMessage());
28+
$this->assertEquals('foo', $collection->get(1)->getMessage());
29+
$this->assertEquals('foo.first.label', $collection->get(2)->getMessage());
30+
$this->assertEquals('foo.second.label', $collection->get(3)->getMessage());
31+
}
32+
33+
public function testExtractTwo()
34+
{
35+
$collection = $this->getSourceLocations(new LinkTitle(),
36+
Resources\Php\Knp\Menu::class);
37+
38+
$this->assertCount(2, $collection);
39+
$this->assertEquals('my.first.title', $collection->get(0)->getMessage());
40+
$this->assertEquals('my.second.title', $collection->get(1)->getMessage());
41+
}
42+
}

tests/Resources/Php/Knp/Menu.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Translation\Extractor\Tests\Resources\Php\Knp;
4+
5+
use Knp\Menu\MenuFactory;
6+
use Knp\Menu\ItemInterface;
7+
8+
class Menu
9+
{
10+
public function buildMenu(): ItemInterface
11+
{
12+
$factory = new MenuFactory();
13+
$menu = $factory->createItem('A menu');
14+
$menu->addChild('my.first.label', ['uri' => '/']);
15+
16+
$menu->addChild('foo', ['uri' => '/']);
17+
$menu['foo']->setLabel('foo.first.label');
18+
$menu->getChild('foo')->setLabel('foo.second.label');
19+
20+
$menu['foo']->setLinkAttribute('title', 'my.first.title');
21+
$menu->getChild('foo')->setLinkAttribute('title', 'my.second.title');
22+
23+
return $menu;
24+
}
25+
}

tests/Smoke/AllExtractorsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Translation\Extractor\Model\SourceCollection;
2121
use Translation\Extractor\Model\SourceLocation;
2222
use Translation\Extractor\Tests\Functional\Visitor\Twig\TwigEnvironmentFactory;
23+
use Translation\Extractor\Visitor\Php\Knp\Menu\ItemLabel;
24+
use Translation\Extractor\Visitor\Php\Knp\Menu\LinkTitle;
2325
use Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor;
2426
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans;
2527
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice;
@@ -153,6 +155,8 @@ private function getPHPFileExtractor(): PHPFileExtractor
153155
$file->addVisitor(new FormTypeTitle());
154156
$file->addVisitor(new SourceLocationContainerVisitor());
155157
$file->addVisitor(new TranslateAnnotationVisitor());
158+
$file->addVisitor(new ItemLabel());
159+
$file->addVisitor(new LinkTitle());
156160

157161
return $file;
158162
}

0 commit comments

Comments
 (0)