CookieTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Components\BrowserKit;
  11. use Symfony\Components\BrowserKit\Cookie;
  12. class CookieTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testGetName()
  15. {
  16. $cookie = new Cookie('foo', 'bar');
  17. $this->assertEquals('foo', $cookie->getName(), '->getName() returns the cookie name');
  18. }
  19. public function testGetValue()
  20. {
  21. $cookie = new Cookie('foo', 'bar');
  22. $this->assertEquals('bar', $cookie->getValue(), '->getValue() returns the cookie value');
  23. }
  24. public function testGetPath()
  25. {
  26. $cookie = new Cookie('foo', 'bar', 0);
  27. $this->assertEquals('/', $cookie->getPath(), '->getPath() returns / is no path is defined');
  28. $cookie = new Cookie('foo', 'bar', 0, '/foo');
  29. $this->assertEquals('/foo', $cookie->getPath(), '->getPath() returns the cookie path');
  30. }
  31. public function testGetDomain()
  32. {
  33. $cookie = new Cookie('foo', 'bar', 0, '/', 'foo.com');
  34. $this->assertEquals('foo.com', $cookie->getDomain(), '->getDomain() returns the cookie domain');
  35. }
  36. public function testIsSecure()
  37. {
  38. $cookie = new Cookie('foo', 'bar');
  39. $this->assertFalse($cookie->isSecure(), '->isSecure() returns false if not defined');
  40. $cookie = new Cookie('foo', 'bar', 0, '/', 'foo.com', true);
  41. $this->assertTrue($cookie->isSecure(), '->getDomain() returns the cookie secure flag');
  42. }
  43. public function testGetExpireTime()
  44. {
  45. $cookie = new Cookie('foo', 'bar');
  46. $this->assertEquals(0, $cookie->getExpireTime(), '->getExpireTime() returns the expire time');
  47. $cookie = new Cookie('foo', 'bar', $time = time() - 86400);
  48. $this->assertEquals($time, $cookie->getExpireTime(), '->getExpireTime() returns the expire time');
  49. }
  50. public function testIsExpired()
  51. {
  52. $cookie = new Cookie('foo', 'bar');
  53. $this->assertFalse($cookie->isExpired(), '->isExpired() returns false when the cookie never expires (0 as expire time)');
  54. $cookie = new Cookie('foo', 'bar', time() - 86400);
  55. $this->assertTrue($cookie->isExpired(), '->isExpired() returns true when the cookie is expired');
  56. }
  57. }