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.

50 lines
1.7 KiB

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