From 7bb394e2c4daf520d8dbb0be3c7ec1ecceebe6d8 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Thu, 26 Mar 2015 11:06:01 +0100 Subject: [PATCH 1/8] Added separated handling of root paths --- src/Symfony/Component/Filesystem/Filesystem.php | 9 +++++++-- .../Component/Filesystem/Tests/FilesystemTest.php | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index a934fd201f..0952bd2e9a 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -330,8 +330,13 @@ class Filesystem // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) $depth = count($startPathArr) - $index; - // Repeated "../" for each level need to reach the common path - $traverser = str_repeat('../', $depth); + // When we need to traverse from the start, and we are starting from a root path, don't add '../' + if ($startPath[0] == '/' && $index == 0 && $depth == 1) { + $traverser = ''; + } else { + // Repeated "../" for each level need to reach the common path + $traverser = str_repeat('../', $depth); + } $endPathRemainder = implode('/', array_slice($endPathArr, $index)); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index cd9adee97e..b57610cb81 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -781,6 +781,8 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase array('/a/aab/bb', '/a/aa/', '../aab/bb/'), array('/a/aab/bb/', '/a/aa', '../aab/bb/'), array('/a/aab/bb/', '/a/aa/', '../aab/bb/'), + array('/a/aab/bb/', '/', 'a/aab/bb/'), + array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'), ); if ('\\' === DIRECTORY_SEPARATOR) { From 791b1247f90adf38bb4d41189fe0b30f2ed8154f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 13 Oct 2015 17:24:19 +0200 Subject: [PATCH 2/8] fixed CS --- src/Symfony/Component/Filesystem/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 0952bd2e9a..6fc9b8b5f7 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -331,7 +331,7 @@ class Filesystem $depth = count($startPathArr) - $index; // When we need to traverse from the start, and we are starting from a root path, don't add '../' - if ($startPath[0] == '/' && $index == 0 && $depth == 1) { + if ('/' === $startPath[0] && 0 === $index && 1 === $depth) { $traverser = ''; } else { // Repeated "../" for each level need to reach the common path From 481fc1286182d6b419cfa796dd8f8e8003f291d3 Mon Sep 17 00:00:00 2001 From: Hippolyte Alain Date: Tue, 13 Oct 2015 17:44:16 +0200 Subject: [PATCH 3/8] [HttpFoundation] Fix some typo in the Request doc --- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index c79bccc390..d2af44626c 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1067,7 +1067,7 @@ class Request /** * Checks whether the request is secure or not. * - * This method can read the client port from the "X-Forwarded-Proto" header + * This method can read the client protocol from the "X-Forwarded-Proto" header * when trusted proxies were set via "setTrustedProxies()". * * The "X-Forwarded-Proto" header must contain the protocol: "https" or "http". @@ -1092,7 +1092,7 @@ class Request /** * Returns the host name. * - * This method can read the client port from the "X-Forwarded-Host" header + * This method can read the client host name from the "X-Forwarded-Host" header * when trusted proxies were set via "setTrustedProxies()". * * The "X-Forwarded-Host" header must contain the client host name. From 795c8b3249ba105c714e6f219bc3a716e561b16c Mon Sep 17 00:00:00 2001 From: Sergey Novikov Date: Sun, 4 Oct 2015 15:22:52 +0200 Subject: [PATCH 4/8] [Security] Use SessionAuthenticationStrategy on RememberMe login Regenerate session ID with default session strategy --- .../Resources/config/security_rememberme.xml | 1 + .../Http/Firewall/RememberMeListener.php | 21 +++-- .../Tests/Firewall/RememberMeListenerTest.php | 77 ++++++++++++++++++- 3 files changed, 89 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml index 0bad7940c3..d9fb0d261e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml @@ -25,6 +25,7 @@ + diff --git a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php index f5ec8c7113..ccadf94732 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php @@ -20,6 +20,7 @@ use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; /** * RememberMeListener implements authentication capabilities via a cookie. @@ -34,18 +35,20 @@ class RememberMeListener implements ListenerInterface private $logger; private $dispatcher; private $catchExceptions = true; + private $sessionStrategy; /** * Constructor. * - * @param TokenStorageInterface $tokenStorage - * @param RememberMeServicesInterface $rememberMeServices - * @param AuthenticationManagerInterface $authenticationManager - * @param LoggerInterface $logger - * @param EventDispatcherInterface $dispatcher - * @param bool $catchExceptions + * @param TokenStorageInterface $tokenStorage + * @param RememberMeServicesInterface $rememberMeServices + * @param AuthenticationManagerInterface $authenticationManager + * @param LoggerInterface $logger + * @param EventDispatcherInterface $dispatcher + * @param bool $catchExceptions + * @param SessionAuthenticationStrategyInterface $sessionStrategy */ - public function __construct(TokenStorageInterface $tokenStorage, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $catchExceptions = true) + public function __construct(TokenStorageInterface $tokenStorage, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $catchExceptions = true, SessionAuthenticationStrategyInterface $sessionStrategy = null) { $this->tokenStorage = $tokenStorage; $this->rememberMeServices = $rememberMeServices; @@ -53,6 +56,7 @@ class RememberMeListener implements ListenerInterface $this->logger = $logger; $this->dispatcher = $dispatcher; $this->catchExceptions = $catchExceptions; + $this->sessionStrategy = $sessionStrategy; } /** @@ -73,6 +77,9 @@ class RememberMeListener implements ListenerInterface try { $token = $this->authenticationManager->authenticate($token); + if (null !== $this->sessionStrategy && $request->hasSession() && $request->getSession()->isStarted()) { + $this->sessionStrategy->onAuthentication($request, $token); + } $this->tokenStorage->setToken($token); if (null !== $this->dispatcher) { diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php index e348355d4e..b16d55b66b 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php @@ -181,6 +181,71 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase $listener->handle($event); } + public function testSessionStrategy() + { + list($listener, $tokenStorage, $service, $manager, , $dispatcher, $sessionStrategy) = $this->getListener(false, true, true); + + $tokenStorage + ->expects($this->once()) + ->method('getToken') + ->will($this->returnValue(null)) + ; + + $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + $service + ->expects($this->once()) + ->method('autoLogin') + ->will($this->returnValue($token)) + ; + + $tokenStorage + ->expects($this->once()) + ->method('setToken') + ->with($this->equalTo($token)) + ; + + $manager + ->expects($this->once()) + ->method('authenticate') + ->will($this->returnValue($token)) + ; + + $session = $this->getMock('\Symfony\Component\HttpFoundation\Session\SessionInterface'); + $session + ->expects($this->once()) + ->method('isStarted') + ->will($this->returnValue(true)) + ; + + $request = $this->getMock('\Symfony\Component\HttpFoundation\Request'); + $request + ->expects($this->once()) + ->method('hasSession') + ->will($this->returnValue(true)) + ; + + $request + ->expects($this->once()) + ->method('getSession') + ->will($this->returnValue($session)) + ; + + $event = $this->getGetResponseEvent(); + $event + ->expects($this->once()) + ->method('getRequest') + ->will($this->returnValue($request)) + ; + + $sessionStrategy + ->expects($this->once()) + ->method('onAuthentication') + ->will($this->returnValue(null)) + ; + + $listener->handle($event); + } + public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent() { list($listener, $tokenStorage, $service, $manager, , $dispatcher) = $this->getListener(true); @@ -240,7 +305,7 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase return $this->getMock('Symfony\Component\HttpKernel\Event\FilterResponseEvent', array(), array(), '', false); } - protected function getListener($withDispatcher = false, $catchExceptions = true) + protected function getListener($withDispatcher = false, $catchExceptions = true, $withSessionStrategy = false) { $listener = new RememberMeListener( $tokenStorage = $this->getTokenStorage(), @@ -248,10 +313,11 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase $manager = $this->getManager(), $logger = $this->getLogger(), $dispatcher = ($withDispatcher ? $this->getDispatcher() : null), - $catchExceptions + $catchExceptions, + $sessionStrategy = ($withSessionStrategy ? $this->getSessionStrategy() : null) ); - return array($listener, $tokenStorage, $service, $manager, $logger, $dispatcher); + return array($listener, $tokenStorage, $service, $manager, $logger, $dispatcher, $sessionStrategy); } protected function getLogger() @@ -278,4 +344,9 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase { return $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); } + + private function getSessionStrategy() + { + return $this->getMock('\Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface'); + } } From b3a54117c8c5fab8daea37565e98478b45bc9af2 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Fri, 16 Oct 2015 14:11:32 +0100 Subject: [PATCH 5/8] [Validator] Allow an empty path in a URL with only a fragment or a query --- src/Symfony/Component/Validator/Constraints/UrlValidator.php | 2 +- .../Validator/Tests/Constraints/UrlValidatorTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 51ef8992c6..5af71e6d82 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -33,7 +33,7 @@ class UrlValidator extends ConstraintValidator \] # a IPv6 address ) (:[0-9]+)? # a port (optional) - (/?|/\S+) # a /, nothing or a / with something + (/?|/\S+|\?|\#) # a /, nothing, a / with something, a query or a fragment $~ixu'; /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index e496245c0a..c08531339c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -111,6 +111,8 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest array('http://☎.com/'), array('http://username:password@symfony.com'), array('http://user-name@symfony.com'), + array('http://symfony.com?'), + array('http://symfony.com#'), ); } @@ -140,8 +142,6 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest array('http://goog_le.com'), array('http://google.com::aa'), array('http://google.com:aa'), - array('http://symfony.com?'), - array('http://symfony.com#'), array('ftp://google.fr'), array('faked://google.fr'), array('http://127.0.0.1:aa/'), From e704ee4d6c27ff1152cef585292724ac5572d92a Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Fri, 16 Oct 2015 14:20:03 +0100 Subject: [PATCH 6/8] [TwigBundle] Fix Twig cache is not properly warmed --- .../CacheWarmer/TemplateCacheCacheWarmer.php | 13 +- .../Compiler/ExtensionPass.php | 4 +- .../TwigBundle/Resources/config/twig.xml | 3 +- .../Tests/Functional/CacheWarmingTest.php | 116 ++++++++++++++++++ .../Resources/config/empty_routing.yml | 0 src/Symfony/Bundle/TwigBundle/composer.json | 1 + 6 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/empty_routing.yml diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php index 65827eba5a..8557a2f55a 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php @@ -31,15 +31,16 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface /** * Constructor. * - * @param ContainerInterface $container The dependency injection container - * @param TemplateFinderInterface $finder The template paths cache warmer + * @param ContainerInterface $container The dependency injection container + * @param TemplateFinderInterface|null $finder The template paths cache warmer */ - public function __construct(ContainerInterface $container, TemplateFinderInterface $finder) + public function __construct(ContainerInterface $container, TemplateFinderInterface $finder = null) { // We don't inject the Twig environment directly as it depends on the // template locator (via the loader) which might be a cached one. // The cached template locator is available once the TemplatePathsCacheWarmer - // has been warmed up + // has been warmed up. + // But it can also be null if templating has been disabled. $this->container = $container; $this->finder = $finder; } @@ -51,6 +52,10 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface */ public function warmUp($cacheDir) { + if (null === $this->finder) { + return; + } + $twig = $this->container->get('twig'); foreach ($this->finder->findAllTemplates() as $template) { diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php index f4344c7434..8746998468 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php @@ -68,9 +68,7 @@ class ExtensionPass implements CompilerPassInterface $container->getDefinition('twig.extension.debug')->addTag('twig.extension'); } - if ($container->has('templating')) { - $container->getDefinition('twig.cache_warmer')->addTag('kernel.cache_warmer'); - } else { + if (!$container->has('templating')) { $loader = $container->getDefinition('twig.loader.native_filesystem'); $loader->addTag('twig.loader'); $loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls()); diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 9e1a117774..6a13980fcd 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -46,8 +46,9 @@ + - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php new file mode 100644 index 0000000000..610bfa3b58 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php @@ -0,0 +1,116 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Tests; + +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; + +class NewCacheWamingTest extends \PHPUnit_Framework_TestCase +{ + public function testCacheIsProperlyWarmedWhenTemplatingIsAvailable() + { + $kernel = new CacheWarmingKernel(true); + $kernel->boot(); + + $warmer = $kernel->getContainer()->get('cache_warmer'); + $warmer->enableOptionalWarmers(); + $warmer->warmUp($kernel->getCacheDir()); + + $this->assertTrue(file_exists($kernel->getCacheDir().'/twig')); + } + + public function testCacheIsNotWarmedWhenTemplatingIsDisabled() + { + $kernel = new CacheWarmingKernel(false); + $kernel->boot(); + + $warmer = $kernel->getContainer()->get('cache_warmer'); + $warmer->enableOptionalWarmers(); + $warmer->warmUp($kernel->getCacheDir()); + + $this->assertFalse(file_exists($kernel->getCacheDir().'/twig')); + } + + protected function setUp() + { + $this->deleteTempDir(); + } + + protected function tearDown() + { + $this->deleteTempDir(); + } + + private function deleteTempDir() + { + if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel')) { + return; + } + + $fs = new Filesystem(); + $fs->remove($dir); + } +} + +class CacheWarmingKernel extends Kernel +{ + private $withTemplating; + + public function __construct($withTemplating) + { + $this->withTemplating = $withTemplating; + + parent::__construct('dev', true); + } + + public function getName() + { + return 'CacheWarming'; + } + + public function registerBundles() + { + return array(new FrameworkBundle(), new TwigBundle()); + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(function ($container) { + $container->loadFromExtension('framework', array( + 'secret' => '$ecret', + )); + }); + + if ($this->withTemplating) { + $loader->load(function ($container) { + $container->loadFromExtension('framework', array( + 'secret' => '$ecret', + 'templating' => array('engines' => array('twig')), + 'router' => array('resource' => '%kernel.root_dir%/Resources/config/empty_routing.yml'), + )); + }); + } + } + + public function getCacheDir() + { + return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache'; + } + + public function getLogDir() + { + return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/logs'; + } +} diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/empty_routing.yml b/src/Symfony/Bundle/TwigBundle/Tests/Functional/Resources/config/empty_routing.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index b52e497b67..ccd3484c66 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -28,6 +28,7 @@ "symfony/dependency-injection": "~2.6,>=2.6.6", "symfony/expression-language": "~2.4", "symfony/config": "~2.2", + "symfony/finder": "~2.0,>=2.0.5", "symfony/routing": "~2.1", "symfony/templating": "~2.1", "symfony/yaml": "~2.3", From 11622ad2942c3345a21ce609f06df1bdbcf5d551 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 17 Oct 2015 08:51:28 +0200 Subject: [PATCH 7/8] [Process] tweaked README --- src/Symfony/Component/Process/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/README.md b/src/Symfony/Component/Process/README.md index 7c83ed413e..7222fe8957 100644 --- a/src/Symfony/Component/Process/README.md +++ b/src/Symfony/Component/Process/README.md @@ -7,12 +7,13 @@ In this example, we run a simple directory listing and get the result back: ```php use Symfony\Component\Process\Process; +use Symfony\Component\Process\Exception\ProcessFailedException; $process = new Process('ls -lsa'); $process->setTimeout(3600); $process->run(); if (!$process->isSuccessful()) { - throw new RuntimeException($process->getErrorOutput()); + throw new ProcessFailedException($process); } print $process->getOutput(); @@ -21,6 +22,19 @@ print $process->getOutput(); You can think that this is easy to achieve with plain PHP but it's not especially if you want to take care of the subtle differences between the different platforms. +You can simplify the code by using `mustRun()` instead of `run()`, which will +throw a `ProcessFailedException` automatically in case of a problem: + +```php +use Symfony\Component\Process\Process; + +$process = new Process('ls -lsa'); +$process->setTimeout(3600); +$process->mustRun(); + +print $process->getOutput(); +``` + And if you want to be able to get some feedback in real-time, just pass an anonymous function to the ``run()`` method and you will get the output buffer as it becomes available: From 608c8d25a319e6b569437ea01e047de21be49f77 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sun, 18 Oct 2015 17:23:56 +0200 Subject: [PATCH 8/8] [Routing] use constants in tests --- .../Dumper/PhpGeneratorDumperTest.php | 9 ++-- .../Tests/Generator/UrlGeneratorTest.php | 48 +++++++++---------- .../Security/Tests/Http/HttpUtilsTest.php | 3 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php index c8c5a4c3e9..43ef624ddf 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Routing\Tests\Generator\Dumper; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; @@ -64,10 +65,10 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase $projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php')); - $absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true); - $absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true); - $relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), false); - $relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), false); + $absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); + $absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL); + $relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH); + $relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar'); $this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2'); diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index 0589dc6c67..2807e1011c 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -22,7 +22,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteUrlWithPort80() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array(), true); + $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/app.php/testing', $url); } @@ -30,7 +30,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteSecureUrlWithPort443() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('https://localhost/app.php/testing', $url); } @@ -38,7 +38,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost:8080/app.php/testing', $url); } @@ -46,7 +46,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteSecureUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('https://localhost:8080/app.php/testing', $url); } @@ -54,7 +54,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testRelativeUrlWithoutParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array(), false); + $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing', $url); } @@ -62,7 +62,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testRelativeUrlWithParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing/bar', $url); } @@ -70,7 +70,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testRelativeUrlWithNullParameter() { $routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null))); - $url = $this->getGenerator($routes)->generate('test', array(), false); + $url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing', $url); } @@ -83,13 +83,13 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null))); // This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params. // Generating path "/testing//bar" would be wrong as matching this route would fail. - $this->getGenerator($routes)->generate('test', array(), false); + $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH); } public function testRelativeUrlWithOptionalZeroParameter() { $routes = $this->getRoutes('test', new Route('/testing/{page}')); - $url = $this->getGenerator($routes)->generate('test', array('page' => 0), false); + $url = $this->getGenerator($routes)->generate('test', array('page' => 0), UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing/0', $url); } @@ -104,7 +104,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testRelativeUrlWithExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH); $this->assertEquals('/app.php/testing?foo=bar', $url); } @@ -112,7 +112,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteUrlWithExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); } @@ -120,7 +120,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testUrlWithNullExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes)->generate('test', array('foo' => null), true); + $url = $this->getGenerator($routes)->generate('test', array('foo' => null), UrlGeneratorInterface::ABSOLUTE_URL); $this->assertEquals('http://localhost/app.php/testing', $url); } @@ -167,7 +167,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenerateWithoutRoutes() { $routes = $this->getRoutes('foo', new Route('/testing/{foo}')); - $this->getGenerator($routes)->generate('test', array(), true); + $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -176,7 +176,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenerateForRouteWithoutMandatoryParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}')); - $this->getGenerator($routes)->generate('test', array(), true); + $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -185,7 +185,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenerateForRouteWithInvalidOptionalParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); - $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); + $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -194,7 +194,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenerateForRouteWithInvalidParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2'))); - $this->getGenerator($routes)->generate('test', array('foo' => '0'), true); + $this->getGenerator($routes)->generate('test', array('foo' => '0'), UrlGeneratorInterface::ABSOLUTE_URL); } public function testGenerateForRouteWithInvalidOptionalParameterNonStrict() @@ -202,7 +202,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); $generator = $this->getGenerator($routes); $generator->setStrictRequirements(false); - $this->assertNull($generator->generate('test', array('foo' => 'bar'), true)); + $this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL)); } public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger() @@ -213,7 +213,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase ->method('error'); $generator = $this->getGenerator($routes, array(), $logger); $generator->setStrictRequirements(false); - $this->assertNull($generator->generate('test', array('foo' => 'bar'), true)); + $this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL)); } public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck() @@ -230,7 +230,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenerateForRouteWithInvalidMandatoryParameter() { $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+'))); - $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); + $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); } /** @@ -405,7 +405,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase { $routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com')); - $this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), true)); + $this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL)); } /** @@ -414,7 +414,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testUrlWithInvalidParameterInHost() { $routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com')); - $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false); + $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH); } /** @@ -423,7 +423,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue() { $routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com')); - $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false); + $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH); } /** @@ -432,7 +432,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testUrlWithInvalidParameterEqualsDefaultValueInHost() { $routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com')); - $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false); + $this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH); } public function testUrlWithInvalidParameterInHostInNonStrictMode() @@ -440,7 +440,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com')); $generator = $this->getGenerator($routes); $generator->setStrictRequirements(false); - $this->assertNull($generator->generate('test', array('foo' => 'baz'), false)); + $this->assertNull($generator->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH)); } public function testHostIsCaseInsensitive() diff --git a/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php b/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php index 019af193da..4a69242d9b 100644 --- a/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php +++ b/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Tests\Http; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Http\HttpUtils; @@ -43,7 +44,7 @@ class HttpUtilsTest extends \PHPUnit_Framework_TestCase $urlGenerator ->expects($this->any()) ->method('generate') - ->with('foobar', array(), true) + ->with('foobar', array(), UrlGeneratorInterface::ABSOLUTE_URL) ->will($this->returnValue('http://localhost/foo/bar')) ; $urlGenerator