2010-11-25 02:50:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-11-25 02:50:21 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Component\Routing;
|
|
|
|
|
2011-03-21 12:56:53 +00:00
|
|
|
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
|
2010-11-25 02:50:21 +00:00
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
use Symfony\Component\Routing\RouteCollection;
|
|
|
|
|
|
|
|
class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
static protected $fixturesPath;
|
|
|
|
|
|
|
|
static public function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
self::$fixturesPath = realpath(__DIR__.'/../../Fixtures/');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDump()
|
|
|
|
{
|
|
|
|
$collection = new RouteCollection();
|
|
|
|
|
2011-03-21 12:56:53 +00:00
|
|
|
// defaults and requirements
|
2010-11-25 14:49:33 +00:00
|
|
|
$collection->add('foo', new Route(
|
2010-11-23 14:11:28 +00:00
|
|
|
'/foo/{bar}',
|
2010-11-25 02:50:21 +00:00
|
|
|
array('def' => 'test'),
|
|
|
|
array('bar' => 'baz|symfony')
|
|
|
|
));
|
2011-03-21 12:56:53 +00:00
|
|
|
// method requirement
|
2010-11-25 14:49:33 +00:00
|
|
|
$collection->add('bar', new Route(
|
2010-11-23 14:11:28 +00:00
|
|
|
'/bar/{foo}',
|
2010-11-25 02:50:21 +00:00
|
|
|
array(),
|
2010-11-25 14:49:33 +00:00
|
|
|
array('_method' => 'GET|head')
|
2010-11-25 02:50:21 +00:00
|
|
|
));
|
2011-03-21 12:56:53 +00:00
|
|
|
// simple
|
2010-12-20 17:13:02 +00:00
|
|
|
$collection->add('baz', new Route(
|
|
|
|
'/test/baz'
|
|
|
|
));
|
2011-03-21 12:56:53 +00:00
|
|
|
// simple with extension
|
2010-12-22 08:41:53 +00:00
|
|
|
$collection->add('baz2', new Route(
|
|
|
|
'/test/baz.html'
|
|
|
|
));
|
2011-03-21 12:56:53 +00:00
|
|
|
// trailing slash
|
2011-02-10 22:03:19 +00:00
|
|
|
$collection->add('baz3', new Route(
|
|
|
|
'/test/baz3/'
|
|
|
|
));
|
2011-03-21 12:56:53 +00:00
|
|
|
// trailing slash with variable
|
2011-02-10 22:03:19 +00:00
|
|
|
$collection->add('baz4', new Route(
|
|
|
|
'/test/{foo}/'
|
|
|
|
));
|
2011-03-21 12:56:53 +00:00
|
|
|
// trailing slash and method
|
|
|
|
$collection->add('baz5', new Route(
|
|
|
|
'/test/{foo}/',
|
|
|
|
array(),
|
|
|
|
array('_method' => 'post')
|
|
|
|
));
|
2011-03-24 08:03:59 +00:00
|
|
|
// complex name
|
|
|
|
$collection->add('baz.baz6', new Route(
|
|
|
|
'/test/{foo}/',
|
|
|
|
array(),
|
|
|
|
array('_method' => 'put')
|
|
|
|
));
|
2010-12-20 17:13:02 +00:00
|
|
|
|
2010-11-25 02:50:21 +00:00
|
|
|
$dumper = new PhpMatcherDumper($collection);
|
|
|
|
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
|
|
|
|
}
|
|
|
|
}
|