PhpCookieManagerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Stdlib\Cookie;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. /**
  9. * Test PhpCookieManager
  10. *
  11. */
  12. class PhpCookieManagerTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * Object Manager
  16. *
  17. * @var \Magento\Framework\ObjectManagerInterface
  18. */
  19. private $objectManager;
  20. /**
  21. * Cookie Manager
  22. *
  23. * @var \Magento\Framework\Stdlib\Cookie\PhpCookieManager
  24. */
  25. protected $cookieManager;
  26. protected function setUp()
  27. {
  28. $this->objectManager = Bootstrap::getObjectManager();
  29. $this->cookieManager = $this->objectManager->create(\Magento\Framework\Stdlib\Cookie\PhpCookieManager::class);
  30. }
  31. public function testGetCookie()
  32. {
  33. $preTestCookies = $_COOKIE;
  34. $cookieName = 'cookie name';
  35. $cookieValue = 'cookie value';
  36. $defaultCookieValue = 'default';
  37. $_COOKIE[$cookieName] = $cookieValue;
  38. $this->assertEquals(
  39. $defaultCookieValue,
  40. $this->cookieManager->getCookie('unknown cookieName', $defaultCookieValue)
  41. );
  42. $this->assertEquals($cookieValue, $this->cookieManager->getCookie($cookieName, $defaultCookieValue));
  43. $this->assertEquals($defaultCookieValue, $this->cookieManager->getCookie(null, $defaultCookieValue));
  44. $this->assertNull($this->cookieManager->getCookie(null));
  45. $_COOKIE = $preTestCookies;
  46. }
  47. /**
  48. * It is not possible to write integration tests for CookieManager::setSensitiveCookie().
  49. * PHPUnit the following error when calling the function:
  50. *
  51. * PHPUnit\Framework\Error_Warning : Cannot modify header information - headers already sent
  52. */
  53. public function testSetSensitiveCookie()
  54. {
  55. }
  56. /**
  57. * It is not possible to write integration tests for CookieManager::setSensitiveCookie().
  58. * PHPUnit the following error when calling the function:
  59. *
  60. * PHPUnit\Framework\Error_Warning : Cannot modify header information - headers already sent
  61. */
  62. public function testSetPublicCookie()
  63. {
  64. }
  65. /**
  66. * It is not possible to write integration tests for CookieManager::deleteCookie().
  67. * PHPUnit the following error when calling the function:
  68. *
  69. * PHPUnit\Framework\Error_Warning : Cannot modify header information - headers already sent
  70. */
  71. public function testDeleteCookie()
  72. {
  73. }
  74. }