HeaderValueTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_Http
  17. * @subpackage Header
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. require_once 'Zend/Http/Header/HeaderValue.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Http_Cookie
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Http
  30. * @group Zend_Http_Header
  31. */
  32. class Zend_Http_Header_HeaderValueTest extends PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * Data for filter value
  36. */
  37. public function getFilterValues()
  38. {
  39. return array(
  40. array("This is a\n test", "This is a test"),
  41. array("This is a\r test", "This is a test"),
  42. array("This is a\n\r test", "This is a test"),
  43. array("This is a\r\n test", "This is a test"),
  44. array("This is a \r\ntest", "This is a test"),
  45. array("This is a \r\n\n test", "This is a test"),
  46. array("This is a\n\n test", "This is a test"),
  47. array("This is a\r\r test", "This is a test"),
  48. array("This is a \r\r\n test", "This is a test"),
  49. array("This is a \r\n\r\ntest", "This is a test"),
  50. array("This is a \r\n\n\r\n test", "This is a test")
  51. );
  52. }
  53. /**
  54. * @dataProvider getFilterValues
  55. * @group ZF2015-04
  56. */
  57. public function testFiltersValuesPerRfc7230($value, $expected)
  58. {
  59. $this->assertEquals($expected, Zend_Http_Header_HeaderValue::filter($value));
  60. }
  61. public function validateValues()
  62. {
  63. return array(
  64. array("This is a\n test", 'assertFalse'),
  65. array("This is a\r test", 'assertFalse'),
  66. array("This is a\n\r test", 'assertFalse'),
  67. array("This is a\r\n test", 'assertFalse'),
  68. array("This is a \r\ntest", 'assertFalse'),
  69. array("This is a \r\n\n test", 'assertFalse'),
  70. array("This is a\n\n test", 'assertFalse'),
  71. array("This is a\r\r test", 'assertFalse'),
  72. array("This is a \r\r\n test", 'assertFalse'),
  73. array("This is a \r\n\r\ntest", 'assertFalse'),
  74. array("This is a \r\n\n\r\n test", 'assertFalse')
  75. );
  76. }
  77. /**
  78. * @dataProvider validateValues
  79. * @group ZF2015-04
  80. */
  81. public function testValidatesValuesPerRfc7230($value, $assertion)
  82. {
  83. $this->{$assertion}(Zend_Http_Header_HeaderValue::isValid($value));
  84. }
  85. public function assertValues()
  86. {
  87. return array(
  88. array("This is a\n test"),
  89. array("This is a\r test"),
  90. array("This is a\n\r test"),
  91. array("This is a \r\ntest"),
  92. array("This is a \r\n\n test"),
  93. array("This is a\n\n test"),
  94. array("This is a\r\r test"),
  95. array("This is a \r\r\n test"),
  96. array("This is a \r\n\r\ntest"),
  97. array("This is a \r\n\n\r\n test")
  98. );
  99. }
  100. /**
  101. * @dataProvider assertValues
  102. * @group ZF2015-04
  103. */
  104. public function testAssertValidRaisesExceptionForInvalidValue($value)
  105. {
  106. $this->setExpectedException('Zend_Http_Header_Exception_InvalidArgumentException');
  107. Zend_Http_Header_HeaderValue::assertValid($value);
  108. }
  109. }