You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

  1. <?php
  2. class MediaTypeTest extends PHPUnit_Framework_TestCase {
  3. public function testParseTextHtml() {
  4. $type = new p3k\XRay\MediaType('text/html');
  5. $this->assertEquals('text', $type->type);
  6. $this->assertEquals('html', $type->subtype);
  7. $this->assertEquals('html', $type->format);
  8. $this->assertEquals(null, $type->charset);
  9. }
  10. public function testParseTextHtmlUtf8() {
  11. $type = new p3k\XRay\MediaType('text/html; charset=UTF-8');
  12. $this->assertEquals('text', $type->type);
  13. $this->assertEquals('html', $type->subtype);
  14. $this->assertEquals('html', $type->format);
  15. $this->assertEquals('UTF-8', $type->charset);
  16. }
  17. public function testParseTextHtmlUtf8Extra() {
  18. $type = new p3k\XRay\MediaType('text/html; hello=world; charset=UTF-8');
  19. $this->assertEquals('text', $type->type);
  20. $this->assertEquals('html', $type->subtype);
  21. $this->assertEquals('html', $type->format);
  22. $this->assertEquals('UTF-8', $type->charset);
  23. }
  24. public function testParseApplicationJson() {
  25. $type = new p3k\XRay\MediaType('application/json');
  26. $this->assertEquals('application', $type->type);
  27. $this->assertEquals('json', $type->subtype);
  28. $this->assertEquals('json', $type->format);
  29. $this->assertEquals(null, $type->charset);
  30. }
  31. public function testParseApplicationJsonFeed() {
  32. $type = new p3k\XRay\MediaType('application/feed+json');
  33. $this->assertEquals('application', $type->type);
  34. $this->assertEquals('feed+json', $type->subtype);
  35. $this->assertEquals('json', $type->format);
  36. $this->assertEquals(null, $type->charset);
  37. }
  38. }