CookieTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpFoundation;
  11. use Symfony\Component\HttpFoundation\Cookie;
  12. /**
  13. * CookieTest
  14. *
  15. * @author John Kary <john@johnkary.net>
  16. */
  17. class CookieTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function invalidNames()
  20. {
  21. return array(
  22. array(''),
  23. array(",MyName"),
  24. array(";MyName"),
  25. array(" MyName"),
  26. array("\tMyName"),
  27. array("\rMyName"),
  28. array("\nMyName"),
  29. array("\013MyName"),
  30. array("\014MyName"),
  31. );
  32. }
  33. public function invalidValues()
  34. {
  35. return array(
  36. array(",MyValue"),
  37. array(";MyValue"),
  38. array(" MyValue"),
  39. array("\tMyValue"),
  40. array("\rMyValue"),
  41. array("\nMyValue"),
  42. array("\013MyValue"),
  43. array("\014MyValue"),
  44. );
  45. }
  46. /**
  47. * @dataProvider invalidNames
  48. * @expectedException InvalidArgumentException
  49. * @covers Symfony\Component\HttpFoundation\Cookie::__construct
  50. */
  51. public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name)
  52. {
  53. new Cookie($name);
  54. }
  55. /**
  56. * @dataProvider invalidValues
  57. * @expectedException InvalidArgumentException
  58. * @covers Symfony\Component\HttpFoundation\Cookie::__construct
  59. */
  60. public function testInstantiationThrowsExceptionIfCookieValueContainsInvalidCharacters($value)
  61. {
  62. new Cookie('MyCookie', $value);
  63. }
  64. /**
  65. * @expectedException InvalidArgumentException
  66. */
  67. public function testInvalidExpiration()
  68. {
  69. $cookie = new Cookie('MyCookie', 'foo','bar');
  70. }
  71. /**
  72. * @covers Symfony\Component\HttpFoundation\Cookie::getValue
  73. */
  74. public function testGetValue()
  75. {
  76. $value = 'MyValue';
  77. $cookie = new Cookie('MyCookie', $value);
  78. $this->assertSame($value, $cookie->getValue(), '->getValue() returns the proper value');
  79. }
  80. }