Skip to content

Commit

Permalink
fix(cookie): options parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
zsilbi committed Sep 11, 2020
1 parent daa1ba8 commit 7561dcd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-4.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ This component can be used to create SQL statements using a fluent interface. Op
- Fixed `Phalcon\Validation\Validator\Uniqueness` fixed except query [#15084](https://github.com/phalcon/cphalcon/issues/15084)
- Fixed `Phalcon\Mvc\Model` to also check the params option in cascade relations when deleting. [#15098](https://github.com/phalcon/cphalcon/issues/15098)
- Fixed `Phalcon\Mvc\Model\CriteriaInterface::where()` parameters. [#15144](https://github.com/phalcon/cphalcon/issues/15144)
- Fixed `Phalcon\Http\Response\Cookies::set()` to utilize the options parameter correctly. [#15129](https://github.com/phalcon/cphalcon/issues/15129)

## Removed
- Removed `Phalcon\Http\Cookie` binding to session [#11770](https://github.com/phalcon/cphalcon/issues/11770)
Expand Down
3 changes: 2 additions & 1 deletion phalcon/Http/Response/Cookies.zep
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Cookies extends AbstractInjectionAware implements CookiesInterface
let cookie =
<CookieInterface> this->container->get(
"Phalcon\\Http\\Cookie",
[name, value, expire, path, secure, domain, httpOnly]
[name, value, expire, path, secure, domain, httpOnly, options]
);

/**
Expand Down Expand Up @@ -271,6 +271,7 @@ class Cookies extends AbstractInjectionAware implements CookiesInterface
cookie->setSecure(secure);
cookie->setDomain(domain);
cookie->setHttpOnly(httpOnly);
cookie->setOptions(options);
cookie->setSignKey(this->signKey);
}

Expand Down
86 changes: 86 additions & 0 deletions tests/unit/Http/Response/Cookies/GetSetCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,90 @@ public function httpCookieSetHttpOnly(UnitTester $I)
$I->assertNotRegexp('/HttpOnly$/', $cookieTwo);
$I->assertNotRegexp('/HttpOnly$/', $cookieThree);
}

/**
* Test Http\Response\Cookies - set() options parameter
*
* @author Phalcon Team <[email protected]>
* @since 2020-09-10
* @issue https://github.com/phalcon/cphalcon/issues/15129
*/
public function httpCookieSetOptions(UnitTester $I)
{
$I->wantToTest('Http\Response\Cookies - set() options parameter');

if(!version_compare(phpversion(), '7.3', '>=')) {
$I->skipTest('Cookie options are only available starting from PHP 7.3');
}

$I->checkExtensionIsLoaded('xdebug');

$this->setDiService('crypt');
$container = $this->getDi();

$cookie = new Cookies();
$cookie->setDI($container);
$cookie->useEncryption(false);

$cookie->set(
'samesite-cookie-1',
'potato',
time() + 86400,
'/',
false,
'localhost',
false,
[
'samesite' => 'None'
]
);

$cookie->set(
'samesite-cookie-2',
'potato',
time() + 86400,
'/',
false,
'localhost',
false,
[
'samesite' => 'Lax'
]
);

$cookie->set(
'samesite-cookie-3',
'potato',
time() + 86400,
'/',
false,
'localhost',
false,
[
'samesite' => 'Strict'
]
);

$cookie->set(
'samesite-cookie-4',
'potato',
time() + 86400,
'/',
false,
'localhost',
false
);

$cookie->send();

$cookieOne = $this->getCookie('samesite-cookie-1');
$cookieTwo = $this->getCookie('samesite-cookie-2');
$cookieThree = $this->getCookie('samesite-cookie-3');
$cookieFour = $this->getCookie('samesite-cookie-4');

$I->assertRegexp('/SameSite=None$/', $cookieOne);
$I->assertRegexp('/SameSite=Lax$/', $cookieTwo);
$I->assertRegexp('/SameSite=Strict$/', $cookieThree);
$I->assertNotRegexp('/SameSite/', $cookieFour);
}
}

0 comments on commit 7561dcd

Please sign in to comment.