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 ;
2011-04-20 12:54:39 +01:00
use Symfony\Component\Routing\RequestContext ;
2010-11-25 02:50:21 +00:00
class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
{
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' )
));
2011-04-05 10:54:15 +01:00
// defaults without variable
$collection -> add ( 'foofoo' , new Route (
'/foofoo' ,
array ( 'def' => 'test' )
));
2010-12-20 17:13:02 +00:00
2011-04-20 12:54:39 +01:00
$dumper = new PhpMatcherDumper ( $collection , new RequestContext ());
2011-04-19 23:25:45 +01:00
$this -> assertStringEqualsFile ( __DIR__ . '/../../Fixtures/dumper/url_matcher1.php' , $dumper -> dump (), '->dump() dumps basic routes to the correct PHP file.' );
// force HTTPS redirection
$collection -> add ( 'secure' , new Route (
'/secure' ,
array (),
array ( '_scheme' => 'https' )
));
// force HTTP redirection
$collection -> add ( 'nonsecure' , new Route (
'/nonsecure' ,
array (),
array ( '_scheme' => 'http' )
));
$this -> assertStringEqualsFile ( __DIR__ . '/../../Fixtures/dumper/url_matcher2.php' , $dumper -> dump ( array ( 'base_class' => 'Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher' )), '->dump() dumps basic routes to the correct PHP file.' );
}
/**
* @ expectedException \LogicException
*/
public function testDumpWhenSchemeIsUsedWithoutAProperDumper ()
{
$collection = new RouteCollection ();
$collection -> add ( 'secure' , new Route (
'/secure' ,
array (),
array ( '_scheme' => 'https' )
));
2011-04-20 12:54:39 +01:00
$dumper = new PhpMatcherDumper ( $collection , new RequestContext ());
2011-04-19 23:25:45 +01:00
$dumper -> dump ();
2010-11-25 02:50:21 +00:00
}
}