2010-03-25 07:55:50 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2010-03-25 07:55:50 +00:00
*
* ( c ) Fabien Potencier < fabien . potencier @ symfony - project . com >
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2010-07-09 08:26:22 +01:00
namespace Symfony\Tests\Components\HttpFoundation ;
2010-03-25 07:55:50 +00:00
2010-07-09 08:26:22 +01:00
use Symfony\Components\HttpFoundation\Request ;
2010-03-25 07:55:50 +00:00
class RequestTest extends \PHPUnit_Framework_TestCase
{
2010-05-06 12:25:53 +01:00
/**
2010-07-09 08:26:22 +01:00
* @ covers Symfony\Components\HttpFoundation\Request :: __construct
2010-05-06 12:25:53 +01:00
*/
public function testConstructor ()
{
$this -> testInitialize ();
}
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
/**
2010-07-09 08:26:22 +01:00
* @ covers Symfony\Components\HttpFoundation\Request :: initialize
2010-05-06 12:25:53 +01:00
*/
public function testInitialize ()
{
$request = new Request ();
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$request -> initialize ( array ( 'foo' => 'bar' ));
$this -> assertEquals ( 'bar' , $request -> query -> get ( 'foo' ), '->initialize() takes an array of query parameters as its first argument' );
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$request -> initialize ( null , array ( 'foo' => 'bar' ));
$this -> assertEquals ( 'bar' , $request -> request -> get ( 'foo' ), '->initialize() takes an array of request parameters as its second argument' );
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$request -> initialize ( null , null , array ( 'foo' => 'bar' ));
$this -> assertEquals ( 'bar' , $request -> path -> get ( 'foo' ), '->initialize() takes an array of path parameters as its thrid argument' );
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$request -> initialize ( null , null , null , null , null , array ( 'HTTP_FOO' => 'bar' ));
$this -> assertEquals ( 'bar' , $request -> headers -> get ( 'FOO' ), '->initialize() takes an array of HTTP headers as its fourth argument' );
}
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
/**
2010-07-09 08:26:22 +01:00
* @ covers Symfony\Components\HttpFoundation\Request :: duplicate
2010-05-06 12:25:53 +01:00
*/
public function testDuplicate ()
{
$request = new Request ( array ( 'foo' => 'bar' ), array ( 'foo' => 'bar' ), array ( 'foo' => 'bar' ), array (), array (), array ( 'HTTP_FOO' => 'bar' ));
$dup = $request -> duplicate ();
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$this -> assertEquals ( $request -> query -> all (), $dup -> query -> all (), '->duplicate() duplicates a request an copy the current query parameters' );
$this -> assertEquals ( $request -> request -> all (), $dup -> request -> all (), '->duplicate() duplicates a request an copy the current request parameters' );
$this -> assertEquals ( $request -> path -> all (), $dup -> path -> all (), '->duplicate() duplicates a request an copy the current path parameters' );
$this -> assertEquals ( $request -> headers -> all (), $dup -> headers -> all (), '->duplicate() duplicates a request an copy the current HTTP headers' );
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$dup = $request -> duplicate ( array ( 'foo' => 'foobar' ), array ( 'foo' => 'foobar' ), array ( 'foo' => 'foobar' ), array (), array (), array ( 'HTTP_FOO' => 'foobar' ));
2010-03-25 07:55:50 +00:00
2010-05-06 12:25:53 +01:00
$this -> assertEquals ( array ( 'foo' => 'foobar' ), $dup -> query -> all (), '->duplicate() overrides the query parameters if provided' );
$this -> assertEquals ( array ( 'foo' => 'foobar' ), $dup -> request -> all (), '->duplicate() overrides the request parameters if provided' );
$this -> assertEquals ( array ( 'foo' => 'foobar' ), $dup -> path -> all (), '->duplicate() overrides the path parameters if provided' );
2010-06-23 15:24:24 +01:00
$this -> assertEquals ( array ( 'foo' => array ( 'foobar' )), $dup -> headers -> all (), '->duplicate() overrides the HTTP header if provided' );
2010-05-06 12:25:53 +01:00
}
2010-04-04 00:19:07 +01:00
2010-05-06 12:25:53 +01:00
/**
2010-07-09 08:26:22 +01:00
* @ covers Symfony\Components\HttpFoundation\Request :: getFormat
2010-05-06 12:25:53 +01:00
*/
public function testGetFormat ()
{
$request = new Request ();
2010-04-04 00:19:07 +01:00
2010-05-06 12:25:53 +01:00
$this -> assertNull ( $request -> getFormat ( null ), '->getFormat() returns null when mime-type is null' );
$this -> assertNull ( $request -> getFormat ( 'unexistant-mime-type' ), '->getFormat() returns null when mime-type is unknown' );
$this -> assertEquals ( 'txt' , $request -> getFormat ( 'text/plain' ), '->getFormat() returns correct format when mime-type have one format only' );
$this -> assertEquals ( 'js' , $request -> getFormat ( 'application/javascript' ), '->getFormat() returns correct format when format have multiple mime-type (first)' );
$this -> assertEquals ( 'js' , $request -> getFormat ( 'application/x-javascript' ), '->getFormat() returns correct format when format have multiple mime-type' );
$this -> assertEquals ( 'js' , $request -> getFormat ( 'text/javascript' ), '->getFormat() returns correct format when format have multiple mime-type (last)' );
}
2010-03-25 07:55:50 +00:00
}