diff options
author | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
Diffstat (limited to 'vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader')
8 files changed, 607 insertions, 0 deletions
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php new file mode 100644 index 00000000..c927ae4a --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php | |||
@@ -0,0 +1,38 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | protected function setUp() | ||
17 | { | ||
18 | if (!class_exists('Doctrine\\Common\\Version')) { | ||
19 | $this->markTestSkipped('Doctrine is not available.'); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | public function getReader() | ||
24 | { | ||
25 | return $this->getMockBuilder('Doctrine\Common\Annotations\Reader') | ||
26 | ->disableOriginalConstructor() | ||
27 | ->getMock() | ||
28 | ; | ||
29 | } | ||
30 | |||
31 | public function getClassLoader($reader) | ||
32 | { | ||
33 | return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader') | ||
34 | ->setConstructorArgs(array($reader)) | ||
35 | ->getMockForAbstractClass() | ||
36 | ; | ||
37 | } | ||
38 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php new file mode 100644 index 00000000..31c43f58 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php | |||
@@ -0,0 +1,119 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest | ||
15 | { | ||
16 | protected $loader; | ||
17 | |||
18 | protected function setUp() | ||
19 | { | ||
20 | parent::setUp(); | ||
21 | |||
22 | $this->reader = $this->getReader(); | ||
23 | $this->loader = $this->getClassLoader($this->reader); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * @expectedException \InvalidArgumentException | ||
28 | */ | ||
29 | public function testLoadMissingClass() | ||
30 | { | ||
31 | $this->loader->load('MissingClass'); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * @expectedException \InvalidArgumentException | ||
36 | */ | ||
37 | public function testLoadAbstractClass() | ||
38 | { | ||
39 | $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass'); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * @dataProvider provideTestSupportsChecksResource | ||
44 | */ | ||
45 | public function testSupportsChecksResource($resource, $expectedSupports) | ||
46 | { | ||
47 | $this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable'); | ||
48 | } | ||
49 | |||
50 | public function provideTestSupportsChecksResource() | ||
51 | { | ||
52 | return array( | ||
53 | array('class', true), | ||
54 | array('\fully\qualified\class\name', true), | ||
55 | array('namespaced\class\without\leading\slash', true), | ||
56 | array('ÿClassWithLegalSpecialCharacters', true), | ||
57 | array('5', false), | ||
58 | array('foo.foo', false), | ||
59 | array(null, false), | ||
60 | ); | ||
61 | } | ||
62 | |||
63 | public function testSupportsChecksTypeIfSpecified() | ||
64 | { | ||
65 | $this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified'); | ||
66 | $this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified'); | ||
67 | } | ||
68 | |||
69 | public function getLoadTests() | ||
70 | { | ||
71 | return array( | ||
72 | array( | ||
73 | 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', | ||
74 | array('name'=>'route1'), | ||
75 | array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') | ||
76 | ), | ||
77 | array( | ||
78 | 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', | ||
79 | array('name'=>'route1', 'defaults' => array('arg2' => 'foo')), | ||
80 | array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') | ||
81 | ), | ||
82 | ); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * @dataProvider getLoadTests | ||
87 | */ | ||
88 | public function testLoad($className, $routeDatas = array(), $methodArgs = array()) | ||
89 | { | ||
90 | $routeDatas = array_replace(array( | ||
91 | 'name' => 'route', | ||
92 | 'path' => '/', | ||
93 | 'requirements' => array(), | ||
94 | 'options' => array(), | ||
95 | 'defaults' => array(), | ||
96 | 'schemes' => array(), | ||
97 | 'methods' => array(), | ||
98 | ), $routeDatas); | ||
99 | |||
100 | $this->reader | ||
101 | ->expects($this->once()) | ||
102 | ->method('getMethodAnnotations') | ||
103 | ->will($this->returnValue(array($this->getAnnotatedRoute($routeDatas)))) | ||
104 | ; | ||
105 | $routeCollection = $this->loader->load($className); | ||
106 | $route = $routeCollection->get($routeDatas['name']); | ||
107 | |||
108 | $this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation'); | ||
109 | $this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation'); | ||
110 | $this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation'); | ||
111 | $this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation'); | ||
112 | } | ||
113 | |||
114 | private function getAnnotatedRoute($datas) | ||
115 | { | ||
116 | return new \Symfony\Component\Routing\Annotation\Route($datas); | ||
117 | } | ||
118 | |||
119 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php new file mode 100644 index 00000000..29126ba4 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php | |||
@@ -0,0 +1,53 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader; | ||
15 | use Symfony\Component\Config\FileLocator; | ||
16 | |||
17 | class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest | ||
18 | { | ||
19 | protected $loader; | ||
20 | protected $reader; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | parent::setUp(); | ||
25 | |||
26 | $this->reader = $this->getReader(); | ||
27 | $this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader)); | ||
28 | } | ||
29 | |||
30 | public function testLoad() | ||
31 | { | ||
32 | $this->reader->expects($this->exactly(2))->method('getClassAnnotation'); | ||
33 | |||
34 | $this->reader | ||
35 | ->expects($this->any()) | ||
36 | ->method('getMethodAnnotations') | ||
37 | ->will($this->returnValue(array())) | ||
38 | ; | ||
39 | |||
40 | $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses'); | ||
41 | } | ||
42 | |||
43 | public function testSupports() | ||
44 | { | ||
45 | $fixturesDir = __DIR__.'/../Fixtures'; | ||
46 | |||
47 | $this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable'); | ||
48 | $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
49 | |||
50 | $this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified'); | ||
51 | $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified'); | ||
52 | } | ||
53 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php new file mode 100644 index 00000000..f0a8a0e3 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php | |||
@@ -0,0 +1,47 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\AnnotationFileLoader; | ||
15 | use Symfony\Component\Config\FileLocator; | ||
16 | |||
17 | class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest | ||
18 | { | ||
19 | protected $loader; | ||
20 | protected $reader; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | parent::setUp(); | ||
25 | |||
26 | $this->reader = $this->getReader(); | ||
27 | $this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader)); | ||
28 | } | ||
29 | |||
30 | public function testLoad() | ||
31 | { | ||
32 | $this->reader->expects($this->once())->method('getClassAnnotation'); | ||
33 | |||
34 | $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'); | ||
35 | } | ||
36 | |||
37 | public function testSupports() | ||
38 | { | ||
39 | $fixture = __DIR__.'/../Fixtures/annotated.php'; | ||
40 | |||
41 | $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable'); | ||
42 | $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
43 | |||
44 | $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified'); | ||
45 | $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified'); | ||
46 | } | ||
47 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php new file mode 100644 index 00000000..64d1b086 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php | |||
@@ -0,0 +1,55 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\Loader\ClosureLoader; | ||
15 | use Symfony\Component\Routing\Route; | ||
16 | use Symfony\Component\Routing\RouteCollection; | ||
17 | |||
18 | class ClosureLoaderTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
23 | $this->markTestSkipped('The "Config" component is not available'); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public function testSupports() | ||
28 | { | ||
29 | $loader = new ClosureLoader(); | ||
30 | |||
31 | $closure = function () {}; | ||
32 | |||
33 | $this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable'); | ||
34 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
35 | |||
36 | $this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified'); | ||
37 | $this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified'); | ||
38 | } | ||
39 | |||
40 | public function testLoad() | ||
41 | { | ||
42 | $loader = new ClosureLoader(); | ||
43 | |||
44 | $route = new Route('/'); | ||
45 | $routes = $loader->load(function () use ($route) { | ||
46 | $routes = new RouteCollection(); | ||
47 | |||
48 | $routes->add('foo', $route); | ||
49 | |||
50 | return $routes; | ||
51 | }); | ||
52 | |||
53 | $this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource'); | ||
54 | } | ||
55 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php new file mode 100644 index 00000000..18b166fc --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php | |||
@@ -0,0 +1,55 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\FileLocator; | ||
15 | use Symfony\Component\Routing\Loader\PhpFileLoader; | ||
16 | |||
17 | class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
22 | $this->markTestSkipped('The "Config" component is not available'); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function testSupports() | ||
27 | { | ||
28 | $loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); | ||
29 | |||
30 | $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable'); | ||
31 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
32 | |||
33 | $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified'); | ||
34 | $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified'); | ||
35 | } | ||
36 | |||
37 | public function testLoadWithRoute() | ||
38 | { | ||
39 | $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
40 | $routeCollection = $loader->load('validpattern.php'); | ||
41 | $routes = $routeCollection->all(); | ||
42 | |||
43 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
44 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
45 | |||
46 | foreach ($routes as $route) { | ||
47 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
48 | $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller')); | ||
49 | $this->assertSame('{locale}.example.com', $route->getHost()); | ||
50 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
51 | $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods()); | ||
52 | $this->assertEquals(array('https'), $route->getSchemes()); | ||
53 | } | ||
54 | } | ||
55 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php new file mode 100644 index 00000000..9f038c16 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php | |||
@@ -0,0 +1,127 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\FileLocator; | ||
15 | use Symfony\Component\Routing\Loader\XmlFileLoader; | ||
16 | use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader; | ||
17 | |||
18 | class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
23 | $this->markTestSkipped('The "Config" component is not available'); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public function testSupports() | ||
28 | { | ||
29 | $loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); | ||
30 | |||
31 | $this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable'); | ||
32 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
33 | |||
34 | $this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified'); | ||
35 | $this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified'); | ||
36 | } | ||
37 | |||
38 | public function testLoadWithRoute() | ||
39 | { | ||
40 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
41 | $routeCollection = $loader->load('validpattern.xml'); | ||
42 | $routes = $routeCollection->all(); | ||
43 | |||
44 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
45 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
46 | |||
47 | foreach ($routes as $route) { | ||
48 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
49 | $this->assertSame('{locale}.example.com', $route->getHost()); | ||
50 | $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller')); | ||
51 | $this->assertSame('\w+', $route->getRequirement('locale')); | ||
52 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
53 | $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods()); | ||
54 | $this->assertEquals(array('https'), $route->getSchemes()); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | public function testLoadWithNamespacePrefix() | ||
59 | { | ||
60 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
61 | $routeCollection = $loader->load('namespaceprefix.xml'); | ||
62 | |||
63 | $this->assertCount(1, $routeCollection->all(), 'One route is loaded'); | ||
64 | |||
65 | $route = $routeCollection->get('blog_show'); | ||
66 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
67 | $this->assertSame('{_locale}.example.com', $route->getHost()); | ||
68 | $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller')); | ||
69 | $this->assertSame('\w+', $route->getRequirement('slug')); | ||
70 | $this->assertSame('en|fr|de', $route->getRequirement('_locale')); | ||
71 | $this->assertSame(null, $route->getDefault('slug')); | ||
72 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
73 | } | ||
74 | |||
75 | public function testLoadWithImport() | ||
76 | { | ||
77 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
78 | $routeCollection = $loader->load('validresource.xml'); | ||
79 | $routes = $routeCollection->all(); | ||
80 | |||
81 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
82 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
83 | |||
84 | foreach ($routes as $route) { | ||
85 | $this->assertSame('/{foo}/blog/{slug}', $route->getPath()); | ||
86 | $this->assertSame('123', $route->getDefault('foo')); | ||
87 | $this->assertSame('\d+', $route->getRequirement('foo')); | ||
88 | $this->assertSame('bar', $route->getOption('foo')); | ||
89 | $this->assertSame('', $route->getHost()); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * @expectedException \InvalidArgumentException | ||
95 | * @dataProvider getPathsToInvalidFiles | ||
96 | */ | ||
97 | public function testLoadThrowsExceptionWithInvalidFile($filePath) | ||
98 | { | ||
99 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
100 | $loader->load($filePath); | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * @expectedException \InvalidArgumentException | ||
105 | * @dataProvider getPathsToInvalidFiles | ||
106 | */ | ||
107 | public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath) | ||
108 | { | ||
109 | $loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
110 | $loader->load($filePath); | ||
111 | } | ||
112 | |||
113 | public function getPathsToInvalidFiles() | ||
114 | { | ||
115 | return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml')); | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * @expectedException \InvalidArgumentException | ||
120 | * @expectedExceptionMessage Document types are not allowed. | ||
121 | */ | ||
122 | public function testDocTypeIsNotAllowed() | ||
123 | { | ||
124 | $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
125 | $loader->load('withdoctype.xml'); | ||
126 | } | ||
127 | } | ||
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php new file mode 100644 index 00000000..a3e934ce --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php | |||
@@ -0,0 +1,113 @@ | |||
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\Routing\Tests\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\FileLocator; | ||
15 | use Symfony\Component\Routing\Loader\YamlFileLoader; | ||
16 | use Symfony\Component\Config\Resource\FileResource; | ||
17 | |||
18 | class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | if (!class_exists('Symfony\Component\Config\FileLocator')) { | ||
23 | $this->markTestSkipped('The "Config" component is not available'); | ||
24 | } | ||
25 | |||
26 | if (!class_exists('Symfony\Component\Yaml\Yaml')) { | ||
27 | $this->markTestSkipped('The "Yaml" component is not available'); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | public function testSupports() | ||
32 | { | ||
33 | $loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator')); | ||
34 | |||
35 | $this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable'); | ||
36 | $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable'); | ||
37 | |||
38 | $this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified'); | ||
39 | $this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified'); | ||
40 | } | ||
41 | |||
42 | public function testLoadDoesNothingIfEmpty() | ||
43 | { | ||
44 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
45 | $collection = $loader->load('empty.yml'); | ||
46 | |||
47 | $this->assertEquals(array(), $collection->all()); | ||
48 | $this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources()); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * @expectedException \InvalidArgumentException | ||
53 | * @dataProvider getPathsToInvalidFiles | ||
54 | */ | ||
55 | public function testLoadThrowsExceptionWithInvalidFile($filePath) | ||
56 | { | ||
57 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
58 | $loader->load($filePath); | ||
59 | } | ||
60 | |||
61 | public function getPathsToInvalidFiles() | ||
62 | { | ||
63 | return array(array('nonvalid.yml'), array('nonvalid2.yml'), array('incomplete.yml'), array('nonvalidkeys.yml'), array('nonesense_resource_plus_path.yml'), array('nonesense_type_without_resource.yml')); | ||
64 | } | ||
65 | |||
66 | public function testLoadSpecialRouteName() | ||
67 | { | ||
68 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
69 | $routeCollection = $loader->load('special_route_name.yml'); | ||
70 | $route = $routeCollection->get('#$péß^a|'); | ||
71 | |||
72 | $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); | ||
73 | $this->assertSame('/true', $route->getPath()); | ||
74 | } | ||
75 | |||
76 | public function testLoadWithRoute() | ||
77 | { | ||
78 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
79 | $routeCollection = $loader->load('validpattern.yml'); | ||
80 | $routes = $routeCollection->all(); | ||
81 | |||
82 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
83 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
84 | |||
85 | foreach ($routes as $route) { | ||
86 | $this->assertSame('/blog/{slug}', $route->getPath()); | ||
87 | $this->assertSame('{locale}.example.com', $route->getHost()); | ||
88 | $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller')); | ||
89 | $this->assertSame('\w+', $route->getRequirement('locale')); | ||
90 | $this->assertSame('RouteCompiler', $route->getOption('compiler_class')); | ||
91 | $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods()); | ||
92 | $this->assertEquals(array('https'), $route->getSchemes()); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public function testLoadWithResource() | ||
97 | { | ||
98 | $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); | ||
99 | $routeCollection = $loader->load('validresource.yml'); | ||
100 | $routes = $routeCollection->all(); | ||
101 | |||
102 | $this->assertCount(2, $routes, 'Two routes are loaded'); | ||
103 | $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); | ||
104 | |||
105 | foreach ($routes as $route) { | ||
106 | $this->assertSame('/{foo}/blog/{slug}', $route->getPath()); | ||
107 | $this->assertSame('123', $route->getDefault('foo')); | ||
108 | $this->assertSame('\d+', $route->getRequirement('foo')); | ||
109 | $this->assertSame('bar', $route->getOption('foo')); | ||
110 | $this->assertSame('', $route->getHost()); | ||
111 | } | ||
112 | } | ||
113 | } | ||