+ public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie()
+ {
+ $request = $this->createRequest();
+ $request->cookies->add(array(
+ 'sf_redirect' => '{}',
+ ));
+
+ $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
+
+ $c = new RequestDataCollector();
+ $c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse()));
+
+ $this->assertTrue($request->attributes->get('_redirected'));
+ }
+
+ public function testItSetsARedirectCookieIfTheResponseIsARedirection()
+ {
+ $c = new RequestDataCollector();
+
+ $response = $this->createResponse();
+ $response->setStatusCode(302);
+ $response->headers->set('Location', '/somewhere-else');
+
+ $c->collect($request = $this->createRequest(), $response);
+ $c->lateCollect();
+
+ $cookie = $this->getCookieByName($response, 'sf_redirect');
+
+ $this->assertNotEmpty($cookie->getValue());
+ }
+
+ public function testItCollectsTheRedirectionAndClearTheCookie()
+ {
+ $c = new RequestDataCollector();
+
+ $request = $this->createRequest();
+ $request->attributes->set('_redirected', true);
+ $request->cookies->add(array(
+ 'sf_redirect' => '{"method": "POST"}',
+ ));
+
+ $c->collect($request, $response = $this->createResponse());
+ $c->lateCollect();
+
+ $this->assertEquals('POST', $c->getRedirect()['method']);
+
+ $cookie = $this->getCookieByName($response, 'sf_redirect');
+ $this->assertNull($cookie->getValue());
+ }
+