/**
  * Tests whether getContentType() / setContentType() work as expected.
  *
  * @return void
  */
 public function testContentTypeHandling()
 {
     $message = new HttpRequest();
     $this->assertSame('text/plain; charset=utf-8', $message->getContentType()->toString());
     $message->setContentType(new InternetMediaType('text', 'html', array('charset' => 'iso-8859-1')));
     $this->assertSame('text/html; charset=iso-8859-1', $message->getContentType()->toString());
     $this->assertSame($message->getContentType(), $message->getContentType());
 }
Example #2
0
 /**
  * Tests whether __construct() sets provided values correctly.
  *
  * @return void
  */
 public function testConstructWithOptionalParameters()
 {
     $request = new HttpRequest(new Uri('http://example.com/foo'), HttpRequest::METHOD_POST, AbstractHttpMessage::HTTP_VERSION_1_0, array(new GenericHeaderField('X-Test', 'Foo')), array('a' => '1'), array('b' => '2'), array(new HttpCookie('test')));
     $this->assertSame('', $request->getContent());
     $this->assertSame('text/plain; charset=utf-8', $request->getContentType()->toString());
     $this->assertFalse($request->getContentType()->hasBinaryContent());
     $this->assertSame('X-Test: Foo', $request->getHeaderFields()->get('x-test')->toString());
     $this->assertTrue($request->getCookies()->containsKey('test'));
     $this->assertSame('1', $request->getQueryParameters()->get('a'));
     $this->assertSame(array('b' => '2'), $request->getPostParameters()->toArray());
     $this->assertSame('http://example.com/foo', $request->getUri()->toString());
     $this->assertSame(HttpRequest::METHOD_POST, $request->getMethod());
 }