Skip to content

Commit

Permalink
session: Added More Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Oct 16, 2024
1 parent a2c7955 commit a16a89e
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions tests/webfiori/framework/test/session/SessionsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,126 @@ public function testInitSessionsDb() {
SessionsManager::reset();
$sto = new DatabaseSessionStorage();
$sto->getController()->createTables()->execute();
$sto->getController()->table('session_data')->select()->execute();
$sto->getController()->table('sessions')->select()->execute();
$this->assertTrue(true);
}
/**
* @test
* @depends testInitSessionsDb
*/
public function testDbSessions00() {
SessionsManager::start('hello', [

]);
$activeSesstion = SessionsManager::getActiveSession();

$this->assertFalse($activeSesstion->isRefresh());
$this->assertTrue($activeSesstion->isRunning());

$this->assertNotNull($activeSesstion);
$this->assertEquals('hello', $activeSesstion->getName());
$this->assertEquals(7200, $activeSesstion->getDuration());
$this->assertEquals(SessionStatus::NEW, $activeSesstion->getStatus());

SessionsManager::set('var-1', 'Good');
$activeSesstion->set('var-2', 'Bad');
$activeSesstion->set('var-3', 'Average');
$activeSesstion->set('var-4', 'Almost Good');
$this->assertEquals('Good', SessionsManager::get('var-1 '));
$this->assertEquals('Bad', SessionsManager::get(' var-2 '));
$this->assertEquals('Average', SessionsManager::get('var-3 '));
$this->assertEquals('Almost Good', SessionsManager::get('var-4 '));

SessionsManager::pauseAll();
$this->assertFalse($activeSesstion->isRunning());
$this->assertNull(SessionsManager::get('var-1 '));
$this->assertNull(SessionsManager::get(' var-2 '));
$this->assertNull(SessionsManager::get('var-3 '));
$this->assertNull(SessionsManager::get('var-4 '));

$this->assertNull(SessionsManager::getActiveSession());
$this->assertEquals(SessionStatus::PAUSED, $activeSesstion->getStatus());

$activeSesstion->start();
$this->assertTrue($activeSesstion->isRunning());

$this->assertNotNull(SessionsManager::getActiveSession());
$this->assertEquals(SessionStatus::RESUMED, $activeSesstion->getStatus());
$this->assertEquals('Good', SessionsManager::get('var-1 '));
$this->assertEquals('Bad', SessionsManager::get(' var-2 '));
$this->assertEquals('Average', SessionsManager::get('var-3 '));
$this->assertEquals('Almost Good', SessionsManager::get('var-4 '));

$this->assertEquals('Good', SessionsManager::pull('var-1 '));
$this->assertNull(SessionsManager::pull('var-1 '));
$this->assertTrue(SessionsManager::remove('var-2'));
$this->assertFalse(SessionsManager::remove('var-2'));
$this->assertNull(SessionsManager::get('var-1 '));
$this->assertNull(SessionsManager::get(' var-2 '));

//Start New Sesstion
SessionsManager::start('another-one', [
'duration' => 5,
'refresh' => true
]);
$this->assertFalse($activeSesstion->isRunning());
$this->assertEquals(SessionStatus::PAUSED, $activeSesstion->getStatus());
$active2 = SessionsManager::getActiveSession();
$this->assertEquals(300, $active2->getDuration());
$this->assertTrue($active2->isRefresh());
$this->assertTrue($active2->isRunning());
$this->assertNull(SessionsManager::get('var-3 '));
$this->assertNull(SessionsManager::get(' var-4 '));

$active2->set('super-var', 'I m super.');
$this->assertEquals('I m super.', SessionsManager::get('super-var'));

$active2->close();
$this->assertNull(SessionsManager::getActiveSession());
$activeSesstion->start();
$this->assertNotNull(SessionsManager::getActiveSession());
$this->assertNull(SessionsManager::get('super-var'));
$this->assertEquals(7200, SessionsManager::getActiveSession()->getDuration());
$this->assertEquals(SessionStatus::PAUSED, $active2->getStatus());

SessionsManager::start('another-one');
$this->assertEquals(SessionStatus::PAUSED, $activeSesstion->getStatus());
$this->assertEquals(SessionStatus::RESUMED, $active2->getStatus());
$this->assertEquals('I m super.', SessionsManager::get('super-var'));
SessionsManager::destroy();
$this->assertNull(SessionsManager::getActiveSession());
$this->assertEquals(SessionStatus::KILLED, $active2->getStatus());
SessionsManager::validateStorage();
$active2->start();
$this->assertEquals(SessionStatus::NEW, $active2->getStatus());
$this->assertNotNull(SessionsManager::getActiveSession());
$this->assertEquals(300, SessionsManager::getActiveSession()->getDuration());
$this->assertNull(SessionsManager::get('super-var'));
SessionsManager::validateStorage();
}
/**
* @test
* @depends testInitSessionsDb
*/
public function testCloseDb00() {
SessionsManager::pauseAll();
$this->assertNull(SessionsManager::getActiveSession());
SessionsManager::start('xyz');
$this->assertNotNull(SessionsManager::getActiveSession());
SessionsManager::close();
$this->assertNull(SessionsManager::getActiveSession());
SessionsManager::start('xyz');
$this->assertEquals(SessionStatus::RESUMED, SessionsManager::getActiveSession()->getStatus());
$oldId = SessionsManager::getActiveSession()->getId();
$newId = SessionsManager::newId();
$this->assertNotEquals($oldId, $newId);
$this->assertNotEquals($oldId, SessionsManager::getActiveSession()->getId());
$this->assertEquals($newId, SessionsManager::getActiveSession()->getId());
}
}





0 comments on commit a16a89e

Please sign in to comment.