Navigation Menu

Skip to content

Commit

Permalink
Updated the tests to use non-empty path component, as specified in RF…
Browse files Browse the repository at this point in the history
…C6265
  • Loading branch information
David Yell committed Jun 6, 2018
1 parent bf70253 commit b9a1ade
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Http/Cookie/Cookie.php
Expand Up @@ -81,7 +81,7 @@ class Cookie implements CookieInterface
*
* @var string
*/
protected $path = '';
protected $path = '/';

/**
* Domain
Expand Down Expand Up @@ -124,7 +124,7 @@ public function __construct(
$name,
$value = '',
$expiresAt = null,
$path = '',
$path = '/',
$domain = '',
$secure = false,
$httpOnly = false
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response.php
Expand Up @@ -2175,7 +2175,7 @@ public function cookie($options = null)
/**
* Create a new response with a cookie set.
*
* ### Options
* ### Data
*
* - `value`: Value of the cookie
* - `expire`: Time the cookie expires in
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/Cookie/CookieCollectionTest.php
Expand Up @@ -483,7 +483,7 @@ public function testCreateFromServerRequest()

$cookie = $cookies->get('name');
$this->assertSame('val', $cookie->getValue());
$this->assertSame('', $cookie->getPath(), 'No path on request cookies');
$this->assertSame('/', $cookie->getPath());
$this->assertSame('', $cookie->getDomain(), 'No domain on request cookies');
}
}
19 changes: 15 additions & 4 deletions tests/TestCase/Http/Cookie/CookieTest.php
Expand Up @@ -72,7 +72,7 @@ public function testToHeaderValue()
{
$cookie = new Cookie('cakephp', 'cakephp-rocks');
$result = $cookie->toHeaderValue();
$this->assertEquals('cakephp=cakephp-rocks', $result);
$this->assertEquals('cakephp=cakephp-rocks; path=/', $result);

$date = Chronos::createFromFormat('m/d/Y h:m:s', '12/1/2027 12:00:00');

Expand All @@ -83,7 +83,7 @@ public function testToHeaderValue()
->withSecure(true);
$result = $cookie->toHeaderValue();

$expected = 'cakephp=cakephp-rocks; expires=Tue, 01-Dec-2026 12:00:00 GMT; domain=cakephp.org; secure; httponly';
$expected = 'cakephp=cakephp-rocks; expires=Tue, 01-Dec-2026 12:00:00 GMT; path=/; domain=cakephp.org; secure; httponly';
$this->assertEquals($expected, $result);
}

Expand Down Expand Up @@ -212,6 +212,17 @@ public function testWithPath()
$this->assertContains('path=/api', $new->toHeaderValue());
}

/**
* Test default path in cookies
*
* @return void
*/
public function testDefaultPath()
{
$cookie = new Cookie('cakephp', 'cakephp-rocks');
$this->assertContains('path=/', $cookie->toHeaderValue());
}

/**
* Test setting httponly in cookies
*
Expand Down Expand Up @@ -550,10 +561,10 @@ public function testToHeaderValueCollapsesComplexData()
public function testGetId()
{
$cookie = new Cookie('cakephp', 'cakephp-rocks');
$this->assertEquals('cakephp;;', $cookie->getId());
$this->assertEquals('cakephp;;/', $cookie->getId());

$cookie = new Cookie('CAKEPHP', 'cakephp-rocks');
$this->assertEquals('cakephp;;', $cookie->getId());
$this->assertEquals('cakephp;;/', $cookie->getId());

$cookie = new Cookie('test', 'val', null, '/path', 'example.com');
$this->assertEquals('test;example.com;/path', $cookie->getId());
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/ResponseTest.php
Expand Up @@ -1773,7 +1773,7 @@ public function testGetCookiesArrayValue()
'name' => 'urmc',
'value' => '{"user_id":1,"token":"abc123"}',
'expire' => null,
'path' => '',
'path' => '/',
'domain' => '',
'secure' => false,
'httpOnly' => true
Expand Down

0 comments on commit b9a1ade

Please sign in to comment.