/** * Sets the value of the header field. * * Accepts either strings or objects of type \Ableron\Lib\Net\InternetMediaType. * * @param string|\Ableron\Lib\Net\InternetMediaType $fieldValue The field value to set * @throws \Ableron\Core\Exception\SystemException * @return void */ public function setFieldValue($fieldValue) { if (is_string($fieldValue)) { $this->fieldValue = InternetMediaType::parse($fieldValue); } elseif ($fieldValue instanceof InternetMediaType) { $this->fieldValue = $fieldValue; } else { throw new SystemException(sprintf('Unable to set header field value to %s - Field value must be a string or an object of type \\Ableron\\Lib\\Net\\InternetMediaType. Given: %s', StringUtil::toString($fieldValue), gettype($fieldValue)), 0, E_USER_WARNING, __FILE__, __LINE__); } }
/** * Returns whether the given internet media type is known by this library. * * Returns TRUE in case the given internet media type is known by this library. * Otherwise returns FALSE. * * @param \Ableron\Lib\Net\InternetMediaType $internetMediaType The internet media type to check * @return bool */ public static function isKnown(InternetMediaType $internetMediaType) { return isset(self::$internetMediaTypes[$internetMediaType->getPrimaryType()][$internetMediaType->getSubType()]); }
/** * Tests whether stripComments() handles invalid comments as expected. * * @return void */ public function testStripCommentsHandlesInvalidComments() { try { InternetMediaType::stripComments('foobar (b(az)'); $this->fail('stripComments() does not throw exceptions as expected'); } catch (SystemException $e) { $this->assertSame('Unable to strip comments from "foobar (b(az)" - Comment not closed!', $e->getMessage()); $this->assertSame(0, $e->getCode()); $this->assertSame(E_USER_NOTICE, $e->getSeverity()); $this->assertNull($e->getPrevious()); } }
/** * Checks whether display() throws an exception on non-existing template. * * @return void */ public function testDisplayChecksTemplateExistence() { try { $this->getTemplateHandler()->display('/FooBarBaz/Templates/Frontend/fooBarBaz.tpl', InternetMediaType::parse('text/html')); $this->fail('display() does not check for template existence'); } catch (SystemException $e) { $this->assertSame('Template file does not exist: /FooBarBaz/Templates/Frontend/fooBarBaz.tpl', $e->getMessage()); $this->assertSame(0, $e->getCode()); $this->assertSame(E_USER_ERROR, $e->getSeverity()); } }