2011-03-05 23:15:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-03-05 23:15:01 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Component\HttpKernel\DataCollector;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\HttpFoundation\Cookie;
|
|
|
|
|
|
|
|
class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provider
|
|
|
|
*/
|
|
|
|
public function testCollect(Request $request, Response $response)
|
|
|
|
{
|
|
|
|
$c = new RequestDataCollector();
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
$c->collect($request, $response);
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
$this->assertSame('request',$c->getName());
|
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getRequestHeaders());
|
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestServer());
|
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestCookies());
|
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestAttributes());
|
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestRequest());
|
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestQuery());
|
|
|
|
$this->assertEquals('html',$c->getFormat());
|
|
|
|
$this->assertEquals(array(),$c->getSessionAttributes());
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getResponseHeaders());
|
|
|
|
$this->assertEquals(200,$c->getStatusCode());
|
|
|
|
$this->assertEquals('application/json',$c->getContentType());
|
|
|
|
}
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
public function provider()
|
|
|
|
{
|
|
|
|
$request = Request::create('http://test.com/foo?bar=baz');
|
|
|
|
$request->attributes->set('foo', 'bar');
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
$response = new Response();
|
|
|
|
$response->setStatusCode(200);
|
|
|
|
$response->headers->set('Content-Type', 'application/json');
|
|
|
|
$response->headers->setCookie(new Cookie('foo','bar',1,'/foo','localhost',true,true));
|
|
|
|
$response->headers->setCookie(new Cookie('bar','foo',new \DateTime('@946684800')));
|
|
|
|
$response->headers->setCookie(new Cookie('bazz','foo','2000-12-12'));
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
return array(
|
|
|
|
array($request,$response)
|
|
|
|
);
|
|
|
|
}
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2011-03-05 23:15:01 +00:00
|
|
|
}
|