Exemplo n.º 1
0
 /**
  * Deletes a cookie with the given name.
  *
  * @param string $name
  * @param CookieMetadata $metadata
  * @return void
  * @throws FailureToSendException If cookie couldn't be sent to the browser.
  *     If this exception isn't thrown, there is still no guarantee that the browser
  *     received and accepted the request to delete this cookie.
  * @throws InputException If the cookie name is empty or contains invalid characters.
  */
 public function deleteCookie($name, CookieMetadata $metadata = null)
 {
     $metadataArray = $this->scope->getCookieMetadata($metadata)->__toArray();
     // explicitly set an expiration time in the metadataArray.
     $metadataArray[PhpCookieManager::KEY_EXPIRE_TIME] = PhpCookieManager::EXPIRE_NOW_TIME;
     $this->checkAbilityToSendCookie($name, '');
     // cookie value set to empty string to delete from the remote client
     $this->setCookie($name, '', $metadataArray);
     // Remove the cookie
     unset($_COOKIE[$name]);
 }
Exemplo n.º 2
0
 public function testSetTooManyCookies()
 {
     /** @var PublicCookieMetadata $publicCookieMetadata */
     $publicCookieMetadata = $this->objectManager->getObject('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata');
     $cookieValue = 'some_value';
     // Set self::MAX_NUM_COOKIES number of cookies in superglobal $_COOKIE.
     for ($i = count($_COOKIE); $i < self::MAX_NUM_COOKIES; $i++) {
         $_COOKIE['test_cookie_' . $i] = 'some_value';
     }
     $this->scopeMock->expects($this->once())->method('getPublicCookieMetadata')->with()->will($this->returnValue($publicCookieMetadata));
     try {
         $this->cookieManager->setPublicCookie(self::MAX_COOKIE_SIZE_TEST_NAME, $cookieValue, $publicCookieMetadata);
         $this->fail('Failed to throw exception of too many cookies.');
     } catch (CookieSizeLimitReachedException $e) {
         $this->assertEquals('Unable to send the cookie. Maximum number of cookies would be exceeded.', $e->getMessage());
     }
 }