PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zendframework/tests/ZendTest/Mail/Header/ContentTypeTest.php

https://bitbucket.org/pcelta/zf2
PHP | 92 lines | 58 code | 15 blank | 19 comment | 0 complexity | 898e4929400c267f7634d64d2fa7be94 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Mail
  9. */
  10. namespace ZendTest\Mail\Header;
  11. use Zend\Mail\Header\ContentType;
  12. /**
  13. * @category Zend
  14. * @package Zend_Mail
  15. * @subpackage UnitTests
  16. * @group Zend_Mail
  17. */
  18. class ContentTypeTest extends \PHPUnit_Framework_TestCase
  19. {
  20. public function testContentTypeFromStringCreatesValidContentTypeHeader()
  21. {
  22. $contentTypeHeader = ContentType::fromString('Content-Type: xxx/yyy');
  23. $this->assertInstanceOf('Zend\Mail\Header\HeaderInterface', $contentTypeHeader);
  24. $this->assertInstanceOf('Zend\Mail\Header\ContentType', $contentTypeHeader);
  25. }
  26. public function testContentTypeGetFieldNameReturnsHeaderName()
  27. {
  28. $contentTypeHeader = new ContentType();
  29. $this->assertEquals('Content-Type', $contentTypeHeader->getFieldName());
  30. }
  31. public function testContentTypeGetFieldValueReturnsProperValue()
  32. {
  33. $contentTypeHeader = new ContentType();
  34. $contentTypeHeader->setType('foo/bar');
  35. $this->assertEquals('foo/bar', $contentTypeHeader->getFieldValue());
  36. }
  37. public function testContentTypeToStringReturnsHeaderFormattedString()
  38. {
  39. $contentTypeHeader = new ContentType();
  40. $contentTypeHeader->setType('foo/bar');
  41. $this->assertEquals("Content-Type: foo/bar", $contentTypeHeader->toString());
  42. }
  43. public function testProvidingParametersIntroducesHeaderFolding()
  44. {
  45. $header = new ContentType();
  46. $header->setType('application/x-unit-test');
  47. $header->addParameter('charset', 'us-ascii');
  48. $string = $header->toString();
  49. $this->assertContains("Content-Type: application/x-unit-test;\r\n", $string);
  50. $this->assertContains(";\r\n charset=\"us-ascii\"", $string);
  51. }
  52. public function testExtractsExtraInformationFromContentType()
  53. {
  54. $contentTypeHeader = ContentType::fromString(
  55. 'Content-Type: multipart/alternative; boundary="Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD"'
  56. );
  57. $params = $contentTypeHeader->getParameters();
  58. $this->assertEquals($params,array('boundary' => 'Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD'));
  59. }
  60. /**
  61. * @group #2728
  62. *
  63. * Tests setting different MIME types
  64. */
  65. public function testSetContentType()
  66. {
  67. $header = new ContentType();
  68. $header->setType('application/vnd.ms-excel');
  69. $this->assertEquals('Content-Type: application/vnd.ms-excel', $header->toString());
  70. $header->setType('application/rss+xml');
  71. $this->assertEquals('Content-Type: application/rss+xml', $header->toString());
  72. $header->setType('video/mp4');
  73. $this->assertEquals('Content-Type: video/mp4', $header->toString());
  74. $header->setType('message/rfc822');
  75. $this->assertEquals('Content-Type: message/rfc822', $header->toString());
  76. }
  77. }