Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Phalcon\Http\Response\Cookies::getCookies. #13591

Merged
merged 2 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Added `Phalcon\Tag::renderTitle()` that renders the title enclosed in `<title>` tags. [#13547](https://github.com/phalcon/cphalcon/issues/13547)
- Added `hasHeader()` method to `Phalcon\Http\Response` to provide the ability to check if a header exists. [PR-12189](https://github.com/phalcon/cphalcon/pull/12189)
- Added global setting `orm.case_insensitive_column_map` to attempt to find value in the column map case-insensitively. Can be also enabled by setting `caseInsensitiveColumnMap` key in `\Phalcon\Mvc\Model::setup()`. [#11802](https://github.com/phalcon/cphalcon/pull/11802)
- Added `Phalcon\Http\Response\Cookies::getCookies` [#13591](https://github.com/phalcon/cphalcon/pull/13591)

## Changed
- By configuring `prefix` and `statsKey` the `Phalcon\Cache\Backend\Redis::queryKeys` no longer returns prefixed keys, now it returns original keys without prefix. [PR-13456](https://github.com/phalcon/cphalcon/pull/13456)
Expand Down
8 changes: 8 additions & 0 deletions phalcon/http/response/cookies.zep
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ class Cookies implements CookiesInterface, InjectionAwareInterface
return cookie;
}

/**
* Gets all cookies from the bag
*/
public function getCookies() -> array
{
return this->_cookies;
}

/**
* Check if a cookie is defined in the bag or exists in the _COOKIE superglobal
*/
Expand Down
54 changes: 54 additions & 0 deletions tests/unit/Http/Response/CookiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace Phalcon\Test\Unit\Http\Response;

use Phalcon\Di;
use Phalcon\Http\Cookie;
use Phalcon\Http\CookieInterface;
use Phalcon\Http\Response;
use Phalcon\Http\Response\Cookies;
use Phalcon\Test\Unit\Http\Helper\HttpBase;
use Phalcon\Session\Adapter\Files as SessionAdapter;

/**
* Phalcon\Test\Unit\Http\Response\Http\CookiesTest
Expand Down Expand Up @@ -41,4 +46,53 @@ function () {
}
);
}

/**
* Tests getCookies is work.
* @author limx <715557344@qq.com>
*/
public function testGetCookies()
{
$cookies = new Cookies();

Di::reset();
$di = new Di();
$di->set('response', function () {
return new Response();
});
$di->set('session', function () {
return new SessionAdapter();
});

$cookies->setDI($di);

$cookies->set('x-token', '1bf0bc92ed7dcc80d337a5755f879878');
$cookies->set('x-user-id', 1);

$this->specify(
"The cookies is not a array.",
function () use ($cookies) {
expect(is_array($cookies->getCookies()))->true();
}
);

$this->specify(
"The cookie is not instance of CookieInterface",
function () use ($cookies) {
$cookieArray = $cookies->getCookies();
expect($cookieArray['x-token'] instanceof CookieInterface)->true();
expect($cookieArray['x-user-id'] instanceof CookieInterface)->true();
}
);

$this->specify(
"The cookie is not correct.",
function () use ($cookies) {
/** @var Cookie[] $cookieArray */
$cookieArray = $cookies->getCookies();
expect($cookieArray['x-token']->getValue())->equals('1bf0bc92ed7dcc80d337a5755f879878');
expect($cookieArray['x-user-id']->getValue())->equals(1);
}
);
}
}