Permalink
Browse files

Add unit test

  • Loading branch information...
1 parent ad093c6 commit ebf819ef9330be29b836b765c5f5e1dba08cf5da @bakura10 committed Sep 4, 2012
Showing with 27 additions and 2 deletions.
  1. +27 −2 tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
@@ -16,6 +16,7 @@
use Zend\Http\Response;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\Http\Literal as LiteralRoute;
+use Zend\Mvc\Router\Http\Segment as SegmentRoute;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\SimpleRouteStack;
use Zend\Stdlib\Parameters;
@@ -41,7 +42,14 @@ public function setUp()
'route' => '/',
'defaults' => array(
'controller' => 'ZendTest\Mvc\Controller\TestAsset\SampleController',
- ),
+ )
+ )));
+
+ $router->addRoute('sub', SegmentRoute::factory(array(
+ 'route' => '/foo/:param',
+ 'defaults' => array(
+ 'param' => 1
+ )
)));
$this->controller = new SampleController();
@@ -126,7 +134,6 @@ public function testNullRouteUsesMatchedRouteName()
'postval1' => 'value1'
)));
-
$result = $this->controller->dispatch($this->request, $this->response);
$prgResultRoute = $this->controller->prg();
@@ -135,4 +142,22 @@ public function testNullRouteUsesMatchedRouteName()
$this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri());
$this->assertEquals(303, $prgResultRoute->getStatusCode());
}
+
+ public function testReuseMatchedParameters()
+ {
+ $this->controller->getEvent()->getRouteMatch()->setMatchedRouteName('sub');
+
+ $this->request->setMethod('POST');
+ $this->request->setPost(new Parameters(array(
+ 'postval1' => 'value1'
+ )));
+
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultRoute = $this->controller->prg();
+
+ $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
+ $this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
+ $this->assertEquals('/foo/1', $prgResultRoute->getHeaders()->get('Location')->getUri());
+ $this->assertEquals(303, $prgResultRoute->getStatusCode());
+ }
}

0 comments on commit ebf819e

Please sign in to comment.