public function testSetHttpResponseWithInvalidMediaTypeThrowsException()
 {
     $this->setExpectedException('webignition\\WebResource\\Exception', 'HTTP response contains invalid content type', 2);
     $validMediaType = new InternetMediaType();
     $validMediaType->setType('foo');
     $validMediaType->setSubtype('bar');
     $this->resource->addValidContentType($validMediaType);
     $response = $this->getHttpResponseFromMessage("HTTP/1.0 200 OK\nContent-Type:text/html");
     $this->assertEquals($this->resource, $this->resource->setHttpResponse($response));
 }
Ejemplo n.º 2
0
 /**
  * @param InternetMediaType $contentType
  * @return WebResource
  * @throws Exception
  */
 public function removeValidContentType(InternetMediaType $contentType)
 {
     if (array_key_exists($contentType->getTypeSubtypeString(), $this->validContentTypes)) {
         unset($this->validContentTypes[$contentType->getTypeSubtypeString()]);
     }
     if ($this->hasHttpResponse() && !$this->hasValidContentType()) {
         throw new Exception('HTTP response contains invalid content type', 2);
     }
     return $this;
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     parent::setUp();
     for ($count = 0; $count < self::MEDIA_TYPE_COUNT; $count++) {
         $mediaType = new InternetMediaType();
         $mediaType->setType('foo' . $count);
         $mediaType->setSubtype('bar');
         $this->expectedMediaTypes[$mediaType->getTypeSubtypeString()] = $mediaType;
         $this->resource->addValidContentType($mediaType);
     }
 }
Ejemplo n.º 4
0
 public function testValidContentTypesMatchThoseAdded()
 {
     $expectedMediaTypes = array();
     for ($count = 0; $count < self::MEDIA_TYPE_COUNT; $count++) {
         $mediaType = new InternetMediaType();
         $mediaType->setType('foo' . $count);
         $mediaType->setSubtype('bar');
         $expectedMediaTypes[$mediaType->getTypeSubtypeString()] = $mediaType;
         $this->resource->addValidContentType($mediaType);
     }
     foreach ($this->resource->getValidContentTypes() as $index => $mediaType) {
         $this->assertEquals($expectedMediaTypes[$index], $mediaType);
     }
 }
Ejemplo n.º 5
0
 /**
  *
  * @param string $internetMediaTypeString
  * @return \webignition\InternetMediaType\InternetMediaType
  */
 public function parse($internetMediaTypeString)
 {
     $inputString = trim($internetMediaTypeString);
     $internetMediaType = new InternetMediaType();
     $internetMediaType->setType($this->getTypeParser()->parse($inputString));
     $internetMediaType->setSubtype($this->getSubypeParser()->parse($inputString));
     $parameterString = $this->getParameterString($inputString, $internetMediaType->getType(), $internetMediaType->getSubtype());
     $parameterStrings = $this->getParameterStrings($parameterString);
     $parameters = $this->getParameters($parameterStrings);
     foreach ($parameters as $parameter) {
         $internetMediaType->addParameter($parameter);
     }
     return $internetMediaType;
 }
 public function testWithSlightlyInvalidMediaTypeString()
 {
     $mediaType = new InternetMediaType();
     $mediaType->setType('text');
     $mediaType->setSubtype('javascript');
     $parameter1 = new Parameter();
     $parameter1->setAttribute('UTF-8');
     $mediaType->addParameter($parameter1);
     $parameter2 = new Parameter();
     $parameter2->setAttribute('charset');
     $parameter2->setValue('UTF-8');
     $mediaType->addParameter($parameter1);
     $mediaType->addParameter($parameter2);
     $this->assertEquals('text/javascript', $mediaType->getTypeSubtypeString());
     $this->assertEquals('text/javascript; utf-8; charset=UTF-8', (string) $mediaType);
 }