2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CookieComponentTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5435
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
|
|
|
|
App::uses('Component', 'Controller');
|
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('CookieComponent', 'Controller/Component');
|
|
|
|
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* CookieComponentTestController class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
class CookieComponentTestController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* components property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Cookie');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* beforeFilter method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function beforeFilter() {
|
|
|
|
$this->Cookie->name = 'CakeTestCookie';
|
|
|
|
$this->Cookie->time = 10;
|
|
|
|
$this->Cookie->path = '/';
|
|
|
|
$this->Cookie->domain = '';
|
|
|
|
$this->Cookie->secure = false;
|
|
|
|
$this->Cookie->key = 'somerandomhaskey';
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CookieComponentTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class CookieComponentTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* Controller property
|
|
|
|
*
|
|
|
|
* @var CookieComponentTestController
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Controller;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* start
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-10 04:47:02 +00:00
|
|
|
function setUp() {
|
2010-09-19 23:30:41 +00:00
|
|
|
$_COOKIE = array();
|
2010-07-04 21:15:10 +00:00
|
|
|
$Collection = new ComponentCollection();
|
2010-09-19 23:42:06 +00:00
|
|
|
$this->Cookie = $this->getMock('CookieComponent', array('_setcookie'), array($Collection));
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->Controller = new CookieComponentTestController();
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->initialize($this->Controller);
|
|
|
|
|
|
|
|
$this->Cookie->name = 'CakeTestCookie';
|
|
|
|
$this->Cookie->time = 10;
|
|
|
|
$this->Cookie->path = '/';
|
|
|
|
$this->Cookie->domain = '';
|
|
|
|
$this->Cookie->secure = false;
|
|
|
|
$this->Cookie->key = 'somerandomhaskey';
|
2010-09-19 23:30:41 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->startup($this->Controller);
|
2008-06-10 22:38:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-10 04:47:02 +00:00
|
|
|
function tearDown() {
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->destroy();
|
2009-03-19 21:10:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-19 23:42:06 +00:00
|
|
|
/**
|
|
|
|
* sets up some default cookie data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-10 04:47:02 +00:00
|
|
|
protected function _setCookieData() {
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
|
|
|
|
$this->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
|
|
|
|
$this->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
|
|
|
|
$this->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
|
|
|
|
|
|
|
|
$this->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
|
|
|
|
$this->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
|
|
|
|
$this->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
|
|
|
|
$this->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
|
2010-06-10 04:47:02 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 03:57:04 +00:00
|
|
|
/**
|
|
|
|
* test that initialize sets settings from components array
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-07-04 21:15:10 +00:00
|
|
|
function testSettings() {
|
2009-12-17 03:57:04 +00:00
|
|
|
$settings = array(
|
|
|
|
'time' => '5 days',
|
|
|
|
'path' => '/'
|
|
|
|
);
|
2010-07-04 21:15:10 +00:00
|
|
|
$Cookie = new CookieComponent(new ComponentCollection(), $settings);
|
|
|
|
$this->assertEqual($Cookie->time, $settings['time']);
|
|
|
|
$this->assertEqual($Cookie->path, $settings['path']);
|
2009-12-17 03:57:04 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testCookieName
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testCookieName() {
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->assertEqual($this->Cookie->name, 'CakeTestCookie');
|
2008-06-10 22:38:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testReadEncryptedCookieData
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testReadEncryptedCookieData() {
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->_setCookieData();
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testReadPlainCookieData
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testReadPlainCookieData() {
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->_setCookieData();
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-19 23:42:06 +00:00
|
|
|
/**
|
|
|
|
* test a simple write()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testWriteSimple() {
|
|
|
|
$this->Cookie->expects($this->once())->method('_setcookie');
|
|
|
|
|
|
|
|
$this->Cookie->write('Testing', 'value');
|
|
|
|
$result = $this->Cookie->read('Testing');
|
|
|
|
|
|
|
|
$this->assertEquals('value', $result);
|
|
|
|
}
|
|
|
|
|
2010-09-26 03:24:37 +00:00
|
|
|
/**
|
|
|
|
* test write with httpOnly cookies
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testWriteHttpOnly() {
|
|
|
|
$this->Cookie->httpOnly = true;
|
|
|
|
$this->Cookie->secure = false;
|
|
|
|
$this->Cookie->expects($this->once())->method('_setcookie')
|
|
|
|
->with('CakeTestCookie[Testing]', 'value', time() + 10, '/', '', false, true);
|
|
|
|
|
|
|
|
$this->Cookie->write('Testing', 'value', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test delete with httpOnly
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testDeleteHttpOnly() {
|
|
|
|
$this->Cookie->httpOnly = true;
|
|
|
|
$this->Cookie->secure = false;
|
|
|
|
$this->Cookie->expects($this->once())->method('_setcookie')
|
|
|
|
->with('CakeTestCookie[Testing]', '', time() - 42000, '/', '', false, true);
|
|
|
|
|
|
|
|
$this->Cookie->delete('Testing', false);
|
|
|
|
}
|
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testWritePlainCookieArray
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-27 06:52:36 +00:00
|
|
|
function testWritePlainCookieArray() {
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->write(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!'), null, false);
|
2008-06-27 06:52:36 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->assertEqual($this->Cookie->read('name'), 'CakePHP');
|
|
|
|
$this->assertEqual($this->Cookie->read('version'), '1.2.0.x');
|
|
|
|
$this->assertEqual($this->Cookie->read('tag'), 'CakePHP Rocks!');
|
2008-06-27 06:52:36 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->delete('name');
|
|
|
|
$this->Cookie->delete('version');
|
|
|
|
$this->Cookie->delete('tag');
|
2008-06-27 06:52:36 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testReadingCookieValue
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testReadingCookieValue() {
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->_setCookieData();
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read();
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array(
|
|
|
|
'Encrytped_array' => array(
|
|
|
|
'name' => 'CakePHP',
|
|
|
|
'version' => '1.2.0.x',
|
|
|
|
'tag' => 'CakePHP Rocks!'),
|
|
|
|
'Encrytped_multi_cookies' => array(
|
|
|
|
'name' => 'CakePHP',
|
|
|
|
'version' => '1.2.0.x',
|
|
|
|
'tag' => 'CakePHP Rocks!'),
|
|
|
|
'Plain_array' => array(
|
|
|
|
'name' => 'CakePHP',
|
|
|
|
'version' => '1.2.0.x',
|
|
|
|
'tag' => 'CakePHP Rocks!'),
|
|
|
|
'Plain_multi_cookies' => array(
|
|
|
|
'name' => 'CakePHP',
|
|
|
|
'version' => '1.2.0.x',
|
|
|
|
'tag' => 'CakePHP Rocks!'));
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testDeleteCookieValue
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testDeleteCookieValue() {
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->_setCookieData();
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->delete('Encrytped_multi_cookies.name');
|
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->delete('Encrytped_array');
|
|
|
|
$data = $this->Cookie->read('Encrytped_array');
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->assertNull($data);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->delete('Plain_multi_cookies.name');
|
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->delete('Plain_array');
|
|
|
|
$data = $this->Cookie->read('Plain_array');
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->assertNull($data);
|
2008-06-10 22:38:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testReadingCookieArray
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testReadingCookieArray() {
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->_setCookieData();
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array.name');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array.version');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = '1.2.0.x';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array.tag');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP Rocks!';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies.name');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies.version');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = '1.2.0.x';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies.tag');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP Rocks!';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array.name');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array.version');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = '1.2.0.x';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array.tag');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP Rocks!';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies.name');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies.version');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = '1.2.0.x';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies.tag');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = 'CakePHP Rocks!';
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testReadingCookieDataOnStartup
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testReadingCookieDataOnStartup() {
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array');
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->assertNull($data);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies');
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->assertNull($data);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array');
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->assertNull($data);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies');
|
2010-06-10 04:47:02 +00:00
|
|
|
$this->assertNull($data);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
|
|
|
$_COOKIE['CakeTestCookie'] = array(
|
2008-10-09 02:35:33 +00:00
|
|
|
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
|
2008-06-10 22:38:05 +00:00
|
|
|
'Encrytped_multi_cookies' => array(
|
2008-10-09 02:35:33 +00:00
|
|
|
'name' => $this->__encrypt('CakePHP'),
|
|
|
|
'version' => $this->__encrypt('1.2.0.x'),
|
|
|
|
'tag' => $this->__encrypt('CakePHP Rocks!')),
|
2008-06-10 22:38:05 +00:00
|
|
|
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
|
|
|
|
'Plain_multi_cookies' => array(
|
|
|
|
'name' => 'CakePHP',
|
|
|
|
'version' => '1.2.0.x',
|
|
|
|
'tag' => 'CakePHP Rocks!'));
|
2010-12-18 05:03:03 +00:00
|
|
|
$this->Cookie->startup(null);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->destroy();
|
2008-06-10 22:38:05 +00:00
|
|
|
unset($_COOKIE['CakeTestCookie']);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* testReadingCookieDataWithoutStartup
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
function testReadingCookieDataWithoutStartup() {
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array');
|
2010-06-10 04:47:02 +00:00
|
|
|
$expected = null;
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies');
|
2010-06-10 04:47:02 +00:00
|
|
|
$expected = null;
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array');
|
2010-06-10 04:47:02 +00:00
|
|
|
$expected = null;
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies');
|
2010-06-10 04:47:02 +00:00
|
|
|
$expected = null;
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
|
|
|
$_COOKIE['CakeTestCookie'] = array(
|
2008-10-09 02:35:33 +00:00
|
|
|
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
|
2008-06-10 22:38:05 +00:00
|
|
|
'Encrytped_multi_cookies' => array(
|
2008-10-09 02:35:33 +00:00
|
|
|
'name' => $this->__encrypt('CakePHP'),
|
|
|
|
'version' => $this->__encrypt('1.2.0.x'),
|
|
|
|
'tag' => $this->__encrypt('CakePHP Rocks!')),
|
2008-06-10 22:38:05 +00:00
|
|
|
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
|
|
|
|
'Plain_multi_cookies' => array(
|
|
|
|
'name' => 'CakePHP',
|
|
|
|
'version' => '1.2.0.x',
|
|
|
|
'tag' => 'CakePHP Rocks!'));
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_array');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Encrytped_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_array');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
|
|
|
|
2010-07-04 21:15:10 +00:00
|
|
|
$data = $this->Cookie->read('Plain_multi_cookies');
|
2008-06-10 22:38:05 +00:00
|
|
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
|
|
|
$this->assertEqual($data, $expected);
|
2010-07-04 21:15:10 +00:00
|
|
|
$this->Cookie->destroy();
|
2008-06-10 22:38:05 +00:00
|
|
|
unset($_COOKIE['CakeTestCookie']);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-25 03:09:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that no error is issued for non array data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testNoErrorOnNonArrayData() {
|
2010-12-11 03:51:42 +00:00
|
|
|
$this->Cookie->destroy();
|
2010-11-25 03:09:08 +00:00
|
|
|
$_COOKIE['CakeTestCookie'] = 'kaboom';
|
|
|
|
|
2010-12-11 03:51:42 +00:00
|
|
|
$this->assertNull($this->Cookie->read('value'));
|
2010-11-25 03:09:08 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 02:35:33 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* encrypt method
|
2008-10-09 02:35:33 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @param mixed $value
|
|
|
|
* @return string
|
|
|
|
* @access private
|
2008-10-09 02:35:33 +00:00
|
|
|
*/
|
2009-03-19 21:10:13 +00:00
|
|
|
function __encrypt($value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
$value = $this->__implode($value);
|
|
|
|
}
|
2010-07-04 21:15:10 +00:00
|
|
|
return "Q2FrZQ==." . base64_encode(Security::cipher($value, $this->Cookie->key));
|
2009-03-19 21:10:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* implode method
|
|
|
|
*
|
|
|
|
* @param array $value
|
|
|
|
* @return string
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __implode($array) {
|
|
|
|
$string = '';
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
$string .= ',' . $key . '|' . $value;
|
|
|
|
}
|
|
|
|
return substr($string, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|