HeaderValueTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Mail
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Mail_Message
  24. */
  25. require_once 'Zend/Mail/Header/HeaderValue.php';
  26. class Zend_Mail_Header_HeaderValueTest extends PHPUnit_Framework_TestCase
  27. {
  28. /**
  29. * Data for filter value
  30. */
  31. public function getFilterValues()
  32. {
  33. return array(
  34. array("This is a\n test", "This is a test"),
  35. array("This is a\r test", "This is a test"),
  36. array("This is a\n\r test", "This is a test"),
  37. array("This is a\r\n test", "This is a\r\n test"),
  38. array("This is a \r\ntest", "This is a test"),
  39. array("This is a \r\n\n test", "This is a test"),
  40. array("This is a\n\n test", "This is a test"),
  41. array("This is a\r\r test", "This is a test"),
  42. array("This is a \r\r\n test", "This is a \r\n test"),
  43. array("This is a \r\n\r\ntest", "This is a test"),
  44. array("This is a \r\n\n\r\n test", "This is a \r\n test")
  45. );
  46. }
  47. /**
  48. * @dataProvider getFilterValues
  49. * @group ZF2015-04
  50. */
  51. public function testFilterValue($value, $expected)
  52. {
  53. $this->assertEquals($expected, Zend_Mail_Header_HeaderValue::filter($value));
  54. }
  55. public function validateValues()
  56. {
  57. return array(
  58. array("This is a\n test", 'assertFalse'),
  59. array("This is a\r test", 'assertFalse'),
  60. array("This is a\n\r test", 'assertFalse'),
  61. array("This is a\r\n test", 'assertTrue'),
  62. array("This is a \r\ntest", 'assertFalse'),
  63. array("This is a \r\n\n test", 'assertFalse'),
  64. array("This is a\n\n test", 'assertFalse'),
  65. array("This is a\r\r test", 'assertFalse'),
  66. array("This is a \r\r\n test", 'assertFalse'),
  67. array("This is a \r\n\r\ntest", 'assertFalse'),
  68. array("This is a \r\n\n\r\n test", 'assertFalse')
  69. );
  70. }
  71. /**
  72. * @dataProvider validateValues
  73. * @group ZF2015-04
  74. */
  75. public function testValidateValue($value, $assertion)
  76. {
  77. $this->{$assertion}(Zend_Mail_Header_HeaderValue::isValid($value));
  78. }
  79. public function assertValues()
  80. {
  81. return array(
  82. array("This is a\n test"),
  83. array("This is a\r test"),
  84. array("This is a\n\r test"),
  85. array("This is a \r\ntest"),
  86. array("This is a \r\n\n test"),
  87. array("This is a\n\n test"),
  88. array("This is a\r\r test"),
  89. array("This is a \r\r\n test"),
  90. array("This is a \r\n\r\ntest"),
  91. array("This is a \r\n\n\r\n test")
  92. );
  93. }
  94. /**
  95. * @dataProvider assertValues
  96. * @group ZF2015-04
  97. */
  98. public function testAssertValidRaisesExceptionForInvalidValues($value)
  99. {
  100. $this->setExpectedException('Zend_Mail_Exception', 'Invalid');
  101. Zend_Mail_Header_HeaderValue::assertValid($value);
  102. }
  103. }