浏览代码

[Routing] Added tests for PhpMatcherDumper changes

Jordi Boggiano 14 年之前
父节点
当前提交
2ed0b975f1

+ 14 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php

@@ -37,6 +37,20 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
             return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz2'));
         }
 
+        if (rtrim($url, '/') === '/test/baz3') {
+            if (substr($url, -1) !== '/') {
+                return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$url.'/', 'permanent' => true, '_route' => 'baz3');
+            }
+            return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz3'));
+        }
+
+        if (0 === strpos($url, '/test') && preg_match('#^/test/(?P<foo>[^/\.]+?)/?$#x', $url, $matches)) {
+            if (substr($url, -1) !== '/') {
+                return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$url.'/', 'permanent' => true, '_route' => 'baz4');
+            }
+            return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'baz4'));
+        }
+
         return false;
     }
 }

+ 6 - 0
tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php

@@ -44,6 +44,12 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
         $collection->add('baz2', new Route(
             '/test/baz.html'
         ));
+        $collection->add('baz3', new Route(
+            '/test/baz3/'
+        ));
+        $collection->add('baz4', new Route(
+            '/test/{foo}/'
+        ));
 
         $dumper = new PhpMatcherDumper($collection);
         $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');