SimpleTest Web tester and sessions

Hello all,

Recently I have been more and more involved in the test framework SimpleTest to test all my applications. At first everything looked promising until I started to test pages requiring login features and checking various session variables to grant access to pages inside the application.

My problem is this: I have created a simple login form with username and password. If I enter a correct username and password I get logged in but as soon as I try to access a restricted part of my application the session is invalid (or unset).

Below are some examples:

class TestLogin extends WebTestCase {
      
    function testLoginSuccess() {
	$this->get('LOGIN_PAGE');
        $this->setField('username', 'Admin');
        $this->setField('password', 'admin');
        $this->click('Login');
        $this->assertText('Admin');
        $this->assertLink('Logout');
    }
    
    function testLoginLasting() {
 	$this->get('LOGIN_PAGE');
        $this->setField('username', 'Admin');
        $this->setField('password', 'admin');
        $this->click('Login');
        $this->assertText('Admin');
        $this->assertLink('Logout');
      
  	$this->get('PROTECTED_PAGE');
    	$this->assertText('Protected area'); # error
  }
}

testLoginSuccess() works perfect but testLoginLasting() is giving me errors saying the text can’t be found, it’s actually telling me the session is not set. But if the session wasn’t set the two tests (assertText and assertLink) would be valid because they are only displayed if the session is set.

If there is anyone out there with a solution for handling sessions with SimpleTest I need help! :slight_smile: So, I’m using SimpleTest and the Web Tester feature.

Thanks all,
Regards,
Nikals