mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-17 06:59:51 +00:00
Making SessionComponent extend Component. Updating test case.
This commit is contained in:
parent
6dbe5b09f8
commit
db1acb461a
2 changed files with 18 additions and 15 deletions
|
@ -31,14 +31,16 @@ if (!class_exists('cakesession')) {
|
||||||
* @link http://book.cakephp.org/view/1310/Sessions
|
* @link http://book.cakephp.org/view/1310/Sessions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class SessionComponent extends Object {
|
class SessionComponent extends Component {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor automatically starts the session.
|
||||||
*
|
*
|
||||||
* @return void
|
* @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components
|
||||||
|
* @param array $settings Array of configuration settings.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct(ComponentCollection $collection, $settings = array()) {
|
||||||
|
parent::__construct($collection, $settings);
|
||||||
CakeSession::start();
|
CakeSession::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$_SESSION = null;
|
$_SESSION = null;
|
||||||
|
$this->ComponentCollection = new ComponentCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,11 +142,11 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionIdConsistentAcrossRequestAction() {
|
function testSessionIdConsistentAcrossRequestAction() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
$this->assertTrue(isset($_SESSION));
|
$this->assertTrue(isset($_SESSION));
|
||||||
|
|
||||||
$Object = new Object();
|
$Object = new Object();
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
$expected = $Session->id();
|
$expected = $Session->id();
|
||||||
|
|
||||||
$result = $Object->requestAction('/session_test/session_id');
|
$result = $Object->requestAction('/session_test/session_id');
|
||||||
|
@ -162,7 +163,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionValid() {
|
function testSessionValid() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
|
|
||||||
$this->assertTrue($Session->valid());
|
$this->assertTrue($Session->valid());
|
||||||
|
|
||||||
|
@ -170,7 +171,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
$Session->userAgent('rweerw');
|
$Session->userAgent('rweerw');
|
||||||
$this->assertFalse($Session->valid());
|
$this->assertFalse($Session->valid());
|
||||||
|
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
$Session->time = $Session->read('Config.time') + 1;
|
$Session->time = $Session->read('Config.time') + 1;
|
||||||
$this->assertFalse($Session->valid());
|
$this->assertFalse($Session->valid());
|
||||||
}
|
}
|
||||||
|
@ -182,7 +183,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionError() {
|
function testSessionError() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
$this->assertFalse($Session->error());
|
$this->assertFalse($Session->error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +194,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionReadWrite() {
|
function testSessionReadWrite() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
|
|
||||||
$this->assertNull($Session->read('Test'));
|
$this->assertNull($Session->read('Test'));
|
||||||
|
|
||||||
|
@ -227,7 +228,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionDelete() {
|
function testSessionDelete() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
|
|
||||||
$this->assertFalse($Session->delete('Test'));
|
$this->assertFalse($Session->delete('Test'));
|
||||||
|
|
||||||
|
@ -242,7 +243,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionCheck() {
|
function testSessionCheck() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
|
|
||||||
$this->assertFalse($Session->check('Test'));
|
$this->assertFalse($Session->check('Test'));
|
||||||
|
|
||||||
|
@ -258,7 +259,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionFlash() {
|
function testSessionFlash() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
|
|
||||||
$this->assertNull($Session->read('Message.flash'));
|
$this->assertNull($Session->read('Message.flash'));
|
||||||
|
|
||||||
|
@ -285,7 +286,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testSessionId() {
|
function testSessionId() {
|
||||||
unset($_SESSION);
|
unset($_SESSION);
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
$this->assertEquals(session_id(), $Session->id());
|
$this->assertEquals(session_id(), $Session->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +297,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionDestroy() {
|
function testSessionDestroy() {
|
||||||
$Session = new SessionComponent();
|
$Session = new SessionComponent($this->ComponentCollection);
|
||||||
|
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($Session->read('Test'), 'some value');
|
$this->assertEqual($Session->read('Test'), 'some value');
|
||||||
|
|
Loading…
Add table
Reference in a new issue