Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'redirect-refresh' of https://github.com/fabicz/zf2 into…

… feature/mvc-refresh

PR #2100

Conflicts:
	library/Zend/Mvc/Controller/Plugin/Redirect.php
	tests/ZendTest/Mvc/Controller/Plugin/RedirectTest.php
  • Loading branch information...
commit 1db1531b56ffea2cd8b95b94515e429bdd91bc12 2 parents 2cdf2fc + 092fffd
@weierophinney weierophinney authored
View
12 library/Zend/Mvc/Controller/Plugin/Redirect.php
@@ -14,7 +14,6 @@
use Zend\Mvc\Exception;
use Zend\Mvc\InjectApplicationEventInterface;
use Zend\Mvc\MvcEvent;
-use Zend\Mvc\Router\RouteStackInterface;
/**
* @todo allow specifying status code as a default, or as an option to methods
@@ -26,7 +25,6 @@ class Redirect extends AbstractPlugin
{
protected $event;
protected $response;
- protected $router;
/**
* Generates a URL based on a route
@@ -75,6 +73,16 @@ public function toUrl($url)
}
/**
+ * Refresh to current route
+ *
+ * @return string
+ */
+ public function refresh()
+ {
+ return $this->toRoute(null, array(), array(), true);
+ }
+
+ /**
* Get the response
*
* @return Response
View
25 tests/ZendTest/Mvc/Controller/Plugin/RedirectTest.php
@@ -12,6 +12,7 @@
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Http\Response;
+use Zend\Route\Request;
use Zend\Mvc\Controller\Plugin\Redirect as RedirectPlugin;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\Http\Literal as LiteralRoute;
@@ -35,6 +36,10 @@ public function setUp()
)));
$this->router = $router;
+ $routeMatch = new RouteMatch(array());
+ $routeMatch->setMatchedRouteName('home');
+ $this->routeMatch = $routeMatch;
+
$event = new MvcEvent();
$event->setRouter($router);
$event->setResponse($this->response);
@@ -162,4 +167,24 @@ public function testCanPassBooleanValueForThirdArgumentToAllowReusingRouteMatche
$location = $headers->get('Location');
$this->assertEquals('/foo/bar', $location->getFieldValue());
}
+
+ public function testPluginCanRefreshToRouteWhenProperlyConfigured()
+ {
+ $this->event->setRouteMatch($this->routeMatch);
+ $response = $this->plugin->refresh();
+ $this->assertTrue($response->isRedirect());
+ $headers = $response->getHeaders();
+ $location = $headers->get('Location');
+ $this->assertEquals('/', $location->getFieldValue());
+ }
+
+ public function testPluginCanRedirectToRouteWithNullWhenProperlyConfigured()
+ {
+ $this->event->setRouteMatch($this->routeMatch);
+ $response = $this->plugin->toRoute();
+ $this->assertTrue($response->isRedirect());
+ $headers = $response->getHeaders();
+ $location = $headers->get('Location');
+ $this->assertEquals('/', $location->getFieldValue());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.