Skip to content

Commit

Permalink
Converting CookieComponentTest to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 10, 2010
1 parent fa8df12 commit d3ec9e1
Showing 1 changed file with 31 additions and 66 deletions.
97 changes: 31 additions & 66 deletions cake/tests/cases/libs/controller/components/cookie.test.php
Expand Up @@ -74,13 +74,12 @@ class CookieComponentTest extends CakeTestCase {
* @access public
* @return void
*/
function start() {
function setUp() {
$this->Controller = new CookieComponentTestController();
$this->Controller->constructClasses();
$this->Controller->Component->initialize($this->Controller);
$this->Controller->beforeFilter();
$this->Controller->Component->startup($this->Controller);
$this->Controller->Cookie->destroy();
}

/**
Expand All @@ -89,10 +88,22 @@ function start() {
* @access public
* @return void
*/
function end() {
function tearDown() {
$this->Controller->Cookie->destroy();
}

protected function _setCookieData() {
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));

$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
}

/**
* test that initialize sets settings from components array
*
Expand All @@ -118,26 +129,14 @@ function testCookieName() {
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
}

/**
* testSettingEncryptedCookieData
*
* @access public
* @return void
*/
function testSettingEncryptedCookieData() {
$this->Controller->Cookie->write('Encrytped_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'));
$this->Controller->Cookie->write('Encrytped_multi_cookies.name', 'CakePHP');
$this->Controller->Cookie->write('Encrytped_multi_cookies.version', '1.2.0.x');
$this->Controller->Cookie->write('Encrytped_multi_cookies.tag', 'CakePHP Rocks!');
}

/**
* testReadEncryptedCookieData
*
* @access public
* @return void
*/
function testReadEncryptedCookieData() {
$this->_setCookieData();
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
Expand All @@ -147,26 +146,15 @@ function testReadEncryptedCookieData() {
$this->assertEqual($data, $expected);
}

/**
* testSettingPlainCookieData
*
* @access public
* @return void
*/
function testSettingPlainCookieData() {
$this->Controller->Cookie->write('Plain_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'), false);
$this->Controller->Cookie->write('Plain_multi_cookies.name', 'CakePHP', false);
$this->Controller->Cookie->write('Plain_multi_cookies.version', '1.2.0.x', false);
$this->Controller->Cookie->write('Plain_multi_cookies.tag', 'CakePHP Rocks!', false);
}

/**
* testReadPlainCookieData
*
* @access public
* @return void
*/
function testReadPlainCookieData() {
$this->_setCookieData();

$data = $this->Controller->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
Expand Down Expand Up @@ -201,6 +189,7 @@ function testWritePlainCookieArray() {
* @return void
*/
function testReadingCookieValue() {
$this->_setCookieData();
$data = $this->Controller->Cookie->read();
$expected = array(
'Encrytped_array' => array(
Expand Down Expand Up @@ -229,15 +218,15 @@ function testReadingCookieValue() {
* @return void
*/
function testDeleteCookieValue() {
$this->_setCookieData();
$this->Controller->Cookie->delete('Encrytped_multi_cookies.name');
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);

$this->Controller->Cookie->delete('Encrytped_array');
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array();
$this->assertEqual($data, $expected);
$this->assertNull($data);

$this->Controller->Cookie->delete('Plain_multi_cookies.name');
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
Expand All @@ -246,28 +235,7 @@ function testDeleteCookieValue() {

$this->Controller->Cookie->delete('Plain_array');
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array();
$this->assertEqual($data, $expected);
}

/**
* testSettingCookiesWithArray
*
* @access public
* @return void
*/
function testSettingCookiesWithArray() {
$this->Controller->Cookie->destroy();

$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));

$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
$this->assertNull($data);
}

/**
Expand All @@ -277,6 +245,8 @@ function testSettingCookiesWithArray() {
* @return void
*/
function testReadingCookieArray() {
$this->_setCookieData();

$data = $this->Controller->Cookie->read('Encrytped_array.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
Expand Down Expand Up @@ -333,23 +303,18 @@ function testReadingCookieArray() {
* @return void
*/
function testReadingCookieDataOnStartup() {
$this->Controller->Cookie->destroy();

$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array();
$this->assertEqual($data, $expected);
$this->assertNull($data);

$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array();
$this->assertEqual($data, $expected);
$this->assertNull($data);

$data = $this->Controller->Cookie->read('Plain_array');
$expected = array();
$this->assertEqual($data, $expected);
$this->assertNull($data);

$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array();
$this->assertEqual($data, $expected);
$this->assertNull($data);

$_COOKIE['CakeTestCookie'] = array(
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
Expand Down Expand Up @@ -391,19 +356,19 @@ function testReadingCookieDataOnStartup() {
*/
function testReadingCookieDataWithoutStartup() {
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array();
$expected = null;
$this->assertEqual($data, $expected);

$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array();
$expected = null;
$this->assertEqual($data, $expected);

$data = $this->Controller->Cookie->read('Plain_array');
$expected = array();
$expected = null;
$this->assertEqual($data, $expected);

$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array();
$expected = null;
$this->assertEqual($data, $expected);

$_COOKIE['CakeTestCookie'] = array(
Expand Down

0 comments on commit d3ec9e1

Please sign in to comment.