UrlMatcherTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Routing\Matcher;
  11. use Symfony\Component\Routing\Matcher\UrlMatcher;
  12. use Symfony\Component\Routing\RouteCollection;
  13. use Symfony\Component\Routing\Route;
  14. class UrlMatcherTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testNormalizeUrl()
  17. {
  18. $collection = new RouteCollection();
  19. $collection->addRoute('foo', new Route('/:foo'));
  20. $matcher = new UrlMatcherForTests($collection, array(), array());
  21. $this->assertEquals('/', $matcher->normalizeUrl(''), '->normalizeUrl() adds a / at the beginning of the URL if needed');
  22. $this->assertEquals('/foo', $matcher->normalizeUrl('foo'), '->normalizeUrl() adds a / at the beginning of the URL if needed');
  23. $this->assertEquals('/foo', $matcher->normalizeUrl('/foo?foo=bar'), '->normalizeUrl() removes the query string');
  24. $this->assertEquals('/foo/bar', $matcher->normalizeUrl('/foo//bar'), '->normalizeUrl() removes duplicated /');
  25. }
  26. }
  27. class UrlMatcherForTests extends UrlMatcher
  28. {
  29. public function normalizeUrl($url)
  30. {
  31. return parent::normalizeUrl($url);
  32. }
  33. }