/**
  * @dataProvider createResponseWithLocationDataProvider
  */
 public function testCreateResponseWithLocation($expected, $format, $forceRedirects, $noContentCode)
 {
     $viewHandler = new ViewHandler(array('html' => true, 'json' => false, 'xml' => false), Codes::HTTP_BAD_REQUEST, $noContentCode, false, $forceRedirects);
     $view = new View();
     $view->setLocation('foo');
     $returnedResponse = $viewHandler->createResponse($view, new Request(), $format);
     $this->assertEquals($expected, $returnedResponse->getStatusCode());
     $this->assertEquals('foo', $returnedResponse->headers->get('location'));
 }
Example #2
0
 public function testSetLocation()
 {
     $url = 'users';
     $code = 500;
     $view = View::createRedirect($url, $code);
     $this->assertAttributeEquals($url, 'location', $view);
     $this->assertAttributeEquals(null, 'route', $view);
     $this->assertEquals($code, $view->getResponse()->getStatusCode());
     $view = new View();
     $location = 'location';
     $view->setLocation($location);
     $this->assertEquals($location, $view->getLocation());
 }
Example #3
0
 public function testCreateResponseWithLocationAndData()
 {
     $testValue = array('naviter' => 'oudie');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get'));
     $this->setupMockedSerializer($container, $testValue);
     $viewHandler = new ViewHandler(array('json' => false));
     $viewHandler->setContainer($container);
     $view = new View();
     $view->setStatusCode(Codes::HTTP_CREATED);
     $view->setLocation('foo');
     $view->setData($testValue);
     $returnedResponse = $viewHandler->createResponse($view, new Request(), 'json');
     $this->assertEquals('foo', $returnedResponse->headers->get('location'));
     $this->assertEquals(var_export($testValue, true), $returnedResponse->getContent());
 }
Example #4
0
 public function testCreateResponseWithLocationAndData()
 {
     $testValue = ['naviter' => 'oudie'];
     $this->setupMockedSerializer($testValue);
     $viewHandler = $this->createViewHandler(['json' => false]);
     $view = new View();
     $view->setStatusCode(Response::HTTP_CREATED);
     $view->setLocation('foo');
     $view->setData($testValue);
     $returnedResponse = $viewHandler->createResponse($view, new Request(), 'json');
     $this->assertEquals('foo', $returnedResponse->headers->get('location'));
     $this->assertEquals(var_export($testValue, true), $returnedResponse->getContent());
 }
 public function testCreateResponseWithLocationAndData()
 {
     $testValue = ['naviter' => 'oudie'];
     $container = $this->getMock(Container::class, ['get']);
     $this->setupMockedSerializer($container, $testValue);
     $viewHandler = new ViewHandler(['json' => false]);
     $viewHandler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $viewHandler->setContainer($container);
     $view = new View();
     $view->setStatusCode(Response::HTTP_CREATED);
     $view->setLocation('foo');
     $view->setData($testValue);
     $returnedResponse = $viewHandler->createResponse($view, new Request(), 'json');
     $this->assertEquals('foo', $returnedResponse->headers->get('location'));
     $this->assertEquals(var_export($testValue, true), $returnedResponse->getContent());
 }