Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * CacheSessionTest
4
 *
5
 * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP(tm) Project
14
 * @package       Cake.Test.Case.Model.Datasource.Session
15
 * @since         CakePHP(tm) v 2.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('CakeSession', 'Model/Datasource');
20
App::uses('CacheSession', 'Model/Datasource/Session');
21
class_exists('CakeSession');
22
 
23
/**
24
 * Class CacheSessionTest
25
 *
26
 * @package       Cake.Test.Case.Model.Datasource.Session
27
 */
28
class CacheSessionTest extends CakeTestCase {
29
 
30
	protected static $_sessionBackup;
31
 
32
/**
33
 * test case startup
34
 *
35
 * @return void
36
 */
37
	public static function setupBeforeClass() {
38
		Cache::config('session_test', array(
39
			'engine' => 'File',
40
			'prefix' => 'session_test_'
41
		));
42
		self::$_sessionBackup = Configure::read('Session');
43
 
44
		Configure::write('Session.handler.config', 'session_test');
45
	}
46
 
47
/**
48
 * cleanup after test case.
49
 *
50
 * @return void
51
 */
52
	public static function teardownAfterClass() {
53
		Cache::clear(false, 'session_test');
54
		Cache::drop('session_test');
55
 
56
		Configure::write('Session', self::$_sessionBackup);
57
	}
58
 
59
/**
60
 * setup
61
 *
62
 * @return void
63
 */
64
	public function setUp() {
65
		parent::setUp();
66
		$this->storage = new CacheSession();
67
	}
68
 
69
/**
70
 * tearDown
71
 *
72
 * @return void
73
 */
74
	public function tearDown() {
75
		parent::tearDown();
76
		unset($this->storage);
77
	}
78
 
79
/**
80
 * test open
81
 *
82
 * @return void
83
 */
84
	public function testOpen() {
85
		$this->assertTrue($this->storage->open());
86
	}
87
 
88
/**
89
 * test write()
90
 *
91
 * @return void
92
 */
93
	public function testWrite() {
94
		$this->storage->write('abc', 'Some value');
95
		$this->assertEquals('Some value', Cache::read('abc', 'session_test'), 'Value was not written.');
96
		$this->assertFalse(Cache::read('abc', 'default'), 'Cache should only write to the given config.');
97
	}
98
 
99
/**
100
 * test reading.
101
 *
102
 * @return void
103
 */
104
	public function testRead() {
105
		$this->storage->write('test_one', 'Some other value');
106
		$this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
107
	}
108
 
109
/**
110
 * test destroy
111
 *
112
 * @return void
113
 */
114
	public function testDestroy() {
115
		$this->storage->write('test_one', 'Some other value');
116
		$this->assertTrue($this->storage->destroy('test_one'), 'Value was not deleted.');
117
 
118
		$this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
119
	}
120
 
121
}