10000 small fix of #5984 when the container param is not set by Tobion · Pull Request #6071 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

small fix of #5984 when the container param is not set #6071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RedirectController extends ContainerAware
* It expects a route path parameter.
* By default, the response status code is 301.
*
* If the route empty, the status code will be 410.
* If the route is empty, the status code will be 410.
* If the permanent path parameter is set, the status code will be 302.
*
* @param string $route The route pattern to redirect to
Expand Down Expand Up @@ -56,11 +56,11 @@ public function redirectAction($route, $permanent = false)
* If the path is empty, the status code will be 410.
* If the permanent flag is set, the status code will be 302.
*
* @param string $path The path to redirect to
* @param Boolean $permanent Whether the redirect is permanent or not
* @param Boolean $scheme The URL scheme (null to keep the current one)
* @param integer $httpPort The HTTP port
* @param integer $httpsPort The HTTPS port
* @param string $path The path to redirect to
* @param Boolean $permanent Whether the redirect is permanent or not
* @param string|null $scheme The URL scheme (null to keep the current one)
* @param integer|null $httpPort The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
* @param integer|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
*
* @return Response A Response instance
*/
Expand Down Expand Up @@ -89,27 +89,25 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht

$port = '';
if ('http' === $scheme) {
if ($httpPort == null) {
if (null === $httpPort) {
if ('http' === $request->getScheme()) {
$httpPort = $request->getPort();
} else {
} elseif ($this->container->hasParameter('request_listener.http_port')) {
$httpPort = $this->container->getParameter('request_listener.http_port');
}
}

if ($httpPort != null && $httpPort != 80) {
if (null !== $httpPort && 80 != $httpPort) {
$port = ":$httpPort";
}
} elseif ('https' === $scheme) {
if ($httpsPort == null) {
if (null === $httpsPort) {
if ('https' === $request->getScheme()) {
$httpsPort = $request->getPort();
} else {
} elseif ($this->container->hasParameter('request_listener.https_port')) {
$httpsPort = $this->container->getParameter('request_listener.https_port');
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra semicolon here... Otherwise looks good!

}

if ($httpsPort != null && $httpsPort != 443) {
if (null !== $httpsPort && 443 != $httpsPort) {
$port = ":$httpsPort";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public function testRoute($permanent, $expectedCode)

$returnResponse = $controller->redirectAction($route, $permanent);

$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);

$this->assertTrue($returnResponse->isRedirect($url));
$this->assertRedirectUrl($returnResponse, $url);
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
}

Expand All @@ -104,9 +102,7 @@ public function testFullURL()
$controller = new RedirectController();
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');

$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);

$this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
$this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
$this->assertEquals(302, $returnResponse->getStatusCode());
}

Expand Down Expand Up @@ -179,7 +175,7 @@ public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme,
$this->assertRedirectUrl($returnValue, $expectedUrl);
}

public function createRequestObject($scheme, $host, $port, $baseUrl)
private function createRequestObject($scheme, $host, $port, $baseUrl)
{
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request
Expand All @@ -202,24 +198,34 @@ public function createRequestObject($scheme, $host, $port, $baseUrl)
return $request;
}

public function createRedirectController($request, $httpPort = null, $httpsPort = null)
private function createRedirectController(Request $request, $httpPort = null, $httpsPort = null)
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container
->expects($this->at(0))
->method('get')
->with($this->equalTo('request'))
->will($this->returnValue($request));
if ($httpPort != null) {
if (null !== $httpPort) {
$container
->expects($this->at(1))
->expects($this->once())
->method('hasParameter')
->with($this->equalTo('request_listener.http_port'))
->will($this->returnValue(true));
$container
->expects($this->once())
->method('getParameter')
->with($this->equalTo('request_listener.http_port'))
->will($this->returnValue($httpPort));
}
if ($httpsPort != null) {
if (null !== $httpsPort) {
$container
->expects($this->once())
->method('hasParameter')
->with($this->equalTo('request_listener.https_port'))
->will($this->returnValue(true));
$container
->expects($this->at(1))
->expects($this->once())
->method('getParameter')
->with($this->equalTo('request_listener.https_port'))
->will($this->returnValue($httpsPort));
Expand All @@ -231,8 +237,8 @@ public function createRedirectController($request, $httpPort = null, $httpsPort
return $controller;
}

public function assertRedirectUrl($returnValue, $expectedUrl)
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
{
$this->assertTrue($returnValue->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnValue->headers->get('Location'));
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
}
}
0