Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 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
    public function testSupports()
20
    {
21
        $loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
22
 
23
        $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
24
        $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
25
 
26
        $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
27
        $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
28
    }
29
 
30
    public function testLoadWithRoute()
31
    {
32
        $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
33
        $routeCollection = $loader->load('validpattern.php');
34
        $routes = $routeCollection->all();
35
 
36
        $this->assertCount(1, $routes, 'One route is loaded');
37
        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
38
 
39
        foreach ($routes as $route) {
40
            $this->assertSame('/blog/{slug}', $route->getPath());
41
            $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
42
            $this->assertSame('{locale}.example.com', $route->getHost());
43
            $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
44
            $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
45
            $this->assertEquals(array('https'), $route->getSchemes());
46
        }
47
    }
48
 
49
    public function testLoadWithImport()
50
    {
51
        $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
52
        $routeCollection = $loader->load('validresource.php');
53
        $routes = $routeCollection->all();
54
 
55
        $this->assertCount(1, $routes, 'One route is loaded');
56
        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
57
 
58
        foreach ($routes as $route) {
59
            $this->assertSame('/prefix/blog/{slug}', $route->getPath());
60
            $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
61
            $this->assertSame('{locale}.example.com', $route->getHost());
62
            $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
63
            $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
64
            $this->assertEquals(array('https'), $route->getSchemes());
65
        }
66
    }
67
 
68
    public function testThatDefiningVariableInConfigFileHasNoSideEffects()
69
    {
70
        $locator = new FileLocator(array(__DIR__.'/../Fixtures'));
71
        $loader = new PhpFileLoader($locator);
72
        $routeCollection = $loader->load('with_define_path_variable.php');
73
        $resources = $routeCollection->getResources();
74
        $this->assertCount(1, $resources);
75
        $this->assertContainsOnly('Symfony\Component\Config\Resource\ResourceInterface', $resources);
76
        $fileResource = reset($resources);
77
        $this->assertSame(
78
            realpath($locator->locate('with_define_path_variable.php')),
79
            (string) $fileResource
80
        );
81
    }
82
}