Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Routing] Adding tests for the ApacheMatcherDumper, PhpMatcherDumper …
…and UrlMatcher.
- Loading branch information
1 parent
547eaa8
commit 1e9e1b3
Showing
6 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.apache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
RewriteCond %{PATH_INFO} ^/foo/(baz|symfony)$ | ||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:foo,E=_ROUTING_bar:%1,E=_ROUTING_def:test] | ||
RewriteCond %{REQUEST_METHOD} =GET [OR] | ||
RewriteCond %{REQUEST_METHOD} =HEAD | ||
RewriteCond %{PATH_INFO} ^/bar/([^/\.]+?)$ | ||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:bar,E=_ROUTING_foo:%1] |
34 changes: 34 additions & 0 deletions
34
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* ProjectUrlMatcher | ||
* | ||
* This class has been auto-generated | ||
* by the Symfony Routing Component. | ||
*/ | ||
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct(array $context = array(), array $defaults = array()) | ||
{ | ||
$this->context = $context; | ||
$this->defaults = $defaults; | ||
} | ||
|
||
public function match($url) | ||
{ | ||
$url = $this->normalizeUrl($url); | ||
|
||
if (0 === strpos($url, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#x', $url, $matches)) { | ||
return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); | ||
} | ||
|
||
if (isset($this->context['method']) && in_array(strtolower($this->context['method']), array ( 0 => 'get', 1 => 'head',)) && 0 === strpos($url, '/bar') && preg_match('#^/bar/(?P<foo>[^/\.]+?)$#x', $url, $matches)) { | ||
return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'bar')); | ||
} | ||
|
||
return false; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Symfony/Tests/Component/Routing/Matcher/Dumper/ApacheMatcherDumperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\Routing; | ||
|
||
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(); | ||
|
||
$collection->addRoute('foo', new Route( | ||
'/foo/:bar', | ||
array('def' => 'test'), | ||
array('bar' => 'baz|symfony') | ||
)); | ||
$collection->addRoute('bar', new Route( | ||
'/bar/:foo', | ||
array(), | ||
array('_method' => array('GET', 'HEAD')) | ||
)); | ||
|
||
$dumper = new ApacheMatcherDumper($collection); | ||
|
||
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.apache', $dumper->dump(), '->dump() dumps basic routes to the correct apache format.'); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\Routing; | ||
|
||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; | ||
|
||
class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
static protected $fixturesPath; | ||
|
||
static public function setUpBeforeClass() | ||
{ | ||
self::$fixturesPath = realpath(__DIR__.'/../../Fixtures/'); | ||
} | ||
|
||
public function testDump() | ||
{ | ||
$collection = new RouteCollection(); | ||
|
||
$collection->addRoute('foo', new Route( | ||
'/foo/:bar', | ||
array('def' => 'test'), | ||
array('bar' => 'baz|symfony') | ||
)); | ||
$collection->addRoute('bar', new Route( | ||
'/bar/:foo', | ||
array(), | ||
array('_method' => array('GET', 'HEAD')) | ||
)); | ||
$dumper = new PhpMatcherDumper($collection); | ||
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters