-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathI18nRouteGeneratorTest.php
More file actions
127 lines (108 loc) · 4.42 KB
/
I18nRouteGeneratorTest.php
File metadata and controls
127 lines (108 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace BeSimple\I18nRoutingBundle\Tests\Routing\RouteGenerator;
use BeSimple\I18nRoutingBundle\Routing\RouteGenerator\I18nRouteGenerator;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class I18nRouteGeneratorTest extends \PHPUnit_Framework_TestCase
{
public function testGenerateRoutes()
{
$generator = new I18nRouteGenerator();
$collection = $generator->generateRoutes('test', array('en' => '/en/', 'nl' => '/nl/'), new Route(''));
$this->assertEquals(
array(
'test.be-simple-i18n.en' => new Route('/en/', array('_locale' => 'en')),
'test.be-simple-i18n.nl' => new Route('/nl/', array('_locale' => 'nl')),
),
$collection->all()
);
}
public function testGenerateRoutesUsesNameInflector()
{
$inflector = $this->getMock('BeSimple\I18nRoutingBundle\Routing\RouteGenerator\NameInflector\RouteNameInflectorInterface');
$inflector
->expects($this->exactly(2))
->method('inflect')
->willReturnMap(array(
array('test', 'en', 'english'),
array('test', 'nl', 'dutch')
));
$generator = new I18nRouteGenerator($inflector);
$collection = $generator->generateRoutes('test', array('en' => '/en/', 'nl' => '/nl/'), new Route(''));
$this->assertEquals(
array(
'english' => new Route('/en/', array('_locale' => 'en')),
'dutch' => new Route('/nl/', array('_locale' => 'nl')),
),
$collection->all()
);
}
public function testGenerateCollectionNormalPrefix()
{
$collection = new RouteCollection();
$collection->add('test', new Route('/test'));
$collection->add('probe', new Route('/probe', array('_locale' => 'de')));
$generator = new I18nRouteGenerator();
$localizedCollection = $generator->generateCollection(
'/prefix',
$collection
);
$this->assertEquals(
array(
'test' => new Route('/prefix/test'),
'probe' => new Route('/prefix/probe', array('_locale' => 'de'))
),
$localizedCollection->all()
);
}
public function testGenerateCollectionLocalizeRoutes()
{
$collection = new RouteCollection();
$collection->add('test', new Route('/test'));
$collection->add('test_localized', new Route('/testing', array('_locale' => 'en')));
$generator = new I18nRouteGenerator();
$localizedCollection = $generator->generateCollection(
array('en' => '/en/', 'nl' => '/nl/'),
$collection
);
$this->assertEquals(
array(
'test.be-simple-i18n.en' => new Route('/en/test', array('_locale' => 'en')),
'test.be-simple-i18n.nl' => new Route('/nl/test', array('_locale' => 'nl')),
'test_localized' => new Route('/en/testing', array('_locale' => 'en')),
),
$localizedCollection->all()
);
}
public function testGenerateCollectionLocalizeRoutesWithMissingPrefixLocale()
{
$collection = new RouteCollection();
$collection->add('test', new Route('/probe', array('_locale' => 'de')));
$generator = new I18nRouteGenerator();
$this->setExpectedException('BeSimple\I18nRoutingBundle\Routing\Exception\MissingRouteLocaleException');
$generator->generateCollection(
array('en' => '/en/'),
$collection
);
}
public function testGenerateCollectionLocaleReplace()
{
$collection = new RouteCollection();
$collection->add('simple', new Route('/simple'));
$collection->add('test.en', new Route('/testing', array('_locale' => 'en')));
$collection->add('test.nl', new Route('/testen', array('_locale' => 'nl')));
$generator = new I18nRouteGenerator();
$localizedCollection = $generator->generateCollection(
'/{_locale}/',
$collection
);
$this->assertEquals(
array(
'simple' => new Route('/{_locale}/simple'),
'test.en' => new Route('/en/testing', array('_locale' => 'en')),
'test.nl' => new Route('/nl/testen', array('_locale' => 'nl')),
),
$localizedCollection->all()
);
}
}