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));
 }
 /**
  * @param InternetMediaType $contentType
  * @return WebResource
  * @throws Exception
  */
 public function addValidContentType(InternetMediaType $contentType)
 {
     $addedMediaType = new InternetMediaType();
     $addedMediaType->setType($contentType->getType());
     $addedMediaType->setSubtype($contentType->getSubtype());
     $this->validContentTypes[$addedMediaType->getTypeSubtypeString()] = $addedMediaType;
     if ($this->hasHttpResponse() && !$this->hasValidContentType()) {
         throw new Exception('HTTP response contains invalid content type', 2);
     }
     return $this;
 }
Пример #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);
     }
 }
Пример #4
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;
 }
Пример #5
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);
     }
 }
 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);
 }