Skip to content

Commit

Permalink
Add additional test for read/write and remove destroy.
Browse files Browse the repository at this point in the history
With CookieComponent managing multiple cookies, the destroy() method
would simply be an alias for delete() which is not useful.
  • Loading branch information
markstory committed May 29, 2014
1 parent eee450f commit e4ddc5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
27 changes: 0 additions & 27 deletions src/Controller/Component/CookieComponent.php
Expand Up @@ -266,33 +266,6 @@ public function delete($key) {
}
}

/**
* Destroy current cookie
*
* You must use this method before any output is sent to the browser.
* Failure to do so will result in header already sent errors.
*
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::destroy
*/
public function destroy() {
$cookieName = $this->config('name');
if (empty($this->_values[$cookieName])) {
$this->read();
}

foreach ($this->_values[$cookieName] as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
unset($this->_values[$cookieName][$name][$key]);
$this->_delete("[$name][$key]");
}
}
unset($this->_values[$cookieName][$name]);
$this->_delete("[$name]");
}
}

/**
* Get / set encryption type. Use this method in ex: AppController::beforeFilter()
* before you have read or written any cookies.
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/Controller/Component/CookieComponentTest.php
Expand Up @@ -194,6 +194,19 @@ public function testWriteSimple() {
$this->assertEquals('value', $result);
}

/**
* Test writes don't omit request data from being read.
*
* @return void
*/
public function testWriteThanRead() {
$this->request->cookies = [
'User' => ['name' => 'mark']
];
$this->Cookie->write('Testing', 'value');
$this->assertEquals('mark', $this->Cookie->read('User.name'));
}

/**
* test write() encrypted data with falsey value
*
Expand Down

0 comments on commit e4ddc5c

Please sign in to comment.