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 .
*/
2011-12-30 18:13:17 +00:00
namespace Symfony\Tests\Component\Routing\Matcher\Dumper ;
2010-11-25 02:50:21 +00:00
use Symfony\Component\Routing\Route ;
use Symfony\Component\Routing\RouteCollection ;
use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper ;
class ApacheMatcherDumperTest 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-06-04 11:46:19 +01:00
// method requirement (again)
$collection -> add ( 'baragain' , new Route (
'/baragain/{foo}' ,
array (),
array ( '_method' => 'get|post' )
));
2011-03-21 12:56:53 +00:00
// simple
2011-02-10 22:03:53 +00:00
$collection -> add ( 'baz' , new Route (
2011-03-21 12:56:53 +00:00
'/test/baz'
2011-02-10 22:03:53 +00:00
));
2011-03-21 12:56:53 +00:00
// simple with extension
2011-02-10 22:03:53 +00:00
$collection -> add ( 'baz2' , new Route (
2011-03-21 12:56:53 +00:00
'/test/baz.html'
));
// trailing slash
$collection -> add ( 'baz3' , new Route (
'/test/baz3/'
));
// trailing slash with variable
$collection -> add ( 'baz4' , new Route (
2011-02-10 22:03:53 +00:00
'/test/{foo}/'
));
2011-12-30 18:30:23 +00:00
// trailing slash and safe method
2011-03-21 12:56:53 +00:00
$collection -> add ( 'baz5' , new Route (
'/test/{foo}/' ,
array (),
2011-12-30 18:30:23 +00:00
array ( '_method' => 'get' )
));
// trailing slash and unsafe method
$collection -> add ( 'baz5unsafe' , new Route (
'/testunsafe/{foo}/' ,
array (),
2011-03-21 12:56:53 +00:00
array ( '_method' => 'post' )
));
2011-06-29 02:07:48 +01:00
// complex
$collection -> add ( 'baz6' , new Route (
'/test/baz' ,
array ( 'foo' => 'bar baz' )
));
2011-02-10 22:03:53 +00:00
2010-11-25 02:50:21 +00:00
$dumper = new ApacheMatcherDumper ( $collection );
$this -> assertStringEqualsFile ( self :: $fixturesPath . '/dumper/url_matcher1.apache' , $dumper -> dump (), '->dump() dumps basic routes to the correct apache format.' );
}
}