-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathAnnotatedRouteControllerLoaderTest.php
More file actions
111 lines (85 loc) · 4.85 KB
/
AnnotatedRouteControllerLoaderTest.php
File metadata and controls
111 lines (85 loc) · 4.85 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
<?php
namespace BeSimple\I18nRoutingBundle\Tests\Routing\Loader;
use BeSimple\I18nRoutingBundle\Routing\Loader\AnnotatedRouteControllerLoader;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
class AnnotatedRouteControllerLoaderTest extends \PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
if (!method_exists('Symfony\Component\Routing\Loader\AnnotationClassLoader', 'getGlobals')) {
self::markTestSkipped('Unsupported symfony version 2.5 or greater is required.');
}
}
public function testRoutesWithoutLocales()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');
$rc = $loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\NoLocalesController');
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $rc);
$this->assertContainsOnlyInstancesOf('Symfony\Component\Routing\Route', $rc);
$this->assertCount(2, $rc);
$this->assertEquals('/base/', $rc->get('index')->getPath());
$this->assertEquals('/base/new', $rc->get('new')->getPath());
}
public function testRoutesWithLocales()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');
$rc = $loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\NoPrefixController');
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $rc);
$this->assertContainsOnlyInstancesOf('Symfony\Component\Routing\Route', $rc);
$this->assertCount(4, $rc);
$this->assertEquals('/', $rc->get('besimple_i18nrouting_tests_fixtures_noprefix_index.be-simple-i18n.en')->getPath());
$this->assertEquals('/nl/', $rc->get('besimple_i18nrouting_tests_fixtures_noprefix_index.be-simple-i18n.nl')->getPath());
$this->assertEquals('/new', $rc->get('new_action.be-simple-i18n.en')->getPath());
$this->assertEquals('/nieuw', $rc->get('new_action.be-simple-i18n.nl')->getPath());
}
public function testRoutesWithPrefixedLocales()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');
$rc = $loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\PrefixedLocalesController');
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $rc);
$this->assertContainsOnlyInstancesOf('Symfony\Component\Routing\Route', $rc);
$this->assertCount(7, $rc);
$this->assertEquals('/en/', $rc->get('idx.be-simple-i18n.en')->getPath());
$this->assertEquals('/nl/', $rc->get('idx.be-simple-i18n.nl')->getPath());
$this->assertEquals('/fr/', $rc->get('idx.be-simple-i18n.fr')->getPath());
$this->assertEquals('/en/edit', $rc->get('edit.be-simple-i18n.en')->getPath());
$this->assertEquals('/en/new', $rc->get('new.be-simple-i18n.en')->getPath());
$this->assertEquals('/nl/nieuw', $rc->get('new.be-simple-i18n.nl')->getPath());
$this->assertEquals('/fr/nouveau', $rc->get('new.be-simple-i18n.fr')->getPath());
}
public function testRoutesWithStringPrefix()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');
$rc = $loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\PlainPrefixController');
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $rc);
$this->assertContainsOnlyInstancesOf('Symfony\Component\Routing\Route', $rc);
$this->assertCount(3, $rc);
$this->assertEquals('/color/', $rc->get('idx.be-simple-i18n.en')->getPath());
$this->assertEquals('/color/test', $rc->get('idx.be-simple-i18n.test')->getPath());
$this->assertEquals('/color/plain', $rc->get('new')->getPath());
}
/**
* @expectedException \BeSimple\I18nRoutingBundle\Routing\Exception\MissingLocaleException
*/
public function testRoutesMissingPrefixLocale()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');
$loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\MissingPrefixedLocalesController');
}
/**
* @expectedException \BeSimple\I18nRoutingBundle\Routing\Exception\MissingRouteLocaleException
*/
public function testRoutesMissingLocales()
{
$loader = new AnnotatedRouteControllerLoader(new AnnotationReader());
AnnotationRegistry::registerLoader('class_exists');
$loader->load('BeSimple\I18nRoutingBundle\Tests\Fixtures\Controller\MissingLocalesController');
}
}