Skip to content

Commit d3ec9e1

Browse files
committed
Converting CookieComponentTest to phpunit
1 parent fa8df12 commit d3ec9e1

File tree

1 file changed

+31
-66
lines changed

1 file changed

+31
-66
lines changed

cake/tests/cases/libs/controller/components/cookie.test.php

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ class CookieComponentTest extends CakeTestCase {
7474
* @access public
7575
* @return void
7676
*/
77-
function start() {
77+
function setUp() {
7878
$this->Controller = new CookieComponentTestController();
7979
$this->Controller->constructClasses();
8080
$this->Controller->Component->initialize($this->Controller);
8181
$this->Controller->beforeFilter();
8282
$this->Controller->Component->startup($this->Controller);
83-
$this->Controller->Cookie->destroy();
8483
}
8584

8685
/**
@@ -89,10 +88,22 @@ function start() {
8988
* @access public
9089
* @return void
9190
*/
92-
function end() {
91+
function tearDown() {
9392
$this->Controller->Cookie->destroy();
9493
}
9594

95+
protected function _setCookieData() {
96+
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
97+
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
98+
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
99+
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
100+
101+
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
102+
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
103+
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
104+
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
105+
}
106+
96107
/**
97108
* test that initialize sets settings from components array
98109
*
@@ -118,26 +129,14 @@ function testCookieName() {
118129
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
119130
}
120131

121-
/**
122-
* testSettingEncryptedCookieData
123-
*
124-
* @access public
125-
* @return void
126-
*/
127-
function testSettingEncryptedCookieData() {
128-
$this->Controller->Cookie->write('Encrytped_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'));
129-
$this->Controller->Cookie->write('Encrytped_multi_cookies.name', 'CakePHP');
130-
$this->Controller->Cookie->write('Encrytped_multi_cookies.version', '1.2.0.x');
131-
$this->Controller->Cookie->write('Encrytped_multi_cookies.tag', 'CakePHP Rocks!');
132-
}
133-
134132
/**
135133
* testReadEncryptedCookieData
136134
*
137135
* @access public
138136
* @return void
139137
*/
140138
function testReadEncryptedCookieData() {
139+
$this->_setCookieData();
141140
$data = $this->Controller->Cookie->read('Encrytped_array');
142141
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
143142
$this->assertEqual($data, $expected);
@@ -147,26 +146,15 @@ function testReadEncryptedCookieData() {
147146
$this->assertEqual($data, $expected);
148147
}
149148

150-
/**
151-
* testSettingPlainCookieData
152-
*
153-
* @access public
154-
* @return void
155-
*/
156-
function testSettingPlainCookieData() {
157-
$this->Controller->Cookie->write('Plain_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'), false);
158-
$this->Controller->Cookie->write('Plain_multi_cookies.name', 'CakePHP', false);
159-
$this->Controller->Cookie->write('Plain_multi_cookies.version', '1.2.0.x', false);
160-
$this->Controller->Cookie->write('Plain_multi_cookies.tag', 'CakePHP Rocks!', false);
161-
}
162-
163149
/**
164150
* testReadPlainCookieData
165151
*
166152
* @access public
167153
* @return void
168154
*/
169155
function testReadPlainCookieData() {
156+
$this->_setCookieData();
157+
170158
$data = $this->Controller->Cookie->read('Plain_array');
171159
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
172160
$this->assertEqual($data, $expected);
@@ -201,6 +189,7 @@ function testWritePlainCookieArray() {
201189
* @return void
202190
*/
203191
function testReadingCookieValue() {
192+
$this->_setCookieData();
204193
$data = $this->Controller->Cookie->read();
205194
$expected = array(
206195
'Encrytped_array' => array(
@@ -229,15 +218,15 @@ function testReadingCookieValue() {
229218
* @return void
230219
*/
231220
function testDeleteCookieValue() {
221+
$this->_setCookieData();
232222
$this->Controller->Cookie->delete('Encrytped_multi_cookies.name');
233223
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
234224
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
235225
$this->assertEqual($data, $expected);
236226

237227
$this->Controller->Cookie->delete('Encrytped_array');
238228
$data = $this->Controller->Cookie->read('Encrytped_array');
239-
$expected = array();
240-
$this->assertEqual($data, $expected);
229+
$this->assertNull($data);
241230

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

247236
$this->Controller->Cookie->delete('Plain_array');
248237
$data = $this->Controller->Cookie->read('Plain_array');
249-
$expected = array();
250-
$this->assertEqual($data, $expected);
251-
}
252-
253-
/**
254-
* testSettingCookiesWithArray
255-
*
256-
* @access public
257-
* @return void
258-
*/
259-
function testSettingCookiesWithArray() {
260-
$this->Controller->Cookie->destroy();
261-
262-
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
263-
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
264-
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
265-
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
266-
267-
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
268-
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
269-
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
270-
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
238+
$this->assertNull($data);
271239
}
272240

273241
/**
@@ -277,6 +245,8 @@ function testSettingCookiesWithArray() {
277245
* @return void
278246
*/
279247
function testReadingCookieArray() {
248+
$this->_setCookieData();
249+
280250
$data = $this->Controller->Cookie->read('Encrytped_array.name');
281251
$expected = 'CakePHP';
282252
$this->assertEqual($data, $expected);
@@ -333,23 +303,18 @@ function testReadingCookieArray() {
333303
* @return void
334304
*/
335305
function testReadingCookieDataOnStartup() {
336-
$this->Controller->Cookie->destroy();
337306

338307
$data = $this->Controller->Cookie->read('Encrytped_array');
339-
$expected = array();
340-
$this->assertEqual($data, $expected);
308+
$this->assertNull($data);
341309

342310
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
343-
$expected = array();
344-
$this->assertEqual($data, $expected);
311+
$this->assertNull($data);
345312

346313
$data = $this->Controller->Cookie->read('Plain_array');
347-
$expected = array();
348-
$this->assertEqual($data, $expected);
314+
$this->assertNull($data);
349315

350316
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
351-
$expected = array();
352-
$this->assertEqual($data, $expected);
317+
$this->assertNull($data);
353318

354319
$_COOKIE['CakeTestCookie'] = array(
355320
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
@@ -391,19 +356,19 @@ function testReadingCookieDataOnStartup() {
391356
*/
392357
function testReadingCookieDataWithoutStartup() {
393358
$data = $this->Controller->Cookie->read('Encrytped_array');
394-
$expected = array();
359+
$expected = null;
395360
$this->assertEqual($data, $expected);
396361

397362
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
398-
$expected = array();
363+
$expected = null;
399364
$this->assertEqual($data, $expected);
400365

401366
$data = $this->Controller->Cookie->read('Plain_array');
402-
$expected = array();
367+
$expected = null;
403368
$this->assertEqual($data, $expected);
404369

405370
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
406-
$expected = array();
371+
$expected = null;
407372
$this->assertEqual($data, $expected);
408373

409374
$_COOKIE['CakeTestCookie'] = array(

0 commit comments

Comments
 (0)